Add single-measure key option for Cirq converison#1043
Add single-measure key option for Cirq converison#1043chriseclectic wants to merge 1 commit intoquantumlib:mainfrom
Conversation
This adds an optional kwarg to `stimcirq.stim_circuit_to_cirq_circuit` for using a fixed measure key for a all cirq.MeasurementGate ops. This will result in cirq.Result containing a single measure record array with all measurements ordered along the "instance" axis in the order they appear in the stim circuit.
| return self.num_measurements_seen - 1 | ||
|
|
||
| def get_next_measure_key(self) -> str: | ||
| return self.measure_key or str(self.get_next_measure_id()) |
There was a problem hiding this comment.
This is incorrect when the measure key is a falsy value, like "".
There was a problem hiding this comment.
Treating "" like None was the intended behavior, but I can change if you prefer.
| measure_key = "m" | ||
| for stim_circuit in stim_circuits: | ||
| cirq_circuit = stimcirq.stim_circuit_to_cirq_circuit( | ||
| stim_circuit, measure_key=measure_key |
There was a problem hiding this comment.
This is not a clear argument name. Replace it with something like fixed_measure_key or single_measure_key
|
|
||
| def stim_circuit_to_cirq_circuit(circuit: stim.Circuit, *, flatten: bool = False) -> cirq.Circuit: | ||
| def stim_circuit_to_cirq_circuit( | ||
| circuit: stim.Circuit, *, flatten: bool = False, measure_key: str | None = None |
There was a problem hiding this comment.
Is there an easy way to make this more general? For example, by passing in a lambda? Does it make sense to have more control?
There was a problem hiding this comment.
I don't think its necessary right now for the primary use of getting the chronologically ordered record array in executed cirq results. One could imagine in large circuits you might want to alias groups of output registers to different records, but at that point its probably worth thinking about bringing that into stim itself rather than the cirq conversion layer. Another option I was debating was just making this a boolean flag and hard coding the measure key (eg "m" or "rec") for simplicity.
This adds an optional kwarg to
stimcirq.stim_circuit_to_cirq_circuitfor using a fixed measure key for a all cirq.MeasurementGate ops. This will result in cirq.Result containing a single measure record array with all measurements ordered along the "instance" axis in the order they appear in the stim circuit.