pauli_evaluator

Implementations of interfaces from parityos.evaluate.evaluator for evaluating Operator, Constraint and ProblemRepresentation instances for basis states in the Pauli basis (PauliBasisState).

class parityos.evaluators.pauli_evaluator.PauliOperatorEvaluator

Bases: OperatorEvaluator[PauliBasisState[Qubit, PauliOperator[Never]], PauliOperator[Qubit]]

Default implementation for evaluating a PauliOperator (X, Y, Z) for a PauliBasisState.

evaluate_operator(state: PauliBasisState[QubitT_co, PauliOperator[Never]], operator: PauliOperator[QubitT_co]) int

Evaluate operator for the given state.

Caution

state and operator must be defined in the same basis and the operator’s qubit must be contained in the 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.

Raises:
class parityos.evaluators.pauli_evaluator.HardConstraintEvaluator

Bases: ConstraintEvaluator[PauliBasisState[Qubit, Z[Never]]]

Implementation of ConstraintEvaluator that returns infinity if at least one constraint is violated by a passed PauliBasisState.

This ConstraintEvaluator only supports states in the ZBasis.

evaluate_constraints(state: PauliBasisState[QubitT, Z[Never]], constraints: Iterable[Constraint[QubitT]]) float

Evaluate constraints for the given state.

Caution

state must be defined in the ZBasis.

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

  • constraints – Constraints which to evaluate for state.

Returns:

The value of constraints for state.

Raises:

ParityOSTypeError – if state is not defined in the Z basis.

class parityos.evaluators.pauli_evaluator.SoftConstraintEvaluator(constraint_strength: float = 1.0)

Bases: ConstraintEvaluator[PauliBasisState[Qubit, Z[Never]]]

Implementation of ConstraintEvaluator that counts how many constraints are violated by a PauliBasisState and weighs that number with a global constraint_strength.

This ConstraintEvaluator only supports states in the ZBasis.

constraint_strength: float

The number of violated constraints is multiplied with this float. Defaults to 1.0.

evaluate_constraints(state: PauliBasisState[QubitT, Z[Never]], constraints: Iterable[Constraint[QubitT]]) float

Evaluate constraints for the given state.

Caution

state must be defined in the ZBasis.

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

  • constraints – Constraints which to evaluate for state.

Returns:

The value of constraints for state.

Raises:

ParityOSTypeError – if state is not defined in the Z basis.

class parityos.evaluators.pauli_evaluator.SingleProblemEvaluator(operator_evaluator: OperatorEvaluator[PauliBasisState[Qubit, Z[Never]], PauliOperator[Qubit]], constraint_evaluator: ConstraintEvaluator[PauliBasisState[Qubit, Z[Never]]])

Bases: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]]

Implementation of ProblemEvaluator that evaluates a given ProblemRepresentation for a single PauliBasisState in the Pauli Z Basis.

Uses an OperatorEvaluator and a ConstraintEvaluator object to compute the relevant contributions. These can be (but are not restricted to) a PauliOperatorEvaluator and a HardConstraintEvaluator or SoftConstraintEvaluator.

operator_evaluator: OperatorEvaluator[PauliBasisState[Qubit, Z[Never]], PauliOperator[Qubit]]

Used for evaluating any operators in the problem representation.

constraint_evaluator: ConstraintEvaluator[PauliBasisState[Qubit, Z[Never]]]

Used for evaluating any constraints in the problem representation.

evaluate_problem(state: PauliBasisState[QubitT_co, Z[Never]], 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.

class parityos.evaluators.pauli_evaluator.AverageProblemEvaluator(problem_evaluator: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]])

Bases: ProblemEvaluator[BasisStateProbabilities[Qubit, PauliBasisState[Qubit, Z[Never]]]]

Implementation of ProblemEvaluator that evaluates a given ProblemRepresentation for a statistical ensemble of PauliBasisState instances by computing an average of the evaluations for each PauliBasisState weighted by their probability.

The statistical ensemble can be anything implementing BasisStateProbabilities, for example PauliBasisStateCounts or PauliQuantumState.

Uses a ProblemEvaluator object to compute the individual contributions to the weighted average. This can be (but is not restricted to) a SingleProblemEvaluator.

problem_evaluator: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]]

Used for repeated problem evaluation in evaluate_problem.

evaluate_problem(state: BasisStateProbabilities[QubitT_co, PauliBasisState[QubitT_co, Z[Never]]], 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.

class parityos.evaluators.pauli_evaluator.MinimalProblemEvaluator(problem_evaluator: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]])

Bases: ProblemEvaluator[BasisStateProbabilities[Qubit, PauliBasisState[Qubit, Z[Never]]]]

Implementation of ProblemEvaluator that evaluates a given ProblemRepresentation for a statistical ensemble of PauliBasisState instances by computing the minimum of all evaluations for a given PauliBasisState.

Uses a ProblemEvaluator object to compute the individual values. This can be (but is not restricted to) a SingleProblemEvaluator.

problem_evaluator: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]]

Used for repeated problem evaluation in evaluate_problem.

evaluate_problem(state: BasisStateProbabilities[QubitT_co, PauliBasisState[QubitT_co, Z[Never]]], problem: ProblemRepresentation[QubitT_co]) float

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.