mimiqcircuits.operations.gates.standard.cnx

Controlled-Controlled-X (Toffoli) and C3X gates.

Classes

GateC3X([num_controls, operation])

Four qubit Controlled-Controlled-Controlled-X gate.

GateCCX([num_controls, operation])

Three qubit Controlled-Controlled-X gate.

class mimiqcircuits.operations.gates.standard.cnx.GateCCX(num_controls=None, operation=None, *args, **kwargs)[source]

Bases: Control

Three qubit Controlled-Controlled-X gate.

By convention, the first two qubits are the controls and the third is the target.

Examples

>>> from mimiqcircuits import *
>>> GateCCX(), GateCCX().num_controls, GateCCX().num_targets, GateCCX().num_qubits
(C₂X, 2, 1, 3)
>>> GateCCX().matrix()
[1.0, 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]
[0, 0, 0, 1.0, 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, 0, 0, 0, 0, 1.0]
[0, 0, 0, 0, 0, 0, 1.0, 0]

>>> c = Circuit().push(GateCCX(), 0, 1, 2)
>>> c
3-qubit circuit with 1 instruction:
└── C₂X @ q[0:1], q[2]

>>> GateCCX().power(2), GateCCX().inverse()
(C₂ID, C₂X)
>>> GateCCX().decompose()
3-qubit circuit with 15 instructions:
├── H @ q[2]
├── CX @ q[1], q[2]
├── T† @ q[2]
├── CX @ q[0], q[2]
├── T @ q[2]
├── CX @ q[1], q[2]
├── T† @ q[2]
├── CX @ q[0], q[2]
├── T @ q[1]
├── T @ q[2]
├── H @ q[2]
├── CX @ q[0], q[1]
├── T @ q[0]
├── T† @ q[1]
└── CX @ q[0], q[1]
__init__(num_controls=2, operation=None)[source]

Initialize a CCX (Toffoli) gate.

class mimiqcircuits.operations.gates.standard.cnx.GateC3X(num_controls=None, operation=None, *args, **kwargs)[source]

Bases: Control

Four qubit Controlled-Controlled-Controlled-X gate.

By convention, the first three qubits are the controls and the fourth is the target

Examples

>>> from mimiqcircuits import *
>>> GateC3X(), GateC3X().num_controls, GateC3X().num_targets, GateC3X().num_qubits
(C₃X, 3, 1, 4)
>>> GateC3X().matrix()
[1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0]

>>> c = Circuit().push(GateC3X(), 0, 1, 2, 3)
>>> c
4-qubit circuit with 1 instruction:
└── C₃X @ q[0:2], q[3]

>>> GateC3X().power(2), GateC3X().inverse()
(C₃ID, C₃X)
>>> GateC3X().decompose()
4-qubit circuit with 31 instructions:
├── H @ q[3]
├── P((1/8)*pi) @ q[0]
├── P((1/8)*pi) @ q[1]
├── P((1/8)*pi) @ q[2]
├── P((1/8)*pi) @ q[3]
├── CX @ q[0], q[1]
├── P((-1/8)*pi) @ q[1]
├── CX @ q[0], q[1]
├── CX @ q[1], q[2]
├── P((-1/8)*pi) @ q[2]
├── CX @ q[0], q[2]
├── P((1/8)*pi) @ q[2]
├── CX @ q[1], q[2]
├── P((-1/8)*pi) @ q[2]
├── CX @ q[0], q[2]
├── CX @ q[2], q[3]
├── P((-1/8)*pi) @ q[3]
├── CX @ q[1], q[3]
├── P((1/8)*pi) @ q[3]
⋮   ⋮
└── H @ q[3]
__init__(num_controls=3, operation=None)[source]

Initialize a C3X gate.