qp.testing.plxpr_to_tape

plxpr_to_tape(plxpr, consts, *args)[source]

Convert a plxpr into a tape.

Parameters:
  • plxpr (jax.extend.core.Jaxpr) – the jaxpr to extract a program from

  • consts (list) – the consts for the jaxpr

  • *args – the arguments to execute the plxpr with

Returns:

a single quantum script containing the quantum operations and measurements

Return type:

QuantumScript

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

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

qp.capture.enable()

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