CCXGate

class CCXGate(label=None, ctrl_state=None)[source]

CCX gate, also known as Toffoli gate.

Circuit symbol:

q_0: ──■──
       │
q_1: ──■──
     ┌─┴─┐
q_2: ┤ X ├
     └───┘

Matrix representation:

\[\begin{split}CCX q_0, q_1, q_2 = |0 \rangle \langle 0| \otimes I \otimes I + |1 \rangle \langle 1| \otimes CX = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \end{pmatrix}\end{split}\]

Note

In Qiskit’s convention, higher qubit indices are more significant (little endian convention). In many textbooks, controlled gates are presented with the assumption of more significant qubits as control, which in our case would be q_2 and q_1. Thus a textbook matrix for this gate will be:

     ┌───┐
q_0: ┤ X ├
     └─┬─┘
q_1: ──■──
       │
q_2: ──■──
\[\begin{split}CCX\ q_2, q_1, q_0 = I \otimes I \otimes |0 \rangle \langle 0| + CX \otimes |1 \rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]

Create new CCX gate.

Attributes

CCXGate.ctrl_state

Return the control state of the gate as a decimal integer.

CCXGate.decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

CCXGate.definition

Return definition in terms of other basic gates.

CCXGate.label

Return gate label

CCXGate.num_ctrl_qubits

Get number of control qubits.

CCXGate.params

return instruction params.

Methods

CCXGate.add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

CCXGate.assemble()

Assemble a QasmQobjInstruction

CCXGate.broadcast_arguments(qargs, cargs)

Validation and handling of the arguments and its relationship.

CCXGate.c_if(classical, val)

Add classical condition on register classical and value val.

CCXGate.control([num_ctrl_qubits, label, …])

Controlled version of this gate.

CCXGate.copy([name])

Copy of the instruction.

CCXGate.inverse()

Return an inverted CCX gate (also a CCX).

CCXGate.is_parameterized()

Return True .IFF.

CCXGate.mirror()

DEPRECATED: use instruction.reverse_ops().

CCXGate.power(exponent)

Creates a unitary gate as gate^exponent.

CCXGate.qasm()

Return a default OpenQASM string for the instruction.

CCXGate.repeat(n)

Creates an instruction with gate repeated n amount of times.

CCXGate.reverse_ops()

For a composite instruction, reverse the order of sub-instructions.

CCXGate.to_matrix()

Return a numpy.array for the CCX gate.