-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add QubitPermutationGate and tuple input support to ClassicalStateSimulator #7567
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
Add QubitPermutationGate and tuple input support to ClassicalStateSimulator #7567
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7567 +/- ##
=======================================
Coverage 97.50% 97.50%
=======================================
Files 1103 1103
Lines 99683 99707 +24
=======================================
+ Hits 97198 97222 +24
Misses 2485 2485 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
def __init__( | ||
self, | ||
initial_state: int | list[int] = 0, | ||
initial_state: int | list[int] | tuple[int, ...] = 0, |
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.
initial_state: int | list[int] | tuple[int, ...] = 0, | |
initial_state: int | Sequence[int] = 0, |
Args: | ||
qubits: The qubits to simulate. | ||
initial_state: The initial state for the simulation. | ||
initial_state: The initial state for the simulation. Accepts int, list[int], |
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.
initial_state: The initial state for the simulation. Accepts int, list[int], | |
initial_state: The initial state for the simulation. Accepts int or a sequence of int. |
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.
please check the definition of the permutation gate https://quantumai.google/reference/python/cirq/QubitPermutationGate
and make sure the ClassicalStateSimulator is consistent with the cirq.Simulator
3d997b8
to
38408a3
Compare
circuit = cirq.Circuit(perm_gate(*qubits), cirq.measure(*qubits, key='key')) | ||
sim = cirq.ClassicalStateSimulator() | ||
result = sim.simulate(circuit, initial_state=state) | ||
expected = [state[perm[i]] for i in range(n)] |
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.
this doesn't match the action of the state vector simulator (cirq.Simulator). if you believe the state vector simulator is the wrong one please file a bug, otherwise please make them match
38408a3
to
d6f095f
Compare
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 @Aqil-Ahmad
…ulator (quantumlib#7567) ## Summary This PR enhances the `ClassicalStateSimulator` by adding support for `QubitPermutationGate` operations and enabling `tuple[int]` input for the initial state parameter. Fixes : quantumlib#7566 ## Changes Made - **QubitPermutationGate Support**: Implemented handling of qubit permutation operations in `_act_on_fallback_` method - **Tuple Input Support**: Added support for `tuple[int, ...]` as initial state input alongside existing `int`, `list[int]`, and `np.ndarray` options - **Documentation Updates**: Updated docstrings and error messages - **Testing**: Added test coverage for: - QubitPermutationGate operations with various permutations - Tuple input validation and functionality - Edge cases and error conditions ## Testing - [x] All existing tests pass - [x] New tests for QubitPermutationGate functionality and tuple input handling --------- Co-authored-by: Noureldin <[email protected]>
Summary
This PR enhances the
ClassicalStateSimulator
by adding support forQubitPermutationGate
operations and enablingtuple[int]
input for the initial state parameter.Fixes : #7566
Changes Made
_act_on_fallback_
methodtuple[int, ...]
as initial state input alongside existingint
,list[int]
, andnp.ndarray
optionsTesting