diff --git a/cirq-core/cirq/qis/entropy.py b/cirq-core/cirq/qis/entropy.py index 3487491bd47..6a70ffaa428 100644 --- a/cirq-core/cirq/qis/entropy.py +++ b/cirq-core/cirq/qis/entropy.py @@ -55,7 +55,7 @@ def _bitstring_format_helper( ) -> npt.NDArray[np.int8]: """Formats the bitstring for analysis based on the selected subsystem. Args: - measured_bitstrings: Measured bitstring + measured_bitstrings: List of sampled measurement outcomes as a numpy array of bitstrings. subsystem: Subsystem of interest Returns: The bitstring string for the subsystem """ @@ -85,9 +85,9 @@ def process_renyi_entropy_from_bitstrings( subsystem: tuple[int] | None = None, pool: Optional[ThreadPoolExecutor] = None, ) -> float: - """Compute the renyi entropy of an array of bitstrings. + """Compute the Rényi entropy of an array of bitstrings. Args: - measured_bitstrings: Numpy array. + measured_bitstrings: List of sampled measurement outcomes as a numpy array of bitstrings. subsystem: Subsystem of interest pool: ThreadPoolExecutor used to paralelleize the computation. @@ -102,9 +102,7 @@ def process_renyi_entropy_from_bitstrings( return 0 if pool is not None: - purities = list( - executor.map(_compute_bitstrings_contribution_to_purity, list(bitstrings)) - ) + purities = list(pool.map(_compute_bitstrings_contribution_to_purity, list(bitstrings))) purity = np.mean(purities) else: diff --git a/cirq-core/cirq/transformers/randomized_measurements.py b/cirq-core/cirq/transformers/randomized_measurements.py index 80a6710dce9..b1653765c00 100644 --- a/cirq-core/cirq/transformers/randomized_measurements.py +++ b/cirq-core/cirq/transformers/randomized_measurements.py @@ -17,7 +17,6 @@ import cirq import numpy as np -import numpy.typing as npt from cirq.transformers import transformer_api @@ -63,20 +62,20 @@ def __call__( pre_measurement_moment = self.unitaries_to_moment(pre_measurement_unitaries_list, qubits) return cirq.Circuit.from_moments( - *circuit.moments, pre_measurement_moment, cirq.measure_each(*qubits) + *circuit.moments, pre_measurement_moment, cirq.M(*qubits, key='m') ) def _generate_unitaries_list(self, rng: np.random.Generator, num_qubits: int) -> Sequence[Any]: """Generates a list of pre-measurement unitaries.""" - pauli_strings = rng.choice(["X", "Y", "Z"], size=(num_qubits)) + pauli_strings = rng.choice(["X", "Y", "Z"], size=num_qubits) if self.subsystem is not None: for i in range(pauli_strings.shape[0]): if i not in self.subsystem: pauli_strings[i] = np.array("Z") - return pauli_strings + return pauli_strings.tolist() def unitaries_to_moment( self, unitaries: Sequence[Literal["X", "Y", "Z"]], qubits: Sequence[Any]