Adds tools for appending randomized measurement bases and processing renyi entropy from bitstring#6664
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6664 +/- ##
========================================
Coverage 97.82% 97.82%
========================================
Files 1068 1072 +4
Lines 91919 92029 +110
========================================
+ Hits 89917 90027 +110
Misses 2002 2002 ☔ View full report in Codecov by Sentry. |
| num_unitaries: int, | ||
| subsystem: Sequence[str | int] | None = None, | ||
| qubit_mapping: Mapping[int, str | int] | None = None, | ||
| rng: np.random.Generator | None = None, |
There was a problem hiding this comment.
I know it's a common code pattern in Cirq but it's a harmful practice. please pass rng to unitaries_to_moment instead
This could be written as a transformer that just appends the random measurements once; then |
eliottrosenberg
left a comment
There was a problem hiding this comment.
Thanks, Seneca! This is getting very close; just some small suggestions.
| 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) |
There was a problem hiding this comment.
Maybe instead of cirq.measure_each(*qubits) we should use cirq.M(*qubits, key='m') to make it easier to extract the bitstrings to feed into process_renyi_entropy_from_bitstrings. (As it is, each qubit has a separate measurement key; this would give one key for the multi-qubit measurement.)
Co-authored-by: Noureldin <noureldinyosri@gmail.com>
Co-authored-by: Noureldin <noureldinyosri@gmail.com>
|
|
||
| @transformer_api.transformer | ||
| class RandomizedMeasurements: | ||
| """A transformer that appends a moment of random rotations to map qubits to |
There was a problem hiding this comment.
I didn't notice that you also add the measurement operation.
| """A transformer that appends a moment of random rotations to map qubits to | |
| """A transformer that appends necessery operations to measure in random pauli bases.""" |
…renyi entropy from bitstring (quantumlib#6664) * add utilities for processing renyi entropy and appending randomized measurements + tests * nit: update test comments * address comments * fix np array shape which changes test solution * Address comments and fix bug * address comments * use zip and itertools and update to transformer * rm print * type check * Update cirq-core/cirq/qis/entropy.py Co-authored-by: Noureldin <noureldinyosri@gmail.com> * Update cirq-core/cirq/transformers/randomized_measurements.py Co-authored-by: Noureldin <noureldinyosri@gmail.com> * comments * line too long --------- Co-authored-by: Noureldin <noureldinyosri@gmail.com>
…renyi entropy from bitstring (quantumlib#6664) * add utilities for processing renyi entropy and appending randomized measurements + tests * nit: update test comments * address comments * fix np array shape which changes test solution * Address comments and fix bug * address comments * use zip and itertools and update to transformer * rm print * type check * Update cirq-core/cirq/qis/entropy.py Co-authored-by: Noureldin <noureldinyosri@gmail.com> * Update cirq-core/cirq/transformers/randomized_measurements.py Co-authored-by: Noureldin <noureldinyosri@gmail.com> * comments * line too long --------- Co-authored-by: Noureldin <noureldinyosri@gmail.com>
Requested by our NISQ team, this PR:
RandomizedMeasurementclass to the experiment folder.Notably this PR does not create a new transformer since append_random_measurements returns a sequence of circuits and thus violates the transformer api contract.
CI passes once #6662 is merged