qml.workflow.construct_tape

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

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

Warning

Using level=None is deprecated and will be removed in a future release. Please use level='device' to include all transforms.

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

  • level (None, 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

@partial(qml.set_shots, shots=10)
@qml.qnode(qml.device("default.qubit"))
def circuit(x):
    qml.RandomLayers(qml.numpy.array([[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)
>>> tape.circuit
[RandomLayers(tensor([[1., 2.]], requires_grad=True), 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))]