qml.tape.expand_tape_state_prep¶
- expand_tape_state_prep(tape, skip_first=True)[source]¶
Expand all instances of StatePrepBase operations in the tape.
- Parameters
tape (QuantumScript) – The tape to expand.
skip_first (bool) – If
True
, will not expand aStatePrepBase
operation if it is the first operation in the tape.
- Returns
The expanded version of
tape
.- Return type
Example
If a
StatePrepBase
occurs as the first operation of a tape, the operation will not be expanded:>>> ops = [qml.StatePrep([0, 1], wires=0), qml.Z(1), qml.StatePrep([1, 0], wires=0)] >>> tape = qml.tape.QuantumScript(ops, []) >>> new_tape = qml.tape.tape.expand_tape_state_prep(tape) >>> new_tape.operations [StatePrep(array([0, 1]), wires=[0]), Z(1), MottonenStatePreparation(array([1, 0]), wires=[0])]
To force expansion, the keyword argument
skip_first
can be set toFalse
:>>> new_tape = qml.tape.tape.expand_tape_state_prep(tape, skip_first=False) [MottonenStatePreparation(array([0, 1]), wires=[0]), Z(1), MottonenStatePreparation(array([1, 0]), wires=[0])]
code/api/pennylane.tape.expand_tape_state_prep
Download Python script
Download Notebook
View on GitHub