API Reference¶
FlashANSR¶
Flash Amortized Neural Symbolic Regressor.
| PARAMETER | DESCRIPTION |
|---|---|
simplipy_engine
|
Engine responsible for manipulating and evaluating symbolic expressions.
TYPE:
|
flash_ansr_model
|
Trained transformer backbone that proposes expression programs.
TYPE:
|
tokenizer
|
Tokenizer mapping model outputs to expression tokens.
TYPE:
|
generation_config
|
Configuration that controls candidate generation. If
TYPE:
|
n_restarts
|
Number of optimizer restarts used by the refiner when fitting constants.
TYPE:
|
refiner_method
|
Optimization routine employed by the refiner.
TYPE:
|
refiner_p0_noise
|
Distribution applied to perturb initial constant guesses.
TYPE:
|
refiner_p0_noise_kwargs
|
Keyword arguments forwarded to the noise sampler.
TYPE:
|
numpy_errors
|
Desired NumPy error handling strategy applied during constant refinement.
TYPE:
|
parsimony
|
Penalty coefficient that discourages overly complex expressions.
TYPE:
|
refiner_workers
|
Number of worker processes to run during constant refinement.
TYPE:
|
Source code in src/flash_ansr/flash_ansr.py
load
classmethod
¶
load(directory: str, generation_config: GenerationConfig | None = None, n_restarts: int = 8, refiner_method: Literal['curve_fit_lm', 'minimize_bfgs', 'minimize_lbfgsb', 'minimize_neldermead', 'minimize_powell', 'least_squares_trf', 'least_squares_dogbox'] = 'curve_fit_lm', refiner_p0_noise: Literal['uniform', 'normal'] | None = 'normal', refiner_p0_noise_kwargs: dict | None | Literal['default'] = 'default', numpy_errors: Literal['ignore', 'warn', 'raise', 'call', 'print', 'log'] | None = 'ignore', parsimony: float = 0.05, device: str = 'cpu', refiner_workers: int | None = None) -> FlashANSR
Instantiate a FlashANSR model from a configuration directory.
| PARAMETER | DESCRIPTION |
|---|---|
directory
|
Directory that contains
TYPE:
|
generation_config
|
Generation parameters to override defaults during candidate search.
TYPE:
|
n_restarts
|
Number of restarts passed to the refiner.
TYPE:
|
refiner_method
|
Optimization routine for constant fitting.
TYPE:
|
refiner_p0_noise
|
Distribution used to perturb initial constant guesses.
TYPE:
|
refiner_p0_noise_kwargs
|
Additional keyword arguments for the noise sampler.
TYPE:
|
numpy_errors
|
NumPy floating-point error policy applied during refinement.
TYPE:
|
parsimony
|
Parsimony coefficient used when compiling results.
TYPE:
|
device
|
Torch device where the model weights will be loaded.
TYPE:
|
refiner_workers
|
Desired worker-pool size for constant refinement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
model
|
Fully initialized regressor ready for inference.
TYPE:
|
Source code in src/flash_ansr/flash_ansr.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
fit ¶
fit(X: ndarray | Tensor | DataFrame, y: ndarray | Tensor | DataFrame | Series, variable_names: list[str] | dict[str, str] | Literal['auto'] | None = 'auto', converge_error: Literal['raise', 'ignore', 'print'] = 'ignore', verbose: bool = False, *, complexity: int | float | None = None, allowed_terms: Iterable[Sequence[Any]] | None = None, include_terms: Iterable[Sequence[Any]] | None = None, exclude_terms: Iterable[Sequence[Any]] | None = None) -> None
Perform symbolic regression on (X, y) and refine candidate expressions.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Feature matrix where rows index observations and columns variables.
TYPE:
|
y
|
Target values. Multi-output targets are unsupported.
TYPE:
|
variable_names
|
Mapping from internal variable tokens to descriptive names.
TYPE:
|
converge_error
|
Handling strategy when the refiner fails to converge.
TYPE:
|
verbose
|
If
TYPE:
|
allowed_terms
|
Keyword-only list of term token sequences that may appear in the generated expression.
TYPE:
|
include_terms
|
Keyword-only subset of allowed terms that the expression should prioritise using.
TYPE:
|
exclude_terms
|
Keyword-only list of term token sequences that should be discouraged during generation.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/flash_ansr/flash_ansr.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
predict ¶
predict(X: ndarray | Tensor | DataFrame, nth_best_beam: int = 0, nth_best_constants: int = 0) -> np.ndarray
Evaluate a fitted expression on new data.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Feature matrix to evaluate.
TYPE:
|
nth_best_beam
|
Beam index to select from the ranked results.
TYPE:
|
nth_best_constants
|
Index of the constant fit to choose for the selected beam.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
y_pred
|
Predicted targets with the same leading dimension as
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the model has not been fitted before prediction. |
Source code in src/flash_ansr/flash_ansr.py
get_expression ¶
get_expression(nth_best_beam: int = 0, nth_best_constants: int = 0, return_prefix: bool = False, precision: int = 2, map_variables: bool = True, **kwargs: Any) -> list[str] | str
Retrieve a formatted expression from the compiled results.
| PARAMETER | DESCRIPTION |
|---|---|
nth_best_beam
|
Beam index to extract from
TYPE:
|
nth_best_constants
|
Constant fit index for the selected beam.
TYPE:
|
return_prefix
|
If
TYPE:
|
precision
|
Number of decimal places used when rendering constants.
TYPE:
|
map_variables
|
When
TYPE:
|
**kwargs
|
Extra keyword arguments forwarded to :meth:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
expression
|
Expression either as a token list or human-readable string.
TYPE:
|
Source code in src/flash_ansr/flash_ansr.py
save_results ¶
Persist fitted results (minus lambdas) for later reuse.
Source code in src/flash_ansr/flash_ansr.py
load_results ¶
Load previously saved results and rebuild refiners if requested.
Source code in src/flash_ansr/flash_ansr.py
compile_results ¶
Aggregate refiner outputs into a tidy pandas.DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
parsimony
|
Parsimony coefficient used to recompute scores before ranking.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ConvergenceError
|
If no beams converged during refinement. |
Source code in src/flash_ansr/flash_ansr.py
FlashANSRDataset¶
Dataset wrapper for amortized neural symbolic regression training.
Manages skeleton sampling, support point generation, optional prompt
preprocessing, and collation into model-ready batches. Can also compile
streaming output into an on-disk datasets.Dataset for deterministic
iteration.
| PARAMETER | DESCRIPTION |
|---|---|
skeleton_pool
|
Source of operator-only expression templates and sampling logic.
TYPE:
|
tokenizer
|
Tokenizer used for expression serialization and padding.
TYPE:
|
padding
|
Strategy for padding numeric support points.
TYPE:
|
preprocessor
|
Prompt-aware preprocessor; when provided, prompt metadata can be injected during sampling or in worker processes.
TYPE:
|
Source code in src/flash_ansr/data/data.py
from_config
classmethod
¶
Instantiate from a YAML/dict config.
Paths are normalized via load_config and substitute_root_path. The
config may embed a skeleton pool definition or point to a directory
containing one.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Dataset config or path to a YAML file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FlashANSRDataset
|
Dataset wrapper with tokenizer and optional preprocessor wired. |
Source code in src/flash_ansr/data/data.py
iterate ¶
iterate(size: int | None = None, steps: int | None = None, batch_size: int | None = None, n_support: int | None = None, max_seq_len: int = 512, max_n_support: int | None = None, n_per_equation: int = 1, preprocess: bool = False, preprocess_in_worker: bool | None = None, tokenizer_oov: Literal['unk', 'raise'] = 'raise', num_workers: int | None = None, prefetch_factor: int = 2, persistent: bool = False, tqdm_kwargs: dict[str, Any] | None = None, verbose: bool = False) -> Generator[dict[str, Any], None, None]
Stream batches of synthetic data.
| PARAMETER | DESCRIPTION |
|---|---|
size
|
Total number of samples to generate (used if
TYPE:
|
steps
|
Number of generation steps; overrides
TYPE:
|
batch_size
|
Samples per step; defaults to 1.
TYPE:
|
n_support
|
Support points per equation; pool default when None.
TYPE:
|
max_seq_len
|
Maximum prefix length for generated expressions.
TYPE:
|
max_n_support
|
Upper bound for support points; used for padding.
TYPE:
|
n_per_equation
|
Number of datasets to draw per skeleton before moving on.
TYPE:
|
preprocess
|
Whether to run the preprocessor on generated batches.
TYPE:
|
preprocess_in_worker
|
Force preprocessing inside workers (True), main process (False), or auto-select (None).
TYPE:
|
tokenizer_oov
|
How to handle tokens missing from the tokenizer.
TYPE:
|
num_workers
|
Worker count for multiprocessing; defaults to CPU count when None.
TYPE:
|
prefetch_factor
|
Jobs per worker to pre-schedule.
TYPE:
|
persistent
|
Clone tensors to detach from shared memory buffers.
TYPE:
|
tqdm_kwargs
|
Additional arguments forwarded to tqdm progress bars.
TYPE:
|
verbose
|
Enable progress reporting.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
dict
|
Model-ready batch with tensors and optional prompt metadata. |
Source code in src/flash_ansr/data/data.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
FlashANSRPreprocessor¶
Format batch inputs and optionally enrich them with prompt metadata.
Source code in src/flash_ansr/preprocessing/pipeline.py
Generation configurations¶
BeamSearchConfig¶
Configuration for beam-search based generation.
Source code in src/flash_ansr/utils/generation.py
SoftmaxSamplingConfig¶
Configuration for softmax sampling generation.
Source code in src/flash_ansr/utils/generation.py
MCTSGenerationConfig¶
Configuration for Monte Carlo tree search generation.
Source code in src/flash_ansr/utils/generation.py
Utilities¶
Resolve a path relative to the repository root (optionally creating directories).
Source code in src/flash_ansr/utils/paths.py
Load a YAML config (optionally resolving nested relative paths).