mimiqcircuits.operations.expectationvalue¶
Expectation value operation.
Classes
|
Compute the expectation value of an operator and store it in a z-variable. |
- class ExpectationValue(op)[source]¶
Bases:
OperationCompute the expectation value of an operator and store it in a z-variable.
For a pure state \(|\psi\rangle\) the expectation value of an operator \(O\) is
\[\langle O \rangle = \langle \psi | O | \psi \rangle,\]and for a density matrix \(\rho\) it is
\[\langle O \rangle = \mathrm{Tr}(\rho O).\]When a noisy circuit is simulated with quantum trajectories, the value is computed on the pure state of each trajectory.
The operator can be a gate or a non-unitary operator such as
SigmaPlusorProjector0. It must act on one or two qubits, except for aPauliString, which can act on any number. The instruction takes the operator’s qubits followed by one z-variable. The quantum state is not changed.- Parameters:
op (AbstractOperator) – The operator to measure.
- Raises:
TypeError – If
opis not anAbstractOperator.ValueError – If
opacts on more than two qubits and is not aPauliString.
See also
AbstractOperator,Gate,AmplitudeExamples
>>> from mimiqcircuits import * >>> ExpectationValue(GateX()) ⟨X⟩
>>> # <X> on qubit 1, stored in z-variable 1 >>> c = Circuit() >>> c.push(ExpectationValue(GateX()), 1, 1) 2-qubit, 2-zvar circuit with 1 instruction: └── ⟨X⟩ @ q[1], z[1]
>>> # non-unitary operators work too >>> c.push(ExpectationValue(SigmaPlus()), 1, 2) 2-qubit, 3-zvar circuit with 2 instructions: ├── ⟨X⟩ @ q[1], z[1] └── ⟨SigmaPlus(1)⟩ @ q[1], z[2]
>>> # a Pauli string can span any number of qubits >>> c.push(ExpectationValue(PauliString("XYZ")), 0, 1, 2, 3) 3-qubit, 4-zvar circuit with 3 instructions: ├── ⟨X⟩ @ q[1], z[1] ├── ⟨SigmaPlus(1)⟩ @ q[1], z[2] └── ⟨XYZ⟩ @ q[0:2], z[3]
- property qregsizes¶
Size of each quantum register, as a list with one entry per register.
Read-only: assigning to it raises
ValueError.
- property cregsizes¶
Size of each classical register, with one entry per register.
Empty or
Nonewhen the operation has no classical register. Read-only: assigning to it raisesValueError.
- property zregsizes¶
Size of each z-variable register, with one entry per register.
Empty or
Nonewhen the operation has no z-variable register. Read-only: assigning to it raisesValueError.
- inverse()[source]¶
Not supported.
- Raises:
NotImplementedError – Always.
- power(_)[source]¶
Not supported.
- Raises:
NotImplementedError – Always.
- static isunitary()[source]¶
Whether the operation acts unitarily on the quantum state.
- Returns:
Truefor gates, annotations,Barrier, and the operations that only read the state into a z-variable, such asExpectationValueorAmplitude.Falsefor everything else: measurements, resets, noise channels, classical operations, and containers such asBlockorIfStatement.- Return type:
- iswrapper()[source]¶
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool