Statistical Operations¶
Statistical operations are simulator specific mathematical operations allowing you to compute properties of the simulated quantum state without making it collapse.
All statistical operations will result in a real or complex number that will be stored in the Z-Register, and can be accessed from the results of the simulation through the zstates option, see Circuits and cloud execution page.
On this page you will find all statistical operations available on MIMIQ with explanations and examples.
Expectation value¶
Mathematical definition¶
An expectation value for a pure state \(| \psi \rangle\) is defined as
where \(O\) is an operator. With respect to a density matrix \(\rho\) it’s given by
Usage on MIMIQ¶
First we need to define the operator \(O\) of which we will compute the expectation value
>>> op = SigmaPlus()
SigmaPlus is only one of the many operators available. Of course, every gate can be used as an operator, for example op = GateZ().
However, MIMIQ also supports many non-unitary operators such as SigmaPlus, more about this on the Operators page.
To ask MIMIQ to compute the expectation value for a circuit you can create an ExpectationValue object and push() it to the circuit like this:
>>> circuit = Circuit()
>>> circuit.push(GateH(), 0)
1-qubit circuit with 1 instructions:
└── H @ q[0]
>>> # Ask to compute the expectation value
>>> ev = ExpectationValue(op)
>>> circuit.push(ev, 0, 0)
1-qubit, 1-zvar circuit with 2 instructions:
├── H @ q[0]
└── ⟨SigmaPlus(1)⟩ @ q[0], z[0]
push() function always follow the order of quantum register index first, classical register second (none in this case), and Z-register index last.0 is the index for the first qubit of the quantum register and the second 0 is the index of the Z-Register.Notice that the expectation value will be computed with respect to the quantum state of the system at the point in the circuit where the ExpectationValue is added.
Entanglement¶
MIMIQ supports statistical operations on entanglement for ordered bipartitions. For instance, for qubits [1...N] MIMIQ can compute the entanglement between the bipartitions [1...k-1] and [k...N].
For this reason when you push() an entanglement operation to a circuit, you need to give it the qubit index k that separates the two bipartitions, as well as the Z-register to store the result.
Warning
The following functions can only be used with the MPS backend.
Von Neumann Entropy¶
Mathematical definition¶
The entanglement entropy for a bipartition into subsystems A and B is defined for a pure state \(\rho = | \psi \rangle\langle \psi\) | as
where \(\rho_A = \mathrm{Tr}_B(\rho)\) is the reduced density matrix. A product state has \(\mathcal{S}(\rho_A)=0\) and a maximally entangled state between A and B gives \(\mathcal{S}(\rho_A)=1\).
We only consider bipartitions where \(A=\{1,\ldots,k-1\}\) and \(B=\{k,\ldots,N\}\),
for some k and where N is the total number of qubits.
Usage on MIMIQ¶
VonNeumannEntropy function.VonNeumannEntropy. To indicate where to create the separation into two subsystems MIMIQ will use the first qubit index given to the push() function, here is an example:>>> circuit = Circuit()
>>> # Asking to compute the Von Neumann entropy between the two subsystems separated between qubit 1 and 2
>>> circuit.push(VonNeumannEntropy(), 2, 0)
3-qubit, 1-zvar circuit with 1 instructions:
└── VonNeumannEntropy @ q[2], z[0]
Here we compute the Von neumann entropy between the two subsystems [1,2] and [3...N] and write the results into the index 0 of the Z-register.
Note
For k=1, A is empty and the Von Neumann entropy will always return 1.
Bond Dimension¶
Mathematical definition¶
The bond dimension is only defined for a matrix-product state (MPS), which can be written as (with \(i_1=i_{N+1}=1\))
Here, \(\chi_k`\) is the bond dimension, i.e. the dimension of the index \(i_k\). The first and last bond dimensions are dummies, \(chi_1=chi_{N+1}=1\). A bond dimension of 1 means there is no entanglement between the two halves of the system.
Usage on MIMIQ¶
To compute the bond dimension between two halves of a system you can use the BondDim operator and push() to the circuit like any entanglement measure:
>>> circuit = Circuit()
>>> # Asking to compute the BondDim between the second and third qubits
>>> circuit.push(BondDim(), 2, 0)
3-qubit, 1-zvar circuit with 1 instructions:
└── BondDim @ q[2], z[0]
Here we compute the bond dimension between the two subsystems [1,2] and [3...N] and write the results into index 0 of the Z-Register.
Note
For k=1 the bond dimension returned will always be 1.
Schmidt Rank¶
Mathematical definition¶
A Schmidt decomposition for a bipartition into subsystems A and B is defined for a pure state as
where \(|\alpha_i\rangle (|\beta_i\rangle)\) are orthonormal states acting on A
(B). The Schmidt rank is the number of terms r in the sum. A product state
gives r=1 and r>1 signals entanglement.
We only consider bipartitions where \(A=\{1,\ldots,k-1\}\) and \(B=\{k,\ldots,N\}\),
for some k and where N is the total number of qubits.
Usage on MIMIQ¶
To compute the Schmidt rank of a bipartition you can use the SchmidtRank operator and push() like all entanglement measures:
>>> circuit = Circuit()
>>> # Asking to compute the Schmidt rank between the two subsystems separated between qubits 1 and 2
>>> circuit.push(SchmidtRank(), 2, 0)
3-qubit, 1-zvar circuit with 1 instructions:
└── SchmidtRank @ q[2], z[0]
Here we compute the Schmidt rank between the two subsystems [1,2] and [3...N] and write the results into index 0 of the Z-Register.
Note
For k=1, A is empty and the Schmidt rank will always return 1.
Amplitude¶
Amplitude.Amplitude function the BitString matching the state for which you want the amplitude.BitString check the BitString documentation page.You can add the Amplitude object to the circuit exactly like any other gate:
>>> mystery_circuit = Circuit()
>>> mystery_circuit.push(GateH(), range(0, 3))
3-qubit circuit with 3 instructions:
├── H @ q[0]
├── H @ q[1]
└── H @ q[2]
>>> # Define the Amplitude operator
>>> amp = Amplitude(BitString("101"))
>>> # Add the amplitude operator to the circuit and write the result in the first complex number of the Z-Register
>>> mystery_circuit.push(amp, 0)
3-qubit, 1-zvar circuit with 4 instructions:
├── H @ q[0]
├── H @ q[1]
├── H @ q[2]
└── Amplitude(bs"101") @ z[0]
This will extract the amplitude of the basis state \(\ket{101}\). When adding the amplitude operation you do not need to give it any specific qubit target, the only index needed is for the Z-register to use for storing the result.
Reference¶
- 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]
- 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
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
- 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.
- class VonNeumannEntropy[source]
Bases:
OperationRecord the bipartite von Neumann entanglement entropy in a z-variable.
For a pure state \(\rho = | \psi \rangle\langle \psi |\) split into subsystems \(A\) and \(B\), the entanglement entropy is
\[\mathcal{S}(\rho_A) = - \mathrm{Tr}(\rho_A \log_2 \rho_A) = - \mathrm{Tr}(\rho_B \log_2 \rho_B) = \mathcal{S}(\rho_B),\]where \(\rho_A = \mathrm{Tr}_B(\rho)\) is the reduced density matrix. A product state has \(\mathcal{S}(\rho_A)=0\) and a maximally entangled pair of qubits gives \(\mathcal{S}(\rho_A)=1\).
The instruction takes one qubit
kand one z-variable. The bipartition is \(A = \{0, \ldots, k-1\}\) and \(B = \{k, \ldots, N-1\}\), where \(N\) is the number of qubits. Fork = 0, \(A\) is empty and the result is always 0. The quantum state is not changed.With noise and quantum trajectories, the entropy of the pure state of each trajectory is recorded.
See also
BondDim,SchmidtRankExamples
>>> from mimiqcircuits import * >>> # entropy between qubits 0-4 and qubits 5 onwards, in z-variable 1 >>> k = 5 >>> c = Circuit() >>> c.push(VonNeumannEntropy(), k, 1) 6-qubit, 2-zvar circuit with 1 instruction: └── VonNeumannEntropy @ q[5], z[1]
- property num_qubits
Number of qubits the operation acts on.
Read-only: assigning to it raises
ValueError.
- property parnames
Names of the operation’s parameters, as a tuple of strings.
Read-only: assigning to it raises
ValueError.
- iswrapper()[source]
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool
- inverse()[source]
Return a new
VonNeumannEntropy: it does not change the state.
- 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:
- class BondDim[source]
Bases:
OperationRecord the MPS bond dimension at a cut of the system in a z-variable.
The bond dimension is only defined for a matrix-product state (MPS), so it is only meaningful with the MPS simulator. An MPS can be written as
\[|\psi \rangle = \sum_{s_1,s_2,\ldots=1}^2 \sum_{i_1}^{\chi_1} \sum_{i_2}^{\chi_2} \ldots \sum_{i_N}^{\chi_N} A^{(s_1)}_{i_0i_1} A^{(s_2)}_{i_1 i_2} A^{(s_3)}_{i_2 i_3} \ldots A^{(s_N)}_{i_{N-1}i_N} | s_1, s_2, s_3, \ldots, s_N \rangle .\]where \(\chi_k\) is the bond dimension, the dimension of the index \(i_k\). The first and last bond dimensions are dummies, \(\chi_0=\chi_N=1\). A bond dimension of 1 means there is no entanglement between the two sides of the cut.
The instruction takes one qubit
kand one z-variable. It records the dimension of the bond between qubitsk - 1andk, that is between qubits0, ..., k - 1andk, ..., N - 1. Fork = 0the result is always 1. The quantum state is not changed.See also
VonNeumannEntropy,SchmidtRankExamples
>>> from mimiqcircuits import * >>> # bond dimension between qubits 4 and 5, stored in z-variable 1 >>> k = 5 >>> c = Circuit() >>> c.push(BondDim(), k, 1) 6-qubit, 2-zvar circuit with 1 instruction: └── BondDim @ q[5], z[1]
- property num_qubits
Number of qubits the operation acts on.
Read-only: assigning to it raises
ValueError.
- property parnames
Names of the operation’s parameters, as a tuple of strings.
Read-only: assigning to it raises
ValueError.
- iswrapper()[source]
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool
- inverse()[source]
Return a new
BondDim: it does not change the state.
- 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:
- class SchmidtRank[source]
Bases:
OperationRecord the Schmidt rank of a bipartition in a z-variable.
The Schmidt decomposition of a pure state split into subsystems \(A\) and \(B\) is
\[|\psi\rangle = \sum_{i=1}^{r} s_i |\alpha_i\rangle \otimes |\beta_i\rangle,\]where \(|\alpha_i\rangle\) (\(|\beta_i\rangle\)) are orthonormal states of \(A\) (\(B\)). The Schmidt rank is the number of terms \(r\). A product state gives \(r=1\), and \(r>1\) signals entanglement.
The instruction takes one qubit
kand one z-variable. The bipartition is \(A = \{0, \ldots, k-1\}\) and \(B = \{k, \ldots, N-1\}\), where \(N\) is the number of qubits. Fork = 0, \(A\) is empty and the result is always 1. The quantum state is not changed.For a matrix-product state that is optimally compressed, the Schmidt rank equals the bond dimension (see
BondDim).See also
VonNeumannEntropy,BondDimExamples
>>> from mimiqcircuits import * >>> # Schmidt rank between qubits 0-4 and qubits 5 onwards, in z-variable 1 >>> k = 5 >>> c = Circuit() >>> c.push(SchmidtRank(), k, 1) 6-qubit, 2-zvar circuit with 1 instruction: └── SchmidtRank @ q[5], z[1]
- property num_qubits
Number of qubits the operation acts on.
Read-only: assigning to it raises
ValueError.
- property parnames
Names of the operation’s parameters, as a tuple of strings.
Read-only: assigning to it raises
ValueError.
- iswrapper()[source]
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool
- inverse()[source]
Return a new
SchmidtRank: it does not change the state.
- 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:
- class Amplitude(bs)[source]
Bases:
OperationRecord the amplitude of a computational basis state.
Amplitude(bs)reads the complex amplitude of the basis statebsin the current quantum state and stores it in a z-variable. It does not change the state. The instruction takes only the target z-variable.- Parameters:
bs (BitString) – The basis state whose amplitude is recorded.
See also
BitString,ExpectationValueExamples
>>> from mimiqcircuits import * >>> c = Circuit() >>> # prepare a Bell state >>> c.push(GateH(), 0) 1-qubit circuit with 1 instruction: └── H @ q[0] >>> c.push(GateCX(), 0, 1) 2-qubit circuit with 2 instructions: ├── H @ q[0] └── CX @ q[0], q[1] >>> # store the amplitude of |11> in z-variable 0 >>> c.push(Amplitude(BitString("11")), 0) 2-qubit, 1-zvar circuit with 3 instructions: ├── H @ q[0] ├── CX @ q[0], q[1] └── Amplitude(bs"11") @ z[0]
- 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.
- iswrapper()[source]
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool
- inverse()[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: