qml.debug_state¶
-
debug_state
()[source]¶ Compute the quantum state at the current point in the quantum circuit.
Debugging measurements do not alter the state, it remains the same until the next operation in the circuit.
- Returns
quantum state of the circuit
- Return type
Array(complex)
Example
While in a “debugging context”, we can query the state as we would at the end of a circuit.
dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(x): qml.RX(x, wires=0) qml.Hadamard(wires=1) qml.breakpoint() qml.CNOT(wires=[0, 1]) return qml.expval(qml.Z(0)) circuit(1.23)
Running the above python script opens up the interactive
[pldb]
prompt in the terminal. We can query the state:[pldb] longlist 4 @qml.qnode(dev) 5 def circuit(x): 6 qml.RX(x, wires=0) 7 qml.Hadamard(wires=1) 8 9 qml.breakpoint() 10 11 -> qml.CNOT(wires=[0, 1]) 12 return qml.expval(qml.Z(0)) [pldb] qml.debug_state() array([0.57754604+0.j , 0.57754604+0.j , 0. -0.40797128j, 0. -0.40797128j])
code/api/pennylane.debug_state
Download Python script
Download Notebook
View on GitHub