Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
senecameeks committed Jul 17, 2024
1 parent 5966bcb commit ba04f00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 4 additions & 6 deletions cirq-core/cirq/qis/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions cirq-core/cirq/transformers/randomized_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import cirq
import numpy as np
import numpy.typing as npt
from cirq.transformers import transformer_api


Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit ba04f00

Please sign in to comment.