-
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
Decompose protocol must create a context when given None and SimpleQubitManager must add a prefix to its qubits #6172
Conversation
…bitManager must add a prefix to its qubits
@@ -364,6 +367,11 @@ def decompose_once( | |||
TypeError: `val` didn't have a `_decompose_` method (or that method returned | |||
`NotImplemented` or `None`) and `default` wasn't set. | |||
""" | |||
if context is None: | |||
context = DecompositionContext( | |||
ops.SimpleQubitManager(prefix=f'_decompose_protocol_{time.time_ns()}') |
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.
Can we use some global counter instead of time_ns here?
It would be nice to have naming reproducibility in repeated executions.
Debugging and making sense of allocated qubit names should also get easier.
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.
added using itertools.count()
@pavoljuhas PTAL |
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 modulo small suggestion.
…bitManager must add a prefix to its qubits (quantumlib#6172)
Problem:
Before this change successive calls to
cirq.decompose_once
can break since they might endup making a gate act on the same qubits.The successive calls to
cirq.decompose_once
can happen implicitly by calling other protocols. for examplesince
has_unitary
falls todecompose_once
if the gate doesn't implement_has_unitary_
. another case is when running a simulator on a decomposed operation. the simulator will callhas_unitary
in its checks.Solution: For
cirq.decompose_once
add a unique prefix to the qubits allocated during decompose if decompose_once allocates its own qubit manager. forcirq.decompose
I think it is okay to have a constant prefix just to distinguish it from qubits allocated by other SimpleQubitManagers.