Skip to content

PyQTorch functions

PyQObservablesParser

Convert InputType object observables into native PyQTorch object, especially for running expectation method from PyQTorch interface class. InputType can be qadence2-expressions or any other module that implement the same methods.

build(observable) classmethod

Parses an input expression or list of expressions into a native PyQTorch object.

PARAMETER DESCRIPTION
observable

the input expression. Any qadence2-expressions expression compatible object or object with same methods.

TYPE: list[InputType] | InputType

RETURNS DESCRIPTION
Observable

An PyQTorch Observable object.

Source code in qadence2_platforms/backends/pyqtorch/functions.py
@classmethod
def build(cls, observable: list[InputType] | InputType) -> Observable:
    """
    Parses an input expression or list of expressions into a native PyQTorch object.

    Args:
        observable (list[InputType] | InputType): the input expression. Any
            qadence2-expressions expression compatible object or object with same
            methods.

    Returns:
        An PyQTorch Observable object.
    """

    res: list[Module] | Module
    if isinstance(observable, list):
        res = cls._iterate_over_obs(observable)
    else:
        res = [cls._get_op(observable)]
    return Observable(res)