mimiqcircuits.instruction

Instruction class and utilities.

Classes

Instruction(operation[, qubits, bits, zvars])

Initializes an instruction of a quantum circuit.

class mimiqcircuits.instruction.Instruction(operation, qubits=None, bits=None, zvars=None)[source]

Bases: object

Initializes an instruction of a quantum circuit.

Parameters:
  • operation (Operation) – The operation applied by the instruction.

  • qubits (tuple of int) – The qubits to apply the quantum operation to.

  • bits (tuple of int) – The classical bits to apply the quantum operation to.

Raises:
  • TypeError – If operation is not a subclass of Gate or qubits is not a tuple.

  • ValueError – If qubits contains less than 1 or more than 2 elements.

Examples

>>> from mimiqcircuits import *
>>> Instruction(GateX(),(0,),())
X @ q[0]
>>> Instruction(Barrier(4),(0,1,2,3),())
Barrier @ q[0:3]
__init__(operation, qubits=None, bits=None, zvars=None)[source]
property operation
property qubits
property bits
property zvars
get_qubits()[source]
get_bits()[source]
get_zvars()[source]
num_qubits()[source]
num_bits()[source]
num_zvars()[source]
get_operation()[source]
getparams()[source]
listvars()[source]
asciiwidth()[source]
inverse()[source]
isunitary()[source]

Check if Instruction is unitary.

Returns:

True if Instruction is unitary, False otherwise.

Return type:

bool

copy()[source]
Creates a shallow copy of the instruction.

To create a full copy use deepcopy() instead.

Returns:

A new Instruction object containing references to the same attributes as the original circuit

Return type:

Instruction

deepcopy()[source]

Creates a copy of the object and for all its attributes

Returns:

A new Instruction object fully identical the original circuit

Return type:

Instruction

decompose()[source]
evaluate(d)[source]
matrix(nq=None)[source]

Return the matrix of this instruction, expanded and reordered to act on nq qubits if specified.