Skip to content

docs: add agent skill for using PySR effectively - #1264

Merged
MilesCranmer merged 1 commit into
masterfrom
agent-skills
Jul 24, 2026
Merged

docs: add agent skill for using PySR effectively#1264
MilesCranmer merged 1 commit into
masterfrom
agent-skills

Conversation

@MilesCranmer

Copy link
Copy Markdown
Member

Adds a self-contained skill file at skills/pysr/SKILL.md that teaches AI coding agents to use PySR well: workflow, losses, template expressions, custom operators and objectives (including tree-walking symbolic constraints), constraints, units, parallelism, persistence, troubleshooting, and a deprecated-API translation table. Distilled from the docs plus all ~800 GitHub issues and discussions, with stale advice filtered out. The README gets a short pointer with a one-line install command in the Agent Skills format.

Validation: every code snippet and API claim was executed against live installs of both 1.5.10 and 2.0.0a2 (15-check suite, all passing). Also dogfooded with 10 fresh Sonnet agents (5 tasks, with-skill vs no-skill arms, docs access forbidden): the skill arm solved all tasks first-try with the intended mechanisms; baselines needed 2-3 attempts and reached for deprecated APIs.

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f0b5e368b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/pysr/SKILL.md

## Constraints and complexity shaping

- `constraints={"pow": (9, 1)}`: max complexity of each argument (here: any base, exponent must be a lone constant/variable). `-1` means unlimited. Strongly recommended whenever `^` is included; unconstrained exponentiation searches terribly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the ^ key for exponent constraints

When agents follow this advice with binary_operators=[..., "^"], PySR matches constraints by the actual operator name, so constraints={"pow": ...} is ignored for "^" and _process_constraints falls back to the unconstrained (-1, -1) entry while warning that ^ has no constraint. This leaves exponentiation unconstrained in the exact case the bullet is trying to prevent; use "^": (9, 1) here, or reserve "pow" for configurations where the operator is actually named pow.

Useful? React with 👍 / 👎.

Comment thread skills/pysr/SKILL.md
model = PySRRegressor(binary_operators=["+", "*", "^"], loss_function=objective)
```

The count-then-penalize shape (violations counted, multiplied by a large finite constant, returned *before* evaluation) is the canonical pattern: cheap structural check first, graded penalty so evolution has a direction, `Inf` reserved for failed numerical evaluation. Requiring a feature is the mirror image: `any(n -> n.degree == 0 && !n.constant && n.feature == 2, tree) || return L(big)`. For template expressions, get the tree of a component via `get_tree(ex)` inside `loss_function_expression`. More traversal tools (`tree_mapreduce`, `NodeSampler`, node construction): https://ai.damtp.cam.ac.uk/dynamicexpressions/stable/examples/base_operations/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Replace L(big) with a numeric penalty

If an agent copies this required-feature pattern literally, big is Julia's built-in conversion function rather than a numeric loss value, so return L(big) will fail when the custom objective is compiled/evaluated instead of returning the intended finite structural penalty. Use a concrete number such as L(1e6) to match the graded-penalty pattern described just before this sentence.

Useful? React with 👍 / 👎.

Comment thread skills/pysr/SKILL.md
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MilesCranmer
MilesCranmer merged commit fdedcc8 into master Jul 24, 2026
21 checks passed
@MilesCranmer
MilesCranmer deleted the agent-skills branch July 24, 2026 11:44
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.

2 participants