Skip to content

Commit

Permalink
Remove unused method SimulationState.with_qubits (quantumlib#5748)
Browse files Browse the repository at this point in the history
Avoid contradictory use of the constructor `state` argument,
which is required for the SimulationState base class,
but unknown to its derived classes.

Closes quantumlib#5721
  • Loading branch information
pavoljuhas authored Jul 13, 2022
1 parent 04c02aa commit 331d009
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 49 deletions.
14 changes: 0 additions & 14 deletions cirq/sim/density_matrix_simulation_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ class NoDetails:
cirq.act_on(NoDetails(), args, qubits=())


def test_with_qubits():
original = cirq.DensityMatrixSimulationState(
qubits=cirq.LineQubit.range(1), initial_state=1, dtype=np.complex64
)
extened = original.with_qubits(cirq.LineQubit.range(1, 2))
np.testing.assert_almost_equal(
extened.target_tensor,
cirq.density_matrix_kronecker_product(
np.array([[0, 0], [0, 1]], dtype=np.complex64),
np.array([[1, 0], [0, 0]], dtype=np.complex64),
),
)


def test_qid_shape_error():
with pytest.raises(ValueError, match="qid_shape must be provided"):
cirq.sim.density_matrix_simulation_state._BufferedDensityMatrix.create(initial_state=0)
Expand Down
21 changes: 0 additions & 21 deletions cirq/sim/simulation_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,6 @@ def kronecker_product(self: TSelf, other: TSelf, *, inplace=False) -> TSelf:
args._set_qubits(self.qubits + other.qubits)
return args

def with_qubits(self: TSelf, qubits) -> TSelf:
"""Extend current state space with added qubits.
The state of the added qubits is the default value set in the
subclasses. A new state space is created as the Kronecker product of
the original one and the added one.
Args:
qubits: The qubits to be added to the state space.
Returns:
A new subclass object containing the extended state space.
"""
# TODO(#5721): Fix inconsistent usage of the `state` argument in the
# SimulationState base (required) and in its derived classes (unknown
# in StateVectorSimulationState), then remove the pylint filter below.
# pylint: disable=missing-kwoa
new_space = type(self)(qubits=qubits) # type: ignore
# pylint: enable=missing-kwoa
return self.kronecker_product(new_space)

def factor(
self: TSelf, qubits: Sequence['cirq.Qid'], *, validate=True, atol=1e-07, inplace=False
) -> Tuple[TSelf, TSelf]:
Expand Down
14 changes: 0 additions & 14 deletions cirq/sim/state_vector_simulation_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,6 @@ def test_measured_mixture():
assert results.histogram(key='flip') == results.histogram(key='m')


def test_with_qubits():
original = cirq.StateVectorSimulationState(
qubits=cirq.LineQubit.range(2), initial_state=1, dtype=np.complex64
)
extened = original.with_qubits(cirq.LineQubit.range(2, 4))
np.testing.assert_almost_equal(
extened.target_tensor,
cirq.state_vector_kronecker_product(
np.array([[0.0 + 0.0j, 1.0 + 0.0j], [0.0 + 0.0j, 0.0 + 0.0j]], dtype=np.complex64),
np.array([[1.0 + 0.0j, 0.0 + 0.0j], [0.0 + 0.0j, 0.0 + 0.0j]], dtype=np.complex64),
),
)


def test_qid_shape_error():
with pytest.raises(ValueError, match="qid_shape must be provided"):
cirq.sim.state_vector_simulation_state._BufferedStateVector.create(initial_state=0)

0 comments on commit 331d009

Please sign in to comment.