mimiqcircuits.operations.barrier

Barrier operation.

Classes

Barrier(*args)

No-op that stops circuit optimizations from moving gates across it.

class Barrier(*args)[source]

Bases: Operation

No-op that stops circuit optimizations from moving gates across it.

A barrier does not change the quantum state. Compression and optimization passes do not merge, cancel or reorder operations across it.

Barrier(n) covers n qubits. Barrier() without arguments returns a lazy expression that takes the number of qubits later.

Parameters:

num_qubits – Number of qubits the barrier covers, at least 1.

Raises:

ValueError – If num_qubits is less than 1, or if more than one argument is given.

Examples

>>> from mimiqcircuits import *
>>> c = Circuit()
>>> # a single-qubit barrier on qubit 1
>>> c.push(Barrier(1), 1)
2-qubit circuit with 1 instruction:
└── Barrier @ q[1]

Pushing a single-qubit barrier to a range adds one barrier per qubit:

>>> c = Circuit()
>>> c.push(Barrier(1), range(0,4))
4-qubit circuit with 4 instructions:
├── Barrier @ q[0]
├── Barrier @ q[1]
├── Barrier @ q[2]
└── Barrier @ q[3]

A multi-qubit barrier is a single instruction across all its qubits:

>>> c = Circuit()
>>> c.push(Barrier(5),1,2,3,4,5)
6-qubit circuit with 1 instruction:
└── Barrier @ q[1:5]
__init__(num_qubits)[source]

Create a barrier on num_qubits qubits.

Parameters:

num_qubits – Number of qubits the barrier covers.

Raises:

ValueError – If num_qubits is less than 1.

inverse()[source]

Return the barrier itself; it is its own inverse.

power(p)[source]

Not supported for barriers.

Raises:

TypeError – Always.

control(num_qubits)[source]

Not supported for barriers.

Raises:

TypeError – Always.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

static isunitary()[source]

Whether the operation acts unitarily on the quantum state.

Returns:

True for gates, annotations, Barrier, and the operations that only read the state into a z-variable, such as ExpectationValue or Amplitude. False for everything else: measurements, resets, noise channels, classical operations, and containers such as Block or IfStatement.

Return type:

bool