evaluator

Classes for evaluating Operator, Constraint and ProblemRepresentation instances under a State.

This module contains 3 abstract base classes to facilitate easy and flexible custom evaluation:

All base classes are generic over the operator, state and problem classes. Custom building of evaluation pipelines of custom types is best achieved using composition over inheritance.

For examples, see the implementations for basis states in the Pauli basis (PauliBasisState) in parityos.evaluate.pauli_evaluator.

class parityos.evaluators.evaluator.OperatorEvaluator

Bases: ABC, Generic[StateT_contra, OperatorT_contra]

Abstract base class for evaluating Operator, OperatorProduct and OperatorPolynomial instances.

Subclasses must implement abstract evaluate_operator and may override evaluate_operator_product and evaluate_operator_polynomial for which a default implementation is given here.

abstractmethod evaluate_operator(state: StateT_contra, operator: OperatorT_contra) float

Evaluate operator for the given state.

Parameters:
  • state – The state for which to evaluate operator.

  • operator – The operator which to evaluate for state.

Returns:

The value of operator for state.

evaluate_operator_product(state: StateT_contra, operator_product: OperatorProduct[OperatorT_contra]) float

Default implementation of OperatorProduct evaluation as a product of single Operator evaluations.

Subclasses may override this implementation.

Parameters:
  • state – The state for which to evaluate operator_product.

  • operator_product – The operator product which to evaluate for state.

Returns:

The value of operator_product for state.

evaluate_operator_polynomial(state: StateT_contra, operator_polynomial: OperatorPolynomial[OperatorT_contra]) Symbolic | complex

Default implementation of OperatorPolynomial evaluation as a weighted sum of single OperatorProduct term evaluations.

Subclasses may override this implementation.

Parameters:
  • state – The state for which to evaluate operator_polynomial.

  • operator_polynomial – The operator polynomial which to evaluate for state.

Returns:

The value of operator_polynomial for state.

class parityos.evaluators.evaluator.ConstraintEvaluator

Bases: Generic[StateT_contra], ABC

Abstract base class for evaluating Constraint instances.

Subclasses must implement abstract evaluate_constraints Subclasses may take custom or built-in OperatorEvaluator objects as helpers.

abstractmethod evaluate_constraints(state: StateT_contra, constraints: Iterable[ConstraintT]) Symbolic | complex

Evaluate constraints for the given state.

Parameters:
  • state – The state for which to evaluate constraints.

  • constraints – Constraints which to evaluate for state.

Returns:

The value of constraints for state.

class parityos.evaluators.evaluator.ProblemEvaluator

Bases: Generic[StateT_contra], ABC

Abstract base class for evaluating ProblemRepresentation instances.

Subclasses must implement abstract evaluate_problem. Subclasses may take custom or built-in OperatorEvaluator and/or ConstraintEvaluator objects as helpers.

abstractmethod evaluate_problem(state: StateT_contra, problem: ProblemRepresentation[QubitT_co]) Symbolic | complex

Evaluate problem for the given state.

Parameters:
  • state – The state for which to evaluate problem.

  • problem – The problem which to evaluate for state.

Returns:

The value of problem for state.