CXGate

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

Controlled-X gate.

Circuit symbol:

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

Matrix representation:

\[\begin{split}CX\ q_0, q_1 = I \otimes |0\rangle\langle0| + X \otimes |1\rangle\langle1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 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_1. Thus a textbook matrix for this gate will be:

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

In the computational basis, this gate flips the target qubit if the control qubit is in the \(|1\rangle\) state. In this sense it is similar to a classical XOR gate.

\[`|a, b\rangle \rightarrow |a, a \oplus b\rangle`\]

Create new CX gate.

Attributes

CXGate.ctrl_state

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

CXGate.decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

CXGate.definition

Return definition in terms of other basic gates.

CXGate.label

Return gate label

CXGate.num_ctrl_qubits

Get number of control qubits.

CXGate.params

return instruction params.

Methods

CXGate.add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

CXGate.assemble()

Assemble a QasmQobjInstruction

CXGate.broadcast_arguments(qargs, cargs)

Validation and handling of the arguments and its relationship.

CXGate.c_if(classical, val)

Add classical condition on register classical and value val.

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

Return a controlled-X gate with more control lines.

CXGate.copy([name])

Copy of the instruction.

CXGate.inverse()

Return inverted CX gate (itself).

CXGate.is_parameterized()

Return True .IFF.

CXGate.mirror()

DEPRECATED: use instruction.reverse_ops().

CXGate.power(exponent)

Creates a unitary gate as gate^exponent.

CXGate.qasm()

Return a default OpenQASM string for the instruction.

CXGate.repeat(n)

Creates an instruction with gate repeated n amount of times.

CXGate.reverse_ops()

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

CXGate.to_matrix()

Return a numpy.array for the CX gate.