Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq-core/cirq/sim/clifford/clifford_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def apply_unitary(self, op: 'cirq.Operation'):
def apply_measurement(
self,
op: 'cirq.Operation',
measurements: Dict[str, List[np.ndarray]],
measurements: Dict[str, List[int]],
prng: np.random.RandomState,
collapse_state_vector=True,
):
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/sim/clifford/clifford_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ def test_invalid_apply_measurement():
state = cirq.CliffordState(qubit_map={q0: 0})
measurements = {}
with pytest.raises(TypeError, match='only supports cirq.MeasurementGate'):
_ = state.apply_measurement(cirq.H(q0), measurements, np.random.RandomState())
state.apply_measurement(cirq.H(q0), measurements, np.random.RandomState())
assert measurements == {}


def test_valid_apply_measurement():
q0 = cirq.LineQubit(0)
state = cirq.CliffordState(qubit_map={q0: 0}, initial_state=1)
measurements = {}
_ = state.apply_measurement(cirq.measure(q0), measurements, np.random.RandomState())
state.apply_measurement(cirq.measure(q0), measurements, np.random.RandomState())
assert measurements == {'q(0)': [1]}


Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/sim/state_vector_simulation_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create(
initial_state: Union[np.ndarray, 'cirq.STATE_VECTOR_LIKE'] = 0,
qid_shape: Optional[Tuple[int, ...]] = None,
dtype: Optional[Type[np.complexfloating]] = None,
buffer: Optional[List[np.ndarray]] = None,
buffer: Optional[np.ndarray] = None,
):
"""Initializes the object with the inputs.

Expand Down
7 changes: 5 additions & 2 deletions cirq-core/cirq/testing/consistent_act_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Optional
from typing import Any, cast, Optional, Type

import numpy as np

Expand Down Expand Up @@ -46,12 +46,15 @@ def state_vector_has_stabilizer(state_vector: np.ndarray, stabilizer: DensePauli
"""

qubits = LineQubit.range(protocols.num_qubits(stabilizer))
complex_dtype: Type[np.complexfloating] = np.complex64
if np.issubdtype(state_vector.dtype, np.complexfloating):
complex_dtype = cast(Type[np.complexfloating], state_vector.dtype)
args = state_vector_simulation_state.StateVectorSimulationState(
available_buffer=np.empty_like(state_vector),
qubits=qubits,
prng=np.random.RandomState(),
initial_state=state_vector.copy(),
dtype=state_vector.dtype,
dtype=complex_dtype,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, since this is in the simulation direct call path, should we just do a cast here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure state_vector.dtype is complex?
If so we can make it simpler with cast.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I misread where this is, this is in the testing of consistent act_on. Think this is fine. Not sure we can assume state_vector dtype is complex, so this works.

)
protocols.act_on(stabilizer, args, qubits)
return np.allclose(args.target_tensor, state_vector)
Expand Down