qml.tape.plxpr_to_tape

plxpr_to_tape(plxpr, consts, *args, shots=None)[source]

Convert a plxpr into a tape.

Parameters
  • plxpr (jax.core.Jaxpr) – a pennylane variant jaxpr

  • consts (list) – the consts for the jaxpr

  • *args – the arguments to execute the plxpr with

Keyword Arguments

shots (None, int, Sequence[int], Shots) – the shots for the tape.

Returns

a single quantum script containing the quantum operations and measurements

Return type

QuantumScript

@qml.for_loop(3)
def loop(i):
    qml.X(i)

def f(x):
    loop()
    qml.adjoint(qml.S)(0)
    m0 = qml.measure(0)
    qml.RX(2*x, 0)
    return qml.probs(wires=0), qml.expval(qml.Z(1))

qml.capture.enable()

plxpr = jax.make_jaxpr(f)(0.5)
tape = qml.tape.plxpr_to_tape(plxpr.jaxpr, plxpr.consts, 1.2)
print(qml.drawer.tape_text(tape, decimals=2))
0: ──X──S†──┤↗├──RX(2.40)─┤  Probs
1: ──X────────────────────┤  <Z>
2: ──X────────────────────┤