qml.debug_expval¶
- debug_expval(op)[source]¶
Compute the expectation value of an observable 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.
- Parameters
op (Operator) – the observable to compute the expectation value for.
- Returns
expectation value of the operator
- Return type
complex
Example
While in a “debugging context”, we can query the expectation value of an observable 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.state() circuit(1.23)
Running the above python script opens up the interactive
[pldb]
prompt in the terminal. We can query the expectation value:[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.state() [pldb] qml.debug_expval(qml.Z(0)) 0.33423772712450256
code/api/pennylane.debug_expval
Download Python script
Download Notebook
View on GitHub