-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds tools for appending randomized measurement bases and processing renyi entropy from bitstring #6664
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-authored-by: Noureldin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just small nit
|
||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]> * Update cirq-core/cirq/transformers/randomized_measurements.py Co-authored-by: Noureldin <[email protected]> * comments * line too long --------- Co-authored-by: Noureldin <[email protected]>
Requested by our NISQ team, this PR:
RandomizedMeasurement
class 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