quantum_circuit::expectation_value()← Back to Class quantum_circuit
Get the expectation value by an observable Hermitian operator \(\hat{A}\). The expectation value is defined as: \[\braket{A} = \int_{-\infty}^{\infty}\psi^*(x)\hat{A}\psi(x)dx\] In the more concise Dirac notation, this is written as: \[\braket{A} = \bra{\psi}\hat{A}\ket{\psi}\]
quantum_circuit::expectation_value(a, qubit_target)
a (matrix) — An observable Hermitian operator \(\hat{A}\)qubit_target (number) — The target qubit
number — Returns the expectation value
import quantum
qc = quantum_circuit(n)
qc.x(0)
exval = qc.expectation_value(gate_z, 0) ' The Z expectation value of qubit 0
writeln(exval)
' Output:
' -1