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 aPauliBasisState.- evaluate_operator(state: PauliBasisState[QubitT_co, PauliOperator[Never]], operator: PauliOperator[QubitT_co]) int¶
Evaluate
operatorfor the givenstate.Caution
stateandoperatormust 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
operatorforstate.- Raises:
ParityOSTypeError – If
stateis not in the basis ofoperator.ParityOSException – If
statedoesn’t contain the qubitoperatoris defined on.
- class parityos.evaluators.pauli_evaluator.HardConstraintEvaluator¶
Bases:
ConstraintEvaluator[PauliBasisState[Qubit,Z[Never]]]Implementation of
ConstraintEvaluatorthat returns infinity if at least one constraint is violated by a passedPauliBasisState.This
ConstraintEvaluatoronly supports states in theZBasis.- evaluate_constraints(state: PauliBasisState[QubitT, Z[Never]], constraints: Iterable[Constraint[QubitT]]) float¶
Evaluate
constraintsfor the givenstate.Caution
statemust be defined in theZBasis.- Parameters:
state – The state for which to evaluate
constraints.constraints – Constraints which to evaluate for
state.
- Returns:
The value of
constraintsforstate.- Raises:
ParityOSTypeError – if
stateis not defined in theZbasis.
- class parityos.evaluators.pauli_evaluator.SoftConstraintEvaluator(constraint_strength: float = 1.0)¶
Bases:
ConstraintEvaluator[PauliBasisState[Qubit,Z[Never]]]Implementation of
ConstraintEvaluatorthat counts how many constraints are violated by aPauliBasisStateand weighs that number with a globalconstraint_strength.This
ConstraintEvaluatoronly supports states in theZBasis.- 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
constraintsfor the givenstate.Caution
statemust be defined in theZBasis.- Parameters:
state – The state for which to evaluate
constraints.constraints – Constraints which to evaluate for
state.
- Returns:
The value of
constraintsforstate.- Raises:
ParityOSTypeError – if
stateis not defined in theZbasis.
- 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
ProblemEvaluatorthat evaluates a givenProblemRepresentationfor a singlePauliBasisStatein the PauliZBasis.Uses an
OperatorEvaluatorand aConstraintEvaluatorobject to compute the relevant contributions. These can be (but are not restricted to) aPauliOperatorEvaluatorand aHardConstraintEvaluatororSoftConstraintEvaluator.- 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
problemfor the givenstate.- Parameters:
state – The state for which to evaluate
problem.problem – The problem which to evaluate for
state.
- Returns:
The value of
problemforstate.
- class parityos.evaluators.pauli_evaluator.AverageProblemEvaluator(problem_evaluator: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]])¶
Bases:
ProblemEvaluator[BasisStateProbabilities[Qubit,PauliBasisState[Qubit,Z[Never]]]]Implementation of
ProblemEvaluatorthat evaluates a givenProblemRepresentationfor a statistical ensemble ofPauliBasisStateinstances by computing an average of the evaluations for eachPauliBasisStateweighted by their probability.The statistical ensemble can be anything implementing
BasisStateProbabilities, for examplePauliBasisStateCountsorPauliQuantumState.Uses a
ProblemEvaluatorobject to compute the individual contributions to the weighted average. This can be (but is not restricted to) aSingleProblemEvaluator.- 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
problemfor the givenstate.- Parameters:
state – The state for which to evaluate
problem.problem – The problem which to evaluate for
state.
- Returns:
The value of
problemforstate.
- class parityos.evaluators.pauli_evaluator.MinimalProblemEvaluator(problem_evaluator: ProblemEvaluator[PauliBasisState[Qubit, Z[Never]]])¶
Bases:
ProblemEvaluator[BasisStateProbabilities[Qubit,PauliBasisState[Qubit,Z[Never]]]]Implementation of
ProblemEvaluatorthat evaluates a givenProblemRepresentationfor a statistical ensemble ofPauliBasisStateinstances by computing the minimum of all evaluations for a givenPauliBasisState.Uses a
ProblemEvaluatorobject to compute the individual values. This can be (but is not restricted to) aSingleProblemEvaluator.- 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
problemfor the givenstate.- Parameters:
state – The state for which to evaluate
problem.problem – The problem which to evaluate for
state.
- Returns:
The value of
problemforstate.