mimiqcircuits.operations.parallel

Parallel gate operation.

Functions

to_superscript(number)

Classes

Parallel(num_repeats, op)

Copies of a gate applied in parallel on separate qubits.

class Parallel(num_repeats, op)[source]

Bases: Gate

Copies of a gate applied in parallel on separate qubits.

Parallel(n, gate) applies gate n times, each copy on its own group of qubits: the first gate.num_qubits targets go to the first copy, the next ones to the second, and so on. Its matrix is the tensor product of n copies of the gate’s matrix.

The parallel method of a gate is the usual way to build one.

Parameters:
  • num_repeats – Number of copies, at least 2.

  • op (Gate) – The gate to repeat.

Raises:

Examples

>>> from mimiqcircuits import *
>>> # three X gates on qubits 1, 2 and 3 as a single instruction
>>> c = Circuit()
>>> c.push(Parallel(3, GateX()), 1, 2, 3)
4-qubit circuit with 1 instruction:
└── ⨷ ³ X @ q[1], q[2], q[3]

>>> # a two-qubit gate in parallel: CX on (0, 1) and on (2, 3)
>>> Parallel(2, GateCX()).decompose()
4-qubit circuit with 2 instructions:
├── CX @ q[0], q[1]
└── CX @ q[2], q[3]
property num_repeats

Number of parallel copies. Read-only.

property op

The repeated gate. Read-only.

iswrapper()[source]

Return False: a plain gate does not wrap another operation.

inverse()[source]

Return the parallel copies of the inverse gate.

power(*args)[source]

Raise each parallel copy to a power.

Parameters:

*args – The exponent. When omitted, a lazy expression is returned that takes the exponent later.

Returns:

Parallel(num_repeats, Power(op, p)), or a lazy expression when called without arguments.

Return type:

Parallel

Raises:

ValueError – If more than one argument is given.

control(*args)[source]

Return the gate controlled by num_controls qubits.

Gates with a named controlled form return it directly (for example GateX().control(1) is GateCX()); otherwise the gate is wrapped in Control. The controls are the first qubits.

Parameters:

*args – The number of controls. Without it, return a LazyExpr that takes the number later.

Raises:

ValueError – If more than one argument is given.

parallel(*args)[source]

Repeat in parallel again, multiplying the number of copies.

Parameters:

*args – The extra repetition factor n. When omitted, a lazy expression is returned that takes it later.

Returns:

Parallel(num_repeats * n, op), or a lazy expression when called without arguments.

Return type:

Parallel

Raises:

ValueError – If more than one argument is given.

Examples

>>> from mimiqcircuits import *
>>> Parallel(2, GateH()).parallel(3)
⨷ ⁶ H
evaluate(d)[source]

Substitute symbols in the gate parameters and return the result.

Parameters:

d (dict) – Map from symbols to the values to substitute.

Returns:

self if nothing changed, otherwise a new gate of the same type with the substituted parameters.

Return type:

Gate

gettypekey()[source]

Return the key used to look up registered decompositions: the gate class.

get_operation()[source]

Return the operation that this one wraps, or the operation itself.

Wrappers such as Control or Power return the operation they wrap; other operations return themselves.

Returns:

Operation