-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add method to get "mapped_circuit" from CircuitOperations #4188
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
Conversation
The mapped circuit is equivalent to the inner circuit, but with various maps and transformations applied (qubit map, param map, measurement map, repetitions, repetition ids). The mapping can be applied deeply, in which case contained CircuitOperations are expanded recursively, or shallowly, in which case contained CircuitOperations are left unchanged. To implement the deep mapping, we add a map_ops method on AbstractCircuit that applies a function to each op in the circuit and then recombines them in a way that preserves moment structure as much as possible. Fixes #3783
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.
This is looking great! Would be nice to add a test case with measurements in a repeated op to see that key paths are remapped properly.
circuit.map_ops(lambda op: func(op, rep)) for rep in self.repetition_ids | ||
) | ||
|
||
def mapped_op(self, deep: bool = False) -> 'cirq.CircuitOperation': |
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.
docstring
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.
Done, although I have question on this. I would normally omit docstrings for one-line methods - is the devsite documentation the primary motivation for including a docstring in such cases?
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.
LGTM
result = self.circuit.unfreeze() | ||
result = result.transform_qubits(lambda q: self.qubit_map.get(q, q)) | ||
def mapped_circuit(self, deep: bool = False) -> 'cirq.Circuit': | ||
"""Applies all maps to the cotained circuit and returns the result. |
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.
"""Applies all maps to the cotained circuit and returns the result. | |
"""Applies all maps to the contained circuit and returns the result. |
deep: If true, this will also call mapped_circuit on any | ||
CircuitOperations this object contains. |
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.
deep: If true, this will also call mapped_circuit on any | |
CircuitOperations this object contains. | |
deep: If true, this will also call mapped_circuit on any | |
CircuitOperations this object contains. |
…#4188) * Add method to get "mapped_circuit" from CircuitOperation The mapped circuit is equivalent to the inner circuit, but with various maps and transformations applied (qubit map, param map, measurement map, repetitions, repetition ids). The mapping can be applied deeply, in which case contained CircuitOperations are expanded recursively, or shallowly, in which case contained CircuitOperations are left unchanged. To implement the deep mapping, we add a map_ops method on AbstractCircuit that applies a function to each op in the circuit and then recombines them in a way that preserves moment structure as much as possible. Fixes quantumlib#3783 * Rework to handle repetition_ids properly when deep=False * Modernize and test mapped_circuit * Formatting * Clearer function names and docstrings. * Fix typos Co-authored-by: Matthew Neeley <[email protected]>
…#4188) * Add method to get "mapped_circuit" from CircuitOperation The mapped circuit is equivalent to the inner circuit, but with various maps and transformations applied (qubit map, param map, measurement map, repetitions, repetition ids). The mapping can be applied deeply, in which case contained CircuitOperations are expanded recursively, or shallowly, in which case contained CircuitOperations are left unchanged. To implement the deep mapping, we add a map_ops method on AbstractCircuit that applies a function to each op in the circuit and then recombines them in a way that preserves moment structure as much as possible. Fixes quantumlib#3783 * Rework to handle repetition_ids properly when deep=False * Modernize and test mapped_circuit * Formatting * Clearer function names and docstrings. * Fix typos Co-authored-by: Matthew Neeley <[email protected]>
This PR replaces #3785, bringing it up to date with the current state of
MeasurementKey
behavior and adding tests. Use of themapped_circuit
method will allow the moment structure ofCircuitOperation
s to be preserved during deserialization.