Repository navigation
Conversation
get_parameter_value turned only a Python float into a constant, so
kernel.ry(1, q), kernel.rx(np.float32(0.5), q) or kernel.u3 with NumPy
angles passed the raw number to the op builder and failed with
"Operand 0 of operation quake.ry must be a Sequence of Values".
exp_pauli had its own float-only check and raised AttributeError
('int' object has no attribute 'mlirValue'), which also broke
givens_rotation with a NumPy angle.
Treat any numbers.Real as a constant angle and let exp_pauli use the
same helper.
Signed-off-by: Raunak Burrows <raunakburrows@gmail.com>
This branch has not been deployed
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.
Problem
In the kernel builder, a constant rotation angle works only when it is a Python
float. Anintor a NumPy scalar that is not afloatsubclass (np.float32,np.int64, ...) is passed through raw and fails while the op is built:get_parameter_value(used by every rotation gate, their controlled forms andu3) only convertsisinstance(parameter, float), andexp_paulihas its own copy of the same float-only check.givens_rotationgoes throughexp_pauli, so it fails with a NumPy angle too, andfermionic_swapwith anintangle.Fix
get_parameter_valuenow turns anynumbers.Realinto anf64constant (float(parameter)), andexp_pauliusesget_parameter_valueinstead of its own check.QuakeValueangles take the same path as before.flowchart TD A[kernel.ry with angle 1] --> B{Build the quake op} B -->|Before| C[ValueError operand 0 is not a Value] B -->|After| D[f64 constant angle and the kernel samples]Narrated recording, before then after (sound on):
evidence.mp4
Reproducer
cuda-quantum-cu130.17.0 from pip (macOS arm64,qpp-cpu), with the installedkernel/kernel_builder.pyreplaced bymain's (16e37c7) for the before run and by this branch's for the after run.On
main:With this change:
Edge cases and unchanged behaviour checked
In the running library (shown in the video):
kernel.exp_pauli(np.float32(0.5), q, "XX")builds and samples00/11.kernel.givens_rotation(np.int64(1), q[0], q[1])afterx(q[0])builds and samples01/10.make_kernel(float)parameter angle and afloatliteral angle in one kernel still build and sample.By tests only:
test_non_float_angle[1 | np.int64(1) | np.float32(1.0)](new):ry,u3,exp_pauliandgivens_rotationwith each angle type give the same state as with1.0.Tests
Run against the 0.17.0 wheel with
python/cudaq/kernel/kernel_builder.pyfrommainand then from this branch (the rest of the installed package unchanged):The other
python/tests/builder/files (test_NoiseModel,test_encoding,test_observe,test_optimizer,test_qalloc_init*,test_qpp_target,test_quake_value,test_resource_metrics,test_sample*,test_state,test_translate, ...) pass the same onmainand on this branch.yapf --style google --diff(v0.40.2, the pre-commit version) reports no changes. I did not build CUDA-Q from source or run the C++ / lit suites; CI is the real check for those.AI tools (Claude Code) assisted with this change; the bug was reproduced on main and the fix verified as shown.