Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically suggest related keywords #620

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

MilesCranmer
Copy link
Owner

@MilesCranmer MilesCranmer commented May 5, 2024

PySRRegressor has a lot of parameters. To help with this, this PR implements an "autosuggestion" feature that, upon receiving an invalid keyword, will print an error message with possibilities for what the user had meant to write out.

In [2]: model = PySRRegressor(iterations=10)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 model = PySRRegressor(iterations=10)

File ~/PermaDocuments/SymbolicRegressionMonorepo/PySR/pysr/sr.py:916, in PySRRegressor.__init__(self, model_selection, binary_operators, unary_operators, niterations, populations, population_size, max_evals, maxsize, maxdepth, warmup_maxsize_by, timeout_in_seconds, constraints, nested_constraints, elementwise_loss, loss_function, complexity_of_operators, complexity_of_constants, complexity_of_variables, parsimony, dimensional_constraint_penalty, dimensionless_constants_only, use_frequency, use_frequency_in_tournament, adaptive_parsimony_scaling, alpha, annealing, early_stop_condition, ncycles_per_iteration, fraction_replaced, fraction_replaced_hof, weight_add_node, weight_insert_node, weight_delete_node, weight_do_nothing, weight_mutate_constant, weight_mutate_operator, weight_swap_operands, weight_randomize, weight_simplify, weight_optimize, crossover_probability, skip_mutation_failures, migration, hof_migration, topn, should_simplify, should_optimize_constants, optimizer_algorithm, optimizer_nrestarts, optimize_probability, optimizer_iterations, perturbation_factor, tournament_selection_n, tournament_selection_p, procs, multithreading, cluster_manager, heap_size_hint_in_bytes, batching, batch_size, fast_cycle, turbo, bumper, precision, enable_autodiff, random_state, deterministic, warm_start, verbosity, update_verbosity, print_precision, progress, equation_file, temp_equation_file, tempdir, delete_tempfiles, update, output_jax_format, output_torch_format, extra_sympy_mappings, extra_torch_mappings, extra_jax_mappings, denoise, select_k_features, **kwargs)
    914 if len(suggested_keywords) > 0:
    915     err_msg += f" Did you mean {' or '.join(suggested_keywords)}?"
--> 916 raise TypeError(err_msg)

TypeError: iterations is not a valid keyword argument for PySRRegressor. Did you mean niterations or migration or optimizer_iterations?

Note the new addition to the error message:

Did you mean niterations or migration or optimizer_iterations?

It does this using difflib and suggests up to 3 options (but only if they are past a threshold similarity).

To be merged after #609 as it is rebased on top of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant