-
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
base: main
Are you sure you want to change the base?
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.53% 97.50% -0.04%
==========================================
Files 1095 1103 +8
Lines 99006 99609 +603
==========================================
+ Hits 96570 97120 +550
- Misses 2436 2489 +53 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -77,20 +77,24 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]): | |||
|
|||
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, |
qubits: Sequence[cirq.Qid] | None = None, | ||
classical_data: cirq.ClassicalDataStore | None = None, | ||
): | ||
"""Initializes the ClassicalBasisSimState object. | ||
|
||
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
else: | ||
raise ValueError('initial_state must be an int or list[int] or np.ndarray') | ||
raise ValueError('initial_state must be an int, list[int], tuple[int], or np.ndarray') |
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.
Sequence[
raise ValueError('initial_state must be an int, list[int], tuple[int], or np.ndarray') | |
raise ValueError('initial_state must be an int or Sequence[int]') |
@@ -60,6 +60,15 @@ def test_Swap(): | |||
np.testing.assert_equal(results, expected_results) | |||
|
|||
|
|||
def test_qubit_permutation_gate(): |
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.
def test_qubit_permutation_gate(): | |
@pytest.mark.parameterize(['n', 'perm', 'state'], [ | |
(n, np.random.permutation(n).tolist(), np.random.choice(2, size=n)) for n in np.random.randint(3, 8, size=10) | |
]) | |
def test_qubit_permutation_gate(n, perm, state): | |
inv_perm = [perm.index(i) for i in range(n)] | |
target = [state[p] for p in inv_perm] | |
... | |
np.testing.assert_equal(result.measurements['key'], target) |
6b9e0a1
to
3d997b8
Compare
3d997b8
to
38408a3
Compare
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