mimiqcircuits.operations.repeat¶
Repeat operation.
Functions
|
Build a |
Classes
|
Operation applied several times in a row on the same targets. |
- class Repeat(repeats, op)[source]¶
Bases:
OperationOperation applied several times in a row on the same targets.
Repeat(n, op)appliesopntimes on the same qubits, bits and z-variables. UnlikePower, it works for any operation, not only gates, and keeps the repetitions explicit: decomposing it givesncopies ofop.The
repeatmethod of a gate and therepeat()function are shorthands for it.- Parameters:
- Raises:
ValueError – If
repeatsis not a non-negativeint.TypeError – If
opis not an operation.
Examples
>>> from mimiqcircuits import * >>> from symengine import * >>> # five X gates in a row >>> Repeat(5, GateX()) ∏⁵ X
>>> Repeat(3, GateRX(Symbol("x"))) ∏³ RX(x)
>>> # nested repeats are kept as they are >>> Repeat(2, Repeat(3, GateX())) ∏² ∏³ X
>>> # without a count, repeat() returns a lazy expression >>> Parallel(2, GateH()).repeat() lazy repeat(?, ⨷ ² H)
>>> Parallel(2, GateH()).repeat()(10) ∏¹⁰ ⨷ ² H
>>> c = Circuit().push(Repeat(2, GateX()), 0) >>> c 1-qubit circuit with 1 instruction: └── ∏² X @ q[0]
>>> # decomposing gives the individual repetitions >>> Repeat(2, GateX()).decompose() 1-qubit circuit with 2 instructions: ├── X @ q[0] └── X @ q[0]
>>> Repeat(3, GateSWAP()).decompose() 2-qubit circuit with 3 instructions: ├── SWAP @ q[0:1] ├── SWAP @ q[0:1] └── SWAP @ q[0:1]
- power(pow)[source]¶
Return the repetitions of
opraised topow.- Parameters:
pow – The exponent.
- Returns:
Repeat(repeats, op.power(pow)).- Return type:
- parallel(repeat)[source]¶
Return the repetitions of
repeatparallel copies ofop.- Parameters:
repeat – Number of parallel copies.
- Returns:
Repeat(repeats, op.parallel(repeat)).- Return type:
- control(repeat)[source]¶
Return the repetitions of
opcontrolled byrepeatqubits.- Parameters:
repeat – Number of control qubits.
- Returns:
Repeat(repeats, op.control(repeat)).- Return type:
- inverse()[source]¶
Return the repetitions of the inverse of
op.- Returns:
Repeat(repeats, op.inverse()). Fails whenophas no inverse.- Return type:
- iswrapper()[source]¶
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool
- supports_canonical_rewrite()[source]¶
Whether
CanonicalRewritemay decompose this operation.Operations opt in: only those the canonical rewrite knows how to handle return
True.- Returns:
bool
- evaluate(d)[source]¶
Substitute values for the symbols in the operation’s parameters.
Operations without symbolic parameters may return themselves.
- copy()[source]¶
Return a shallow copy of the operation.
The copy shares its attributes (for example a wrapped operation) with the original. Use
deepcopy()for an independent copy.- Returns:
A new operation of the same type.
- Return type:
- repeat(*args)[source]¶
Build a
Repeatoperation, or a lazy one that waits for its count.repeat(n, op)isRepeat(n, op).repeat(op)returns a lazy expression; calling it withnbuildsRepeat(n, op).- Parameters:
*args –
(n, op)or(op,).- Returns:
The operation, or the lazy expression.
- Return type:
- Raises:
TypeError – If called with no arguments or with more than two.
Examples
>>> from mimiqcircuits import * >>> repeat(3, GateX()) ∏³ X >>> repeat(GateX())(3) ∏³ X