BosonicCircuit¶
- class BosonicCircuit(num_modes)¶
Bases:
objectA wrapper around
QuantumCircuitfor expressing bosonic circuits.This class maintains a reduced API compared to the full API of the underlying
QuantumCircuit. This is done to avoid exposing (among other methods) the ability to apply qubit-based gates onto a bosonic circuit, which would not be a well-defined operation in the general case.barrier()is re-exposed because it is an exception to that rule: a barrier acts on modes without interpreting them and carries no unitary content, so it is as well-defined on a bosonic register as it is on a qubit one.Initializing a circuit instance can be done with the arguments listed below.
- Parameters:
num_modes (int) – the number of bosonic modes on which this circuit acts.
Attributes
- modes¶
The bosonic mode
bitsthat this circuit acts upon.
- register: BosonicRegister¶
The inner circuit’s
BosonicRegister.
Methods
- append(gate, bargs, cargs=None, *, copy=True)¶
Appends a
BosonicGateto this circuit.- Parameters:
gate (BosonicGate) – the bosonic gate to apply.
bargs (Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]) – the bosonic modes on which this gate acts.
cargs (None) –
the classical bits on which this gate acts.
Warning
No gates of this kind are currently supported.
- Raises:
ValueError – if the provided
gateis not an instance ofBosonicGate.- Return type:
None
- barrier(*bargs, label=None)¶
Re-exposes
barrier().A barrier carries no unitary effect. It marks a synchronization point that optimization passes will not fuse gates across.
The boson-to-qubit synthesis stage maps a barrier onto every qubit of each register it touched, so it constrains the subsequent qubit-level transpilation too. Because a
B2QLayoutrelates whole registers, whose two sides differ in size (an encoding needs several qubits per mode), a barrier is deliberately not narrowed to the qubits encoding the modes it was placed on.
- compose(other, bargs=None, *, front=False, inplace=False)¶
Composes another
BosonicCircuitonto this one.The instructions of
otherare inlined into this circuit, rather than wrapped into a single gate. This mirrorscompose()with its defaultwrap=False. Thewrap=Truecounterpart is deliberately not offered: a dedicated encapsulation mechanism is planned instead, so adding a second way to box up a block of instructions here would leave two patterns solving the same problem.- Parameters:
other (BosonicCircuit) – the circuit to compose onto this one. It may act on fewer modes than this circuit, in which case
bargsselects the modes it is placed on.bargs (Qubit | QuantumRegister | int | slice | Sequence[Qubit | int] | None) – the bosonic modes of this circuit onto which
otheris placed. Defaults to all of this circuit’s modes, in order.front (bool) – whether to compose
otherbefore rather than after this circuit’s instructions.inplace (bool) – whether to modify this circuit rather than return a new one.
- Returns:
The composed circuit, or
Noneifinplaceis set.- Raises:
ValueError – if
otheris not an instance ofBosonicCircuit. Only bosonic circuits are accepted because the plaincompose()would happily inline qubit-based instructions, bypassing the type guard thatappend()enforces.CircuitError – if
otheracts on more modes than this circuit, orbargsdoes not match its width.
- Return type:
BosonicCircuit | None
- count_ops()¶
Re-exposes
count_ops().- Return type:
- decompose(gates_to_decompose=None, reps=1)¶
Re-exposes
decompose().- Parameters:
gates_to_decompose (str | type[Instruction] | Sequence[str | type[Instruction]] | None)
reps (int)
- Return type:
- repeat(reps, *, insert_barriers=False)¶
Repeats this circuit
repstimes.The repetitions are flattened: the returned circuit holds this circuit’s instructions
repstimes in sequence, rather than one gate wrapping the circuit asrepeat()produces. As a consequencecount_ops()scales withreps, anddecompose()decomposes the repeated body rather than peeling off a repetition.Flattening also leaves the gates that meet at a repetition boundary adjacent, so optimization passes can act across it. Set
insert_barriersto keep the repetitions apart instead, which places abarrier()that those passes do not fuse across.Note
This is unrelated to the
repsargument ofBosonicSuzukiTrotter, which subdivides a singleEvolutioninto more, shorter factors. Repeating a circuit holding oneEvolutionmerely multiplies its total evolution time. To converge a grouped evolution, give the gate a synthesis with severalrepsand atimeoftotal / steps, or repeat a single stepstepstimes.See also
Work with bosonic circuits works through a repeated Trotter step, including the boundary fusion and how to prevent it.
- Parameters:
reps (int) – how often this circuit should be repeated. Repeating it zero times yields an empty circuit, which is the identity.
insert_barriers (bool) – whether to place a
barrier()between consecutive repetitions. No barrier is placed after the final repetition, so the returned circuit ends on the same instruction it would without this argument.
- Returns:
A new circuit containing
repsrepetitions of this circuit.- Raises:
ValueError – if
repsis negative.- Return type: