Skip to content

Commit df782ff

Browse files
authored
Remove unused method SimulationState.with_qubits (#5748)
Avoid contradictory use of the constructor `state` argument, which is required for the SimulationState base class, but unknown to its derived classes. Closes #5721
1 parent 8ef8aef commit df782ff

File tree

3 files changed

+0
-49
lines changed

3 files changed

+0
-49
lines changed

Diff for: cirq-core/cirq/sim/density_matrix_simulation_state_test.py

-14
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ class NoDetails:
7373
cirq.act_on(NoDetails(), args, qubits=())
7474

7575

76-
def test_with_qubits():
77-
original = cirq.DensityMatrixSimulationState(
78-
qubits=cirq.LineQubit.range(1), initial_state=1, dtype=np.complex64
79-
)
80-
extened = original.with_qubits(cirq.LineQubit.range(1, 2))
81-
np.testing.assert_almost_equal(
82-
extened.target_tensor,
83-
cirq.density_matrix_kronecker_product(
84-
np.array([[0, 0], [0, 1]], dtype=np.complex64),
85-
np.array([[1, 0], [0, 0]], dtype=np.complex64),
86-
),
87-
)
88-
89-
9076
def test_qid_shape_error():
9177
with pytest.raises(ValueError, match="qid_shape must be provided"):
9278
cirq.sim.density_matrix_simulation_state._BufferedDensityMatrix.create(initial_state=0)

Diff for: cirq-core/cirq/sim/simulation_state.py

-21
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,6 @@ def kronecker_product(self: TSelf, other: TSelf, *, inplace=False) -> TSelf:
173173
args._set_qubits(self.qubits + other.qubits)
174174
return args
175175

176-
def with_qubits(self: TSelf, qubits) -> TSelf:
177-
"""Extend current state space with added qubits.
178-
179-
The state of the added qubits is the default value set in the
180-
subclasses. A new state space is created as the Kronecker product of
181-
the original one and the added one.
182-
183-
Args:
184-
qubits: The qubits to be added to the state space.
185-
186-
Returns:
187-
A new subclass object containing the extended state space.
188-
"""
189-
# TODO(#5721): Fix inconsistent usage of the `state` argument in the
190-
# SimulationState base (required) and in its derived classes (unknown
191-
# in StateVectorSimulationState), then remove the pylint filter below.
192-
# pylint: disable=missing-kwoa
193-
new_space = type(self)(qubits=qubits) # type: ignore
194-
# pylint: enable=missing-kwoa
195-
return self.kronecker_product(new_space)
196-
197176
def factor(
198177
self: TSelf, qubits: Sequence['cirq.Qid'], *, validate=True, atol=1e-07, inplace=False
199178
) -> Tuple[TSelf, TSelf]:

Diff for: cirq-core/cirq/sim/state_vector_simulation_state_test.py

-14
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,6 @@ def test_measured_mixture():
269269
assert results.histogram(key='flip') == results.histogram(key='m')
270270

271271

272-
def test_with_qubits():
273-
original = cirq.StateVectorSimulationState(
274-
qubits=cirq.LineQubit.range(2), initial_state=1, dtype=np.complex64
275-
)
276-
extened = original.with_qubits(cirq.LineQubit.range(2, 4))
277-
np.testing.assert_almost_equal(
278-
extened.target_tensor,
279-
cirq.state_vector_kronecker_product(
280-
np.array([[0.0 + 0.0j, 1.0 + 0.0j], [0.0 + 0.0j, 0.0 + 0.0j]], dtype=np.complex64),
281-
np.array([[1.0 + 0.0j, 0.0 + 0.0j], [0.0 + 0.0j, 0.0 + 0.0j]], dtype=np.complex64),
282-
),
283-
)
284-
285-
286272
def test_qid_shape_error():
287273
with pytest.raises(ValueError, match="qid_shape must be provided"):
288274
cirq.sim.state_vector_simulation_state._BufferedStateVector.create(initial_state=0)

0 commit comments

Comments
 (0)