Skip to content

Add single-measure key option for Cirq converison#1043

Open
chriseclectic wants to merge 1 commit intoquantumlib:mainfrom
chriseclectic:cirq_flat_key
Open

Add single-measure key option for Cirq converison#1043
chriseclectic wants to merge 1 commit intoquantumlib:mainfrom
chriseclectic:cirq_flat_key

Conversation

@chriseclectic
Copy link

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.

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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect when the measure key is a falsy value, like "".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants