qml.workflow.construct_tape

construct_tape(qnode, level='user')[source]

Constructs the tape for a designated stage in the transform program.

Parameters:
  • qnode (QNode) – the qnode we want to get the tapes and post-processing for.

  • level (str, int, slice) – An indication of what transforms to apply before drawing. Check get_transform_program() for more information on the allowed values and usage details of this argument.

Returns:

a quantum circuit.

Return type:

tape (QuantumScript)

Raises:

ValueError – if the level argument corresponds to more than one tape.

See also

pennylane.workflow.get_transform_program() to inspect the contents of the transform program for a specified level.

Example

@qml.set_shots(10)
@qml.qnode(qml.device("default.qubit"))
def circuit(x):
    qml.RandomLayers([[1.0, 2.0]], wires=(0,1))
    qml.RX(x, wires=0)
    qml.RX(-x, wires=0)
    qml.SWAP((0,1))
    qml.X(0)
    qml.X(0)
    return qml.expval(qml.X(0) + qml.Y(0))
>>> tape = qml.workflow.construct_tape(circuit)(0.5)
>>> from pprint import pprint
>>> pprint(tape.circuit)
[RandomLayers(array([[1., 2.]]), wires=[0, 1]), RX(0.5, wires=[0]), RX(-0.5, wires=[0]), SWAP(wires=[0, 1]), X(0), X(0), expval(X(0) + Y(0))]