-
Notifications
You must be signed in to change notification settings - Fork 1.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
Recursive transformer / iterator #4923
Comments
|
Like for when changing measurements to dephases, given a map_operation(
circuit,
change_measure_to_dephase,
run_inside_subcircuits=True,
run_inside_classically_controlled_operations=True,
run_inside_tags=True,
preserve_tags_if_modified=False,
) or something like that, and There are probably a lot of extra features we could add. However recuring through subcircuits is certainly the top. (I'm actually not super sure about the iterate functionality. It sounded neat initially but I can't think of a solid use case for it). |
@daxfohl Please let me know if you think anything else needs to be added, for example:
|
@tanujkhattar Here's kind of what I'd expect: def test_me():
q = cirq.LineQubit(0)
circuit = cirq.Circuit(
cirq.X(q),
cirq.X(q).with_tags('t'),
cirq.X(q).with_tags('no_compile'),
cirq.X(q).with_classical_controls('m'),
cirq.CircuitOperation(cirq.FrozenCircuit(
cirq.X(q),
)),
)
def x_to_y(op: 'cirq.Operation', _) -> 'cirq.OP_TREE':
return cirq.Y(q) if op.gate == cirq.X else op
result = cirq.map_operations(circuit, x_to_y, deep=True, tags_to_ignore=('no_compile',))
expected = cirq.Circuit(
cirq.Y(q),
cirq.Y(q).with_tags('t'),
cirq.X(q).with_tags('no_compile'),
cirq.Y(q).with_classical_controls('m'),
cirq.CircuitOperation(cirq.FrozenCircuit(
cirq.Y(q),
)),
)
cirq.testing.assert_same_circuits(result, expected) But here's what it comes out to
So, the tag is removed in the 2nd one (which I'm aware is an ongoing discussion in #4956, and probably there should be a flag in Granted this is an artificial example, but something similar like increasing the exponents by 1% or something could be real-world use cases. (Also see #970, it would be nice to be able to have a simple mapping function |
From cirq sync: Let's open separate issues to track the two remaining requests, as both of them are nuanced and would need further discussion / evidence. See comments as follows:
|
…ubcircuits. (quantumlib#4934) - As requested in quantumlib#4923 - Should also be useful to simplify quantumlib#4933, cc @daxfohl
…ubcircuits. (quantumlib#4934) - As requested in quantumlib#4923 - Should also be useful to simplify quantumlib#4933, cc @daxfohl
Is your feature request related to a use case or problem? Please describe.
Would be great if there was built in support for mapping operations to automatically run in subcircuits. Otherwise all simple transformers have to do that themselves.
Describe the solution you'd like
Probably just a "run_inside_subcircuits" option in Cirq.map_operations. We should also have one for running inside tagged ops, running inside classically controlled ops, etc.
Additionally it would be nice if we had a Cirq.iterate that had the same options, so you could do something like Cirq.iterate(isinstance(cirq.X), op, run_inside_tags) and we could stop all the special handling for tagged ops. (Or maybe we make a special Cirq.isinstance specifically for this).
[optional] Describe alternatives/workarounds you've considered
[optional] Additional context (e.g. screenshots)
What is the urgency from your perspective for this issue? Is it blocking important work?
P2 - we should do it in the next couple of quarters
The text was updated successfully, but these errors were encountered: