Make cirq.final_density_matrix work on classical controls #5915
Labels
area/density-matrix-simulator
area/simulation
good for learning
For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues"
kind/feature-request
Describes new functionality
triage/accepted
A consensus emerged that this bug report, feature request, or other action should be worked on
Is your feature request related to a use case or problem? Please describe.
The
ignore_measurement_results
argument offinal_density_matrix
is used for calculating the final density matrix without ever collapsing the DM due to a measurement. However this causes the function to fail when presented with a classically controlled operation.Describe the solution you'd like
This can be fixed by first passing the circuit through the
defer_measurements
transformer, before passing through thedephase_measurements
transformer. The simulator can then run on this circuit. The produced DM will include axes for the ancilla qubits that were added in the deferral transform. These can be removed by doing apartial_trace
and only retaining the axes corresponding to the original circuit's qubits.Note that within
final_density_matrix
we'd also have to apply the noise model explicitly, prior to callingdefer_measurements
, instead of just passing it into the simulator. Otherwise any noise would be applied to the ancilla "measurement qubits" as well, which is not desired.(good for learning, good first issue with some guidance) I'll leave this open for a while if someone wants to contribute.
[optional] Describe alternatives/workarounds you've considered
We could build this functionality into the simulators themselves. This would be a lot longer project and I imagine could get quite gnarly. Though a possible approach for that was prototyped and discussed here #6040 (comment)
[optional] Additional context (e.g. screenshots)
What is the urgency from your perspective for this issue? Is it blocking important work?
P3 - I'm not really blocked by it, it is an idea I'd like to discuss / suggestion based on principle
The text was updated successfully, but these errors were encountered: