- 
                Notifications
    You must be signed in to change notification settings 
- Fork 706
          Add traits for Quantum dialect ops and remove AnyAttr usage
          #8083
        
          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
Conversation
Co-authored-by: Joey Carter <[email protected]>
4a56137    to
    fb5a70d      
    Compare
  
    commit 154de3c Author: Marcus Edwards <[email protected]> Date: Thu Aug 28 09:01:10 2025 -0400 Decomposition rule (#8070) ------------------------------------------------------------------------------------------------------------ **Context:** We would like to provide a way for users to specify that they are using a compute/uncompute pattern [U, V, U†] so that it may be efficiently controlled by applying controls to the "middle" operator V instead of the entire pattern. **Description of the Change:** Adds a decomposition rule and registers it under "C(ChangeOpBasis)". This rule applies ctrl only to the middle op in a compute/uncompute pattern. <img width="283" height="57" alt="image" src="https://github.com/user-attachments/assets/228b8a09-3b56-47bd-a014-d41667e0cb98" /> **Benefits:** We can now decompose controlled compute/uncompute patterns efficiently. **Possible Drawbacks:** **Related ShortCut Stories:** [sc-97007] --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Astral Cai <[email protected]> Co-authored-by: Pietropaolo Frisoni <[email protected]> Co-authored-by: ANT0N <[email protected]> Co-authored-by: Austin Huang <[email protected]> commit a77cf19 Author: Andrija Paurevic <[email protected]> Date: Thu Aug 28 08:31:11 2025 -0400 feat: freeze `dict` fields of `ExecutionConfig` using new custom `FrozenMapping` object (#8046) **Context:** Currently we can mutate the dict fields of the `ExecutionConfig`, ```python import pennylane as qml from pennylane.devices.execution_config import ExecutionConfig config = ExecutionConfig( device_options={"hi": "bye"}, gradient_keyword_arguments={"foo": "bar"} ) config.device_options["hi"] = "hello" # Should not be able to mutate this! ``` This is bad. **Description of the Change:** Creates a new `FrozenMapping` object that prevents this. **Benefits:** Fully immutable execution config. This ensures our configuration isn't being mutated along the way which could lead to unexpected results. Furthermore, this helps out with the upgrade to jax 0.7.0 as it is now hashable. **Possible Drawbacks:** Might impact ecosystem? [sc-96529] --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Astral Cai <[email protected]> Co-authored-by: Yushao Chen (Jerry) <[email protected]> commit a17daca Author: ringo-but-quantum <[email protected]> Date: Thu Aug 28 09:51:46 2025 +0000 [no ci] bump nightly version commit b9a0cfa Author: Mehrdad Malek <[email protected]> Date: Wed Aug 27 19:09:57 2025 -0400 Add elementwise operationss to Stablehlo dialect in Python compiler (#8084) **Context:** Adds All the missing element-wise operations to the stablehlo dialect in python compiler. **Description of the Change:** We organized elementwise operations into logical modules (unary.py, binary.py, other.py) New Elementwise Operation Classes: - Unary Elementwise Operations (20 operations): `ConvertOp`, `CosineOp`, `ExponentialMinusOneOp`, `ExponentialOp`, `FloorOp`, `ImagOp`, `IsFiniteOp`, `LogOp`, `LogPlusOneOp`, `LogisticOp`, `NegateOp`, `RealOp`, `RoundNearestAfzOp`, `RoundNearestEvenOp`, `RsqrtOp`, `SignOp`, `SineOp`, `SqrtOp`, `TanOp`, `TanhOp` - Binary Elementwise Operations (6 operations): `ComplexOp`, `DivideOp`, `MaximumOp`, `MinimumOp`, `PowerOp`, `RemainderOp` - Other Operations (5 operations): `ClampOp`, `CompareOp`, `MapOp`, `ReducePrecisionOp`, `SelectOp` New Traits: - `Elementwise` - `SameOperandsAndResultShape` - `SameOperandsElementType` New Constraint: - `NestedTupleOfConstraint` **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Mudit Pandey <[email protected]> commit 2e42d23 Author: Astral Cai <[email protected]> Date: Wed Aug 27 16:15:06 2025 -0400 Refactor decompositions to use dynamic wire allocation (#8024) **Context:** **Description of the Change:** Updates decompositions for controlled operators to use dynamic wire allocation No updates have been made to templates. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-94401] --------- Co-authored-by: Isaac De Vlugt <[email protected]> Co-authored-by: Mudit Pandey <[email protected]> Co-authored-by: Marcus Edwards <[email protected]> Co-authored-by: Yushao Chen (Jerry) <[email protected]> commit de04d85 Author: David Wierichs <[email protected]> Date: Wed Aug 27 22:02:03 2025 +0200 Stop queueing from within `qml.pauli.PauliWord.operation` and `qml.pauli.PauliSentence.operation` (#8136) **Context:** Queuing behaviour is inconsistent due to caching, see bug report. **Description of the Change:** Stop queuing altogether from within the mentioned methods. **Benefits:** Consistent queuing behaviour. **Possible Drawbacks:** Stopping the queuing system for each call to `.operation` might be a performance regression (because in many cases there was no queuing anyways, so now we just do extra work of toggling the recording status, I suppose). **Related GitHub Issues:** Fixes #8135 [sc-98282] commit 08d58a7 Author: Simone Gasperini <[email protected]> Date: Wed Aug 27 15:51:24 2025 -0400 Implement strategy for smart shots distribution (#7988) When estimating the expectation value of a Hamiltonian written as a linear combination of several terms, we usually need to partition it into groups of mutually-commuting terms which can be measured simultaneously. Given a fixed total number of measurement shots, a crucial task is to determine the optimal allocation of these shots across the measurements for each commuting group. The goal of this strategy is to finally combine the individual expectation values to produce the best estimate of the whole original Hamiltonian. For example, we might want to weight the number of shots for each group based on the coefficients of its terms. The aim of this PR is to set the ground for this "smart" shots distribution and to integrate this strategy into the already existing `split_non_commuting` transform. Here we focus on the simple case of a circuit measuring the expectation value of a single Hamiltonian, but the idea can be generalized for multiple Hamiltonians as well. Let's show an example considering the following case: ```python import pennylane as qml coeffs = [10, 0.1, 20, 100, 0.2] observables = [ qml.X(0) @ qml.Y(1), qml.Z(0) @ qml.Z(2), qml.Y(1), qml.X(1) @ qml.X(2), qml.Z(0) @ qml.Z(1) @ qml.Z(2) ] shots = 10000 ham = qml.Hamiltonian(coeffs=coeffs, observables=observables) tape = qml.tape.QuantumScript(measurements=[qml.expval(ham)], shots=shots) ``` We want to allow the user to pass a custom function to the `split_non_commuting` transform in order to define a `shot_distribution` strategy. For example: ```python from pennylane.transforms import split_non_commuting def my_shot_distribution(total_shots, coeffs_per_group): sum_per_group = np.array([np.sum(np.abs(coeffs)) for coeffs in coeffs_per_group]) prob_shots = sum_per_group / np.sum(sum_per_group) return total_shots * prob_shots new_tapes, _ = split_non_commuting(tape, shot_distribution=my_shot_distribution) for new_tape in new_tapes: print(new_tape.measurements, new_tape.shots) ``` ``` [expval(X(0) @ Y(1)), expval(Y(1))] Shots(total=2302) [expval(Z(0) @ Z(2)), expval(Z(0) @ Z(1) @ Z(2))] Shots(total=23) [expval(X(1) @ X(2))] Shots(total=7674) ``` [sc-96319] --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Yushao Chen (Jerry) <[email protected]> Co-authored-by: Isaac De Vlugt <[email protected]> Co-authored-by: Isaac De Vlugt <[email protected]> commit 57e07c7 Author: Marcus Edwards <[email protected]> Date: Wed Aug 27 14:44:16 2025 -0400 Efficiently controlled ops conjugation (#8023) ------------------------------------------------------------------------------------------------------------ **Context:** We would like to provide a way for users to specify that they are using a compute / uncompute pattern U, V, U† so that it may be efficiently controlled by applying controls to the "middle" operator V instead of the entire pattern. **Description of the Change:** Adds `ChangeOpBasis` and `change_op_basis` which allow users to represent a compute / uncompute pattern using `qml.change_op_basis(U, V, U†)`. A follow-on will add a decomposition rule for controlled Conjugations which just applies controls to V. **Benefits:** Decompositions using this pattern are made more efficient. **Possible Drawbacks:** We need to re-factor existing decompositions to use `ChangeOpBasis` and `change_op_basis`. **Related ShortCut Stories:** [sc-97008] --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Astral Cai <[email protected]> Co-authored-by: Pietropaolo Frisoni <[email protected]> Co-authored-by: ANT0N <[email protected]> commit 62b73ce Author: Astral Cai <[email protected]> Date: Wed Aug 27 12:02:43 2025 -0400 matrix and cond now dequeues operators in arguments to the qfunc (#8119) **Context:** Applying the same thing in #8094 to `matrix` and `cond` **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-98196] --------- Co-authored-by: Yushao Chen (Jerry) <[email protected]> commit 10747ae Author: ringo-but-quantum <[email protected]> Date: Wed Aug 27 09:51:35 2025 +0000 [no ci] bump nightly version commit 392d005 Author: ringo-but-quantum <[email protected]> Date: Tue Aug 26 21:28:49 2025 +0000 [no ci] bump nightly version commit 97052b0 Author: Christina Lee <[email protected]> Date: Tue Aug 26 17:28:23 2025 -0400 [Capture] support for shot vectors and dynamic number of shots (#7652) **Context:** Program capture only allowed for shots to come from the device and only staticly known shots. Catalyst currently allows for dynamic numbers of shots. In order for program capture to serve as the frontend for catalyst, capture needs to be able to handle overridden shots, shot vectors, and abstract shots. **Description of the Change:** Adds a `shots_len` metadata to the qnode primitive. Then the first `shots_len` of the args describe the shots. `shots_len=0` means analytic and shots > 1 means a shot vector. **Benefits:** * Integration with `qml.set_shots` * Dynamic numbers of shots support * Shot vectors suport An example of what we can now capture is: ``` jax.config.update("jax_dynamic_shapes", True) qml.capture.enable() @qml.qnode(qml.device('default.qubit', wires=1)) def c(): return qml.sample(wires=0), qml.expval(qml.Z(0)) def w(num_shots): return qml.set_shots(c, (num_shots, 10))() jaxpr = jax.make_jaxpr(w)(3) jaxpr ``` ``` { lambda ; a:i32[]. let b:i32[] = mul a 1:i32[] c:i32[] = add 0:i32[] b _:i32[] = add c 10:i32[] d:i32[a] e:f32[] f:i32[10] g:f32[] = qnode[ device=<default.qubit device (wires=1) at 0x17be6e480> execution_config=ExecutionConfig(grad_on_execution=False, use_device_gradient=True, use_device_jacobian_product=False, gradient_method='backprop', gradient_keyword_arguments={}, device_options={'max_workers': None, 'rng': Generator(PCG64) at 0x17CDB74C0, 'prng_key': None}, interface=<Interface.JAX: 'jax'>, derivative_order=1, mcm_config=MCMConfig(mcm_method='deferred', postselect_mode=None), convert_to_numpy=True, executor_backend=<class 'pennylane.concurrency.executors.native.multiproc.MPPoolExec'>) n_consts=0 qfunc_jaxpr={ lambda ; . let h:AbstractMeasurement(n_wires=1) = sample_wires 0:i32[] i:AbstractOperator() = PauliZ[n_wires=1] 0:i32[] j:AbstractMeasurement(n_wires=None) = expval_obs i in (h, j) } qnode=<QNode: device='<default.qubit device (wires=1) at 0x17be6e480>', interface='jax', diff_method='best'> shots_len=2 ] a 10:i32[] in (d, e, f, g) } ``` **Possible Drawbacks:** Not integrated with native plxpr execution. The qnode primitive is getting clunky. **Related GitHub Issues:** [sc-97095] --------- Co-authored-by: JerryChen97 <[email protected]> commit 2e5690c Author: Yushao Chen (Jerry) <[email protected]> Date: Tue Aug 26 15:58:54 2025 -0400 Make `qnode.shots` Public Again (#8073) **Context:** Note that long ago we abandoned the `shots` specification at `QNode`. However, now with many things and contexts changed drastically, we would like to bring back a public UI for convenience and friendliness. **Description of the Change:** - [x] a new public property `shots` has been created. Its setter is blocked by errors due to exclusive access of `qml.set_shots` - [x] `QNode` now can accept `shots` kwarg as the default shots; this will take precedence over the deprecated `device.shots` **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-97581] --------- Co-authored-by: Isaac De Vlugt <[email protected]> Co-authored-by: Christina Lee <[email protected]> commit 6993524 Author: Yushao Chen (Jerry) <[email protected]> Date: Tue Aug 26 15:32:42 2025 -0400 Skip custom measurement for ionq plugin (#8126) **Context:** With deprecation of device.shots on ionq plugin, it does not support analytic mode when executed. Therefore certain measurement test should be skipped. See https://github.com/PennyLaneAI/PennyLane-IonQ/actions/runs/17146349703/job/48643340932?pr=149 for a quick look why this appears redundant. **Description of the Change:** Added a skipper for ionq device. Used the skipper for `ennylane/devices/tests/test_measurements.py::TestCustomMeasurement::test_custom_measurement` **Benefits:** **Possible Drawbacks:** [sc-98197] **Related GitHub Issues:** commit c256b7e Author: Christina Lee <[email protected]> Date: Tue Aug 26 12:29:14 2025 -0400 more informative draw error for deep circuits (#8139) **Context:** Unhelpful error message is raised when drawing very deep circuits. **Description of the Change:** Adds context to the error message. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** Fixes #8137 [sc-98283] commit a346335 Author: Mudit Pandey <[email protected]> Date: Tue Aug 26 11:50:49 2025 -0400 [Unified compiler] Add constraints for tensors and memrefs that allow richer constraints (#8120) Add new constraints for providing ways to constrain the element type, and either shape or rank of the containers. The new constraints allow constraining the exact shape of the containers, or the rank. The rank can be constrained to a single rank, or to a set of possible ranks. [sc-98077] --------- Co-authored-by: Joey Carter <[email protected]> commit ed7aacd Author: ringo-but-quantum <[email protected]> Date: Tue Aug 26 09:51:47 2025 +0000 [no ci] bump nightly version commit 73066dd Author: Diksha Dhawan <[email protected]> Date: Mon Aug 25 21:11:20 2025 -0400 Added a template for estimating the resources for trotterization of a Hamiltonian (#7910) **Context:** Added templates for estimating the resources for trotterization of a Hamiltonian based on Trotter-Suzuki formula. **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-94207] --------- Co-authored-by: Jay Soni <[email protected]> Co-authored-by: Soran Jahangiri <[email protected]> commit 45d6d13 Author: Mehrdad Malek <[email protected]> Date: Mon Aug 25 17:04:00 2025 -0400 Extend the StableHLO dialect in the Python Compiler (#8036) **Context:** Currently StableHLO dialect in xdsl contains a small subset of operations available in the OpenXLA repo. A full list of categorized operations can be found [here](https://github.com/openxla/stablehlo/blob/main/docs/interpreter_status.md#stablehlo-ops-categories) **Description of the Change:** Creates a local shim which mirrors the existing upstream operations as well as allowing us to extend the stablehlo to include more operation. **Benefits:** **Possible Drawbacks:** This PR should be upstreamed once the StableHLO migration from xdsl is complete **Related GitHub Issues:**
| Hello. You may have forgotten to update the changelog! 
 | 
| Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@           Coverage Diff           @@
##           master    #8083   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         548      548           
  Lines       56845    56845           
=======================================
  Hits        56672    56672           
  Misses        173      173           ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks Great. Thanks @mudit2812! Just a couple of minor comments!
Co-authored-by: Mehrdad Malek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mudit2812, looks good. I just have some minor questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mudit2812 , happy to approve.
When you have a chance, please don't forget the PR(s) for visualization : )
Context:
The xDSL quantum dialect had a lot of missing traits and very permissive ins/outs definitions. This PR resolves both these issues.
Description of the Change:
AnyAttrfrom the Quantum dialect.Benefits:
Possible Drawbacks:
Related GitHub Issues:
[sc-97692] [sc-97620]