# Operator Estimation¶

The Classiq operator estimation module computes the estimated expectation values of quantum operators $$O_i$$ given a quantum state $$|\psi\rangle$$:

$E_i = \langle\psi | O_i | \psi\rangle$

The quantum operators $$O_i$$ need not necessarily be Hermitian. Therefore, the estimates $$E_i$$, that are the main estimation results, are generally complex numbers. The quantum state is represented by a quantum circuit.

### Operators¶

Each of the operators is a sum of the Pauli operators' product:

$O_i = \sum_{j=1}^{n_i} \alpha_{i,j} P_1^{i,j} \otimes \cdots \otimes P_m^{i,j}$
• $$O_i$$ is the i-th operator in the operators' list. Every parameter with $$i$$ is related to this operator.
• $$n_i$$ is the number of distinct terms/summands in $$O_i$$.
• $$\alpha_{i,j}$$ is the complex coefficient of the j-th summand in $$O_i$$.
• $$P_k^{i,j}$$ are the Pauli operators of the relevant summand. Each operator is one of the following four: $$I$$, $$X$$, $$Y$$, $$Z$$.
• $$m$$ are the number of qubits. This property is global and cannot differ from one operator to another.

For example, the code block below defines operators, which consist of two operators, $$O_1$$ and $$O_2$$, on $$m=4$$ qubits:

from classiq.applications.chemistry import PauliOperator, PauliOperators

operators = PauliOperators(
operators=[
PauliOperator(pauli_list=[("XXYZ", 0.3 - 0.2j), ("IYYY", 1.4j)]),
PauliOperator(
pauli_list=[
("ZIII", 3.2),
("IXYI", -0.1),
("IIXY", 0.1),
("YIIX", -0.1),
("XYII", 0.1),
]
),
]
)


The operators:

$O_1 = (0.3 - 0.2i)XXYZ + 1.4i IYYY$
$O_2 = 3.2ZIII - 0.1IXYI + 0.1IIXY - 0.1YIIX + 0.1XYII$

### State¶

The quantum state $$|\psi\rangle$$ is represented by a quantum program, which is a quantum circuit.

The following snippet defines a quantum state on four qubits:

from classiq.execution import QuantumProgram

quantum_state = QuantumProgram(
code="""
OPENQASM 3;
include "stdgates.inc";
qubit[4] q;
bit[4] c;

h q[0];
h q[1];
h q[2];
h q[3];
x q[0];
z q[2];
rz(pi/4) q[3];
c = measure q;
"""
)


The quantum state can be generated by the Classiq functions. See creating circuits.

Info

The estimator supports only OpenQASM programs to describe the quantum state.

### Estimation Problem¶

Classiq combines the above operators and state into a united problem before execution.

from classiq.execution import OperatorsEstimation

operators_estimation = OperatorsEstimation(
operators=operators,
quantum_program=quantum_state,
)


The operators and state must all have the same number of qubits.

### Execution¶

from classiq import Executor

estimation_result = Executor().execute(operators_estimation)


The estimation result contains the following lists. Each list has the length of the number of operators:

• value: the estimate $$\langle\psi | O_i | \psi\rangle$$
• variance: the variance of the estimate (when the estimate is calculated from many shots)
• metadata: EstimationMetadata contains the number of shots and more execution properties