mimiqcircuits.operations.expectationvalue

Expectation value operation.

Classes

ExpectationValue(op)

Compute the expectation value of an operator and store it in a z-variable.

class ExpectationValue(op)[source]

Bases: Operation

Compute 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 SigmaPlus or Projector0. It must act on one or two qubits, except for a PauliString, 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 op is not an AbstractOperator.

  • ValueError – If op acts on more than two qubits and is not a PauliString.

See also

AbstractOperator, Gate, Amplitude

Examples

>>> 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]
opname()[source]

Return "ExpectationValue".

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 None when the operation has no classical register. Read-only: assigning to it raises ValueError.

property zregsizes

Size of each z-variable register, with one entry per register.

Empty or None when the operation has no z-variable register. Read-only: assigning to it raises ValueError.

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:

True for gates, annotations, Barrier, and the operations that only read the state into a z-variable, such as ExpectationValue or Amplitude. False for everything else: measurements, resets, noise channels, classical operations, and containers such as Block or IfStatement.

Return type:

bool

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

asciiwidth(qubits, bits=[], zvars=[])[source]

Return the width of the operation in ASCII circuit drawings.

get_operation()[source]

Return the measured operator, op.

getparams()[source]

Return the parameters of the measured operator.

evaluate(d)[source]

Substitute values for the symbols in the operation’s parameters.

Operations without symbolic parameters may return themselves.

Parameters:

d (dict) – Map from symbols (or their names) to values.

Returns:

The operation with the symbols substituted.

Return type:

Operation