mimiqcircuits.classical

Classical operations and utilities.

class mimiqcircuits.classical.SetBit0[source]

Bases: AbstractClassical

SetBit0 operation.

Classical operation that sets a classical bit to 0. 0 → 0 and 1 → 0.

Examples

>>> from mimiqcircuits import *
>>> not_op = SetBit0()
>>> not_op.name
'set0'
>>> c = Circuit()
>>> c.push(SetBit0(), 1)
2-bit circuit with 1 instruction:
└── c[1] = 0
inverse()[source]
iswrapper()[source]
get_operation()[source]
format_with_targets(qubits, bits, zvars)[source]
class mimiqcircuits.classical.SetBit1[source]

Bases: AbstractClassical

SetBit1 operation.

Classical operation that sets a classical bit to 1. 0 → 1 and 1 → 1.

Examples

>>> from mimiqcircuits import *
>>> not_op = SetBit1()
>>> not_op.name
'set1'
>>> c = Circuit()
>>> c.push(SetBit1(), 1)
2-bit circuit with 1 instruction:
└── c[1] = 1
inverse()[source]
iswrapper()[source]
get_operation()[source]
format_with_targets(qubits, bits, zvars)[source]
class mimiqcircuits.classical.Not[source]

Bases: AbstractClassical

Not operation.

Represents a NOT operation that can be added to quantum circuits. Classical operation that flips a classical bit: 0 → 1 and 1 → 0.

Examples

>>> from mimiqcircuits import *
>>> not_op = Not()
>>> not_op.name
'!'
>>> c = Circuit()
>>> c.push(Not(), 1)
2-bit circuit with 1 instruction:
└── c[1] = !c[1]
inverse()[source]
iswrapper()[source]
get_operation()[source]
format_with_targets(qubits, bits, zvars)[source]
class mimiqcircuits.classical.And(N=3)[source]

Bases: AbstractClassical

Computes the bitwise AND of N-1 classical bits and stores the result in the first given bit.

Examples

>>> from mimiqcircuits import *
>>> And()
c[?0] = c[?1] & c[?2]
>>> And(8)
c[?0] = & @ c[?1:?7]
>>> c = Circuit()
>>> c.push(And(), 0, 2, 3)
4-bit circuit with 1 instruction:
└── c[0] = c[2] & c[3]

>>> c = Circuit()
>>> c.push(And(5), 0, 1, 2, 3, 4)
5-bit circuit with 1 instruction:
└── c[0] = c[1] & c[2] & c[3] & c[4]

>>> c = Circuit()
>>> c.push(And(8), 0, 1, 2, 3, 4, 5, 6, 7)
8-bit circuit with 1 instruction:
└── c[0] = & @ c[1, 2, 3, 4, 5, 6, 7]
__init__(N=3)[source]

Initializes an And operation.

Parameters:

N – The total number of classical bits (1 destination + N-1 inputs). Must be 3 or greater. Defaults to 3.

iswrapper()[source]
__repr__()[source]

Returns the string representation of the operation with placeholders.

__str__()[source]

Returns the simple string name of the operation.

format_with_targets(qubits, bits, zvars)[source]

Formats the operation with its specific target bits.

class mimiqcircuits.classical.Or(N=3)[source]

Bases: AbstractClassical

Computes the bitwise OR of N-1 classical bits and stores the result in the first given bit.

Examples

>>> from mimiqcircuits import *
>>> Or()
c[?0] = c[?1] | c[?2]
>>> Or(8)
c[?0] = | @ c[?1:?7]
>>> c = Circuit()
>>> c.push(Or(), 0, 2, 3)
4-bit circuit with 1 instruction:
└── c[0] = c[2] | c[3]

>>> c = Circuit()
>>> c.push(Or(5), 0, 1, 2, 3, 4)
5-bit circuit with 1 instruction:
└── c[0] = c[1] | c[2] | c[3] | c[4]

>>> c = Circuit()
>>> c.push(Or(8), 0, 1, 2, 3, 4, 5, 6, 7)
8-bit circuit with 1 instruction:
└── c[0] = | @ c[1, 2, 3, 4, 5, 6, 7]
__init__(N=3)[source]

Initializes an Or operation.

Parameters:

N – The total number of classical bits (1 destination + N-1 inputs). Must be 3 or greater. Defaults to 3.

iswrapper()[source]
__repr__()[source]

Returns the string representation of the operation with placeholders.

__str__()[source]

Returns the simple string name of the operation.

format_with_targets(qubits, bits, zvars)[source]

Formats the operation with its specific target bits.

class mimiqcircuits.classical.Xor(N=3)[source]

Bases: AbstractClassical

Computes the bitwise XOR of N-1 classical bits and stores the result in the first given bit.

Examples

>>> from mimiqcircuits import *
>>> Xor()
c[?0] = c[?1] ^ c[?2]
>>> Xor(8)
c[?0] = ^ @ c[?1:?7]
>>> c = Circuit()
>>> c.push(Xor(), 0, 2, 3)
4-bit circuit with 1 instruction:
└── c[0] = c[2] ^ c[3]

>>> c = Circuit()
>>> c.push(Xor(5), 0, 1, 2, 3, 4)
5-bit circuit with 1 instruction:
└── c[0] = c[1] ^ c[2] ^ c[3] ^ c[4]

>>> c = Circuit()
>>> c.push(Xor(8), 0, 1, 2, 3, 4, 5, 6, 7)
8-bit circuit with 1 instruction:
└── c[0] = ^ @ c[1, 2, 3, 4, 5, 6, 7]
__init__(N=3)[source]

Initializes an Xor operation.

Parameters:

N – The total number of classical bits (1 destination + N-1 inputs). Must be 3 or greater. Defaults to 3.

iswrapper()[source]
__repr__()[source]

Returns the string representation of the operation with placeholders.

__str__()[source]

Returns the simple string name of the operation.

format_with_targets(qubits, bits, zvars)[source]

Formats the operation with its specific target bits.

class mimiqcircuits.classical.ParityCheck(N=3)[source]

Bases: AbstractClassical

Performs a parity check on N-1 classical bits and stores the result in the first bit.

It computes the sum modulo 2 of the inputs.

Examples

>>> from mimiqcircuits import *
>>> ParityCheck()
c[?0] = ⨊ c[?1, ?2]
>>> ParityCheck(5)
c[?0] = ⨊ c[?1, ?2, ?3, ?4]
>>> c = Circuit()
>>> c.push(ParityCheck(), 0, 2, 3)
4-bit circuit with 1 instruction:
└── c[0] = ⨊ c[2, 3]

>>> c = Circuit()
>>> c.push(ParityCheck(5), 0, 1, 2, 3, 4)
5-bit circuit with 1 instruction:
└── c[0] = ⨊ c[1, 2, 3, 4]
__init__(N=3)[source]

Initializes a ParityCheck operation.

Parameters:

N – The total number of classical bits (1 destination + N-1 inputs). Must be 3 or greater. Defaults to 3.

iswrapper()[source]
__repr__()[source]

Returns the string representation of the operation with placeholders.

__str__()[source]

Returns the simple string name of the operation.

format_with_targets(qubits, bits, zvars)[source]

Formats the operation with its specific target bits.

Modules