qml.devices.preprocess.device_resolve_dynamic_wires

device_resolve_dynamic_wires(tape, wires)[source]

Allocate dynamic wires in a manner consistent with the provided device wires.

Parameters:
  • tape (QuantumScript) – a circuit that may contain dynamic wire allocation

  • wires (None| Wires) – the device wires

If device wires are provided, possible values for dynamic wires are determined from device wires not present in the tape.

>>> from pennylane.devices.preprocess import device_resolve_dynamic_wires
>>> def f():
...     qml.H(0)
...     with qml.allocation.allocate(1) as wires:
...         qml.X(wires)
...     with qml.allocation.allocate(1) as wires:
...         qml.X(wires)
>>> transformed = device_resolve_dynamic_wires(f, wires=qml.wires.Wires((0, "a", "b")))
>>> print(qml.draw(transformed)())
0: ──H─┤
b: ──X─┤
a: ──X─┤

If the device has no wires, then wires are allocated starting at the smallest integer that is larger than all integer wires present in the tape.

>>> transformed_None = device_resolve_dynamic_wires(f, wires=None)
>>> print(qml.draw(transformed_None)())
0: ──H──────────────┤
1: ──X──┤↗│  │0⟩──X─┤

See resolve_dynamic_wires() for a more detailed description.

Contents

Using PennyLane

Release news

Development

API

Internals