feat: Quil arithmetic expressions as gate arguments in the exact simulators - #1869
Open
bramathon wants to merge 2 commits into
Open
feat: Quil arithmetic expressions as gate arguments in the exact simulators#1869bramathon wants to merge 2 commits into
bramathon wants to merge 2 commits into
Conversation
|
| Project | pyquil |
| Branch | 1860-affine-parameters |
| Testbed | ci-runner-linux |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | seconds (s) |
|---|---|---|
| test/benchmarks/test_program.py::test_copy_everything_except_instructions | 📈 view plot | 9.61 s |
| test/benchmarks/test_program.py::test_instructions | 📈 view plot | 3.35 s |
| test/benchmarks/test_program.py::test_iteration | 📈 view plot | 3.31 s |
A gate angle may now be any affine expression a*theta + b in a single memory reference (RX(theta[0]/2 + pi), RZ(-2*phi[1]), RX(theta + theta)), which is what quilc emits when it compiles a parametric program. The scale and offset travel with the ParametricGate and are per-member data of a gate batch, so the batching key is unchanged and such gates still share one vmap with plain references. Products, powers and functions of references are rejected with an error naming the parameter. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JfZKmgqinMhR4BS87y4G4F
bramathon
force-pushed
the
1860-affine-parameters
branch
from
September 11, 2026 09:50
6b2134c to
85c393d
Compare
Replace the affine-only parser with a compiler from pyQuil expression trees to JAX functions: + - * / ^, SIN, COS, SQRT, EXP, CIS, and real or complex literals. A ParameterExpression carries the slots it reads and a shape key (references replaced by %0, %1, ...); gate batches are keyed by shape, so SIN(theta[0]) and SIN(theta[1]) still share one vmap and differ only in the slots gathered per member. Complex-valued arguments (CIS, a complex literal) are accepted for DEFGATE gates and rejected with a clear error for the built-in gates, whose angles are real. Parameter-free expressions such as SIN(pi/4) fold to literals. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JfZKmgqinMhR4BS87y4G4F
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mini-PR onto
1855-experimental-exact-simulators(#1860), as requested in the review discussion there.What
A gate angle may now be any Quil arithmetic expression over memory references:
+ - * / ^, the functionsSIN,COS,SQRT,EXP,CIS, and real or complex literals.RX(theta[0]/2 + pi)(what quilc emits for a compiled parametric program),RZ(2*SIN(phi[1]))andCPH(CIS(theta[0])) 0for aDEFGATEwith a complex parameter all simulate directly instead of failing at construction.How
_resolver._compile_expressionwalks the pyQuil expression tree and produces aParameterExpression: the slots it reads, a JAX closure, and a shape key with references replaced by%0, %1, …(SIN(theta[0])andSIN(theta[1])share the keySIN(%0)).ParametricGate.argumentsholds a literal or aParameterExpressionper gate argument._GateBatchkeys on(gate, literals, expression shapes, embedding)and gathers each member's slot values, so same-shaped expressions still share onevmap; the traced graph stays proportional to the number of distinct gate kinds.CIS, a complex literal) are accepted forDEFGATEgates and rejected with a clear error for the built-in gates, which take real angles (quax's gate constructors reject complex angles).SQRT/^are evaluated in real arithmetic; a negative radicand givesnanwhere Quil would give a complex number, which the docstring says.SIN(pi/4)fold to literals.Tests
test/unit/test_parameter_expressions.py(48 tests): shape keys and slot order for 13 forms, key sharing across slots, the complex flag, numeric evaluation against Quil semantics (includingCISand complex literals), equality with the literal gate for 12 expression shapes, a quilc-style Quil-text program,CIS/complex arithmetic through aDEFGATE, the complex-argument error for built-in gates, feed-forward still rejected, slot sharing/batching,jit+gradthroughRX(SIN(theta))(analytic derivative), and literal folding.🤖 Generated with Claude Code
https://claude.ai/code/session_01JfZKmgqinMhR4BS87y4G4F