qp.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 = qp.device("default.qubit", wires=2)

@qp.qnode(dev)
def circuit(x):
    qp.RX(x, wires=0)
    qp.Hadamard(wires=1)

    qp.breakpoint()

    qp.CNOT(wires=[0, 1])
    return qp.expval(qp.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     @qp.qnode(dev)
  5     def circuit(x):
  6         qp.RX(x, wires=0)
  7         qp.Hadamard(wires=1)
  8
  9         qp.breakpoint()
 10
 11  ->     qp.CNOT(wires=[0, 1])
 12         return qp.expval(qp.Z(0))
[pldb] qp.debug_state()
array([0.57754604+0.j        , 0.57754604+0.j        ,
0.        -0.40797128j, 0.        -0.40797128j])

Contents

Using PennyLane

Release news

Development

API

Internals