Make ControlledGate work with gates that only provide a decomposition
See original GitHub issueThe following should work:
import cirq
class G(cirq.TwoQubitGate):
def _decompose_(self, qubits):
a, b = qubits
yield cirq.X(a)**0.5
yield cirq.H(b)
yield cirq.CZ(a, b)
cg = cirq.ControlledGate(G())
x, y, z = cirq.LineQubit.range(3)
c = cirq.Circuit.from_ops(cg(x, y, z))
print(c.to_unitary_matrix())
but currently it raises an exception:
Operation without a known matrix or decomposition: cirq.ControlledGate(sub_gate=[...G...].on(cirq.LineQubit(0), cirq.LineQubit(1), cirq.LineQubit(2))
because ControlledGate
doesn’t have a _decompose_
method. This issue is to add that method.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to decompose a multi-target controlled gate?
Firstly one needs to decompose the given U operator into gates, then for each gate construct the controlled version of it.
Read more >Quantum Gate Decomposition Algorithms - OSTI.gov
Two-qubit gates operate through the relatively weak coupling of two qubits, making such gates more difficult to implement. Therefore, efficient de- compositions ...
Read more >Gates, States, and Circuits - Gavin E. Crooks
The geometric representation of 1-qubit states by the Bloch sphere only works because of a mathematical accident that doesn't generalize.
Read more >Method for reducing a uniformly controlled gate into nearest ...
A collection of quantum gates is called universal if it can be used to construct any n-qubit gate. In... | Decomposition, Quantum and...
Read more >cirq.SupportsDecompose - Google Quantum AI
All decomposition methods should ultimately terminate on basic 1-qubit and 2-qubit gates included by default in Cirq. Cirq does not make any ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@balopat Go for it 😃
This ended up being more complicated than I expected, because it requires defining a controlled operation and understanding how the decomposition machinery works in detail.