Say we have a custom gate CG, defined by a unitary matrix U, and line qubits qubits in Cirq. Something like this:

import numpy
import cirq

U = np.eye(8)    # The custom unitary matrix goes here
CG = cirq.MatrixGate(U)
qubits = cirq.LineQubit.range(3)

We build the circuit as follows:

circuit = cirq.Circuit()
circuit.append(CG(qubits[0], qubits[1], qubits[2]))

Is it possible to build the circuit without explicitly specifying all the qubits? Something like circuit.append(CG(qubits)), which would apply the CG gate to all the qubits?


In Python you can say callable(*args) instead of callable(args[0], args[1], args[2]).

  • $\begingroup$ i.e. in your example you could write CG(*qubits) $\endgroup$ – dabacon Jul 30 '20 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.