-
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
Add support to cirq.unitary(val)
to compute a reduced unitary when val
s decomposition can allocate new qubits
#6101
Comments
checking that the final for borrowable qubits it's necessary but not sufficient since we also need to check that the unitary after transpose is a tensor product |
A few comments TerminologyI recommend against the term "reduced unitary" since it's inconsistent with the use of the adjective "reduced" for quantum states. Reduced state of a ket is typically not a ket, but a density matrix. By analogy, a reduced unitary would not be a unitary, but a channel. However, in this case this would be misleading since we're interested in precisely the case where the resulting operation actually is a unitary. Narrow and wide might be better alternatives. DecompositionThe way we currently describe decompositions using It would be neat if the tests could determine which decompositions are meant to restore the auxiliary qubits and which aren't so that the decision whether to invoke Validation@NoureldinYosri I think your conditions are roughly correct, but what do you mean by "after transpose"? Consider a circuit In the first case, In the second case, I think it is important that we check that PerformanceThe cost of multiplying two However, we can compute Notice that if I don't know how long typical relevant decompositions are, but if every auxiliary qubit is touched by one or two gates then the above idea enables us to completely avoid multiplying (This optimization can also be described as a tensor network contraction.) |
@viathor at the moment we only have 2 types of auxillary qubits clean and borrowable. if a In particular we don't support allocating a clean qubit but leaving it in a dirty state or allocating a borrowable qubit and then leaving it in a state different from its initial state. so we have to enforce By transpose I mean reordering the matrix/qubits to the correct order. Since the original state of a borrowable qubit is not known we need only to care about the From what I have seen so far most auxiliary qubits are used in at least 3 operations. a preparation operation, a work operation and a clean up operation. I don't think we can get away with these optimizations though they will certainly help. |
@tanujkhattar how many qubits do we need to support? The sample implemention you provide asserts that the total number of qubits is less than 13. Is this the intended limit on qubits for this case? @viathor the |
@NoureldinYosri Your heuristic suggests that We could either modify |
@viathor not quite. what I mean is that the ancillas are functions of the input qubits. take for example the And gate that uses only 4 T gates (rather than 8) at the cost of one ancilla from https://algassert.com/post/1903. the ancilla will hold and value of the two input qubits so although the decomposition will have 3 qubits (so that there are 8 possible state) only 4 states will be reachable. That construction can be extended to compute the and of there are four questions attached to this issue
the simple implementation provided in the issue description fullfills only the first question. however since this issue is blocking the release of the cirq-ft I think it makes sense to start with the basic support to unblock cirq-ft and then iteratively improve the implementation to answer the other questions. |
@NoureldinYosri I'd like to explicitly call out an assumption that we make as part of #6112 When the Now, this works fine for the
cc @senecameeks I think this will become more important for your simulators PR since simply doing a |
completed in #6196 |
Is your feature request related to a use case or problem? Please describe.
As part of providing tools for allocating / deallocating qubits in #6040, we want to support gates which can allocate ancilla qubits (and clean them up) as part of their
_decompose_
method (eg: related #6081).Right now,
cirq.unitary(val)
would fail when called on an operation / gate which allocates new qubits. We should fix this.As part of #6040, we always assume that any dirty / clean ancilla qubits allocated as part of the
_decompose_
method will be correctly cleaned up within the_decompose_
method so that no new dirty qubits become part of the system outside of the OP_TREE yielded by_decompose_
. Using this assumption, we can extend thecirq.unitary(val)
implementation such that ifval
does not define a_unitary_
protocol, we can use it's decomposition to compute a reduced unitary that acts only onval.qubits
, assuming the op-tree yielded bycirq.decompose(val)
is unitary.Describe the solution you'd like
A simple implementation showing such an extension to
cirq.unitary
is given as follows:and the output, as one would expect, is
Note that this would work when
GateWithDecompose
allocates both clean and dirty qubits because for a) for clean qubits; we are interested only in the000... 0
subspace (i.e. where all input/output ancillas are zeros) and for dirty qubits picking any combination of suspace is valid (because the input dirty ancillas can be in any state and the decomposition promises to leave them back in the same state).This sample implementation works assuming that the decomposition is correct and performs no validation to verify that the decomposition indeed cleans up the newly allocated clean / dirty qubits. We can also consider extending the implementation above to perform a correctness check and raise an error if decomposition is not valid -- this is relatively straightforward for borrowed dirty qubits but I think it'd be tricky for clean qubits.
What is the urgency from your perspective for this issue? Is it blocking important work?
P0 - this should land no later than a week
cc @daxfohl @NoureldinYosri
The text was updated successfully, but these errors were encountered: