How to use the blueqat.qasmparser.QasmRealExpr function in blueqat

To help you get started, we’ve selected a few blueqat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
self.rhs = rhs

    def eval(self):
        return self.lhs.eval() - self.rhs.eval()


class QasmRealMul(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() * self.rhs.eval()


class QasmRealDiv(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() / self.rhs.eval()


class QasmRealValue(QasmRealExpr):
    def __init__(self, value: float):
        self.value = value

    def eval(self):
        return self.value
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
class QasmRealExpr(QasmExpr):
    @abstractmethod
    def eval(self) -> float:
        pass


class QasmRealAdd(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() + self.rhs.eval()


class QasmRealSub(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() - self.rhs.eval()


class QasmRealMul(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() * self.rhs.eval()
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
def eval(self):
        pass

    def __repr__(self):
        if hasattr(self, 'value'):
            return f'{self.__class__.__name__}({repr(self.value)})'
        return f'{self.__class__.__name__}({repr(self.lhs)}, {repr(self.rhs)})'


class QasmRealExpr(QasmExpr):
    @abstractmethod
    def eval(self) -> float:
        pass


class QasmRealAdd(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() + self.rhs.eval()


class QasmRealSub(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() - self.rhs.eval()
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
self.rhs = rhs

    def eval(self):
        return self.lhs.eval() + self.rhs.eval()


class QasmRealSub(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() - self.rhs.eval()


class QasmRealMul(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() * self.rhs.eval()


class QasmRealDiv(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() / self.rhs.eval()
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
func = math.exp
        elif self.func == QasmRealUnaryFunctions.Ln:
            func = math.log
        elif self.func == QasmRealUnaryFunctions.Sqrt:
            func = math.sqrt
        else:
            raise ValueError('Unexpected Enum value.')
        return func(self.arg.eval())

    def __repr__(self):
        return f'{self.__class__.__name__}({repr(self.func)}, {repr(self.arg)})'


QasmRealConstValues = Enum('QasmRealConstValues', 'Pi')

class QasmRealConst(QasmRealExpr):
    def __init__(self, value: QasmRealConstValues):
        self.value = value

    def eval(self):
        if self.value == QasmRealConstValues.Pi:
            return math.pi
        raise ValueError('Unexpected Enum value.')



class QasmGateDecl(QasmNode):
    pass


class QasmApplyGate(QasmNode):
    def __init__(self, gate, params, qregs):
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
self.rhs = rhs

    def eval(self):
        return self.lhs.eval() * self.rhs.eval()


class QasmRealDiv(QasmRealExpr):
    def __init__(self, lhs: QasmExpr, rhs: QasmExpr):
        self.lhs = lhs
        self.rhs = rhs

    def eval(self):
        return self.lhs.eval() / self.rhs.eval()


class QasmRealValue(QasmRealExpr):
    def __init__(self, value: float):
        self.value = value

    def eval(self):
        return self.value


class QasmRealUnaryFunctions(Enum):
    Sin = auto()
    Cos = auto()
    Tan = auto()
    Exp = auto()
    Ln = auto()
    Sqrt = auto()

    @staticmethod
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
def from_str(s: str) -> 'QasmRealUnaryFunctions':
        if s == 'sin':
            return QasmRealUnaryFunctions.Sin
        if s == 'cos':
            return QasmRealUnaryFunctions.Cos
        if s == 'tan':
            return QasmRealUnaryFunctions.Tan
        if s == 'exp':
            return QasmRealUnaryFunctions.Exp
        if s == 'ln':
            return QasmRealUnaryFunctions.Ln
        if s == 'sqrt':
            return QasmRealUnaryFunctions.Sqrt
        raise ValueError('Unexpected value')

class QasmRealCall(QasmRealExpr):
    def __init__(self, func: QasmRealUnaryFunctions, arg: QasmRealExpr):
        self.func = func
        self.arg = arg

    def eval(self):
        func = None
        if self.func == QasmRealUnaryFunctions.Sin:
            func = math.sin
        elif self.func == QasmRealUnaryFunctions.Cos:
            func = math.cos
        elif self.func == QasmRealUnaryFunctions.Tan:
            func = math.tan
        elif self.func == QasmRealUnaryFunctions.Exp:
            func = math.exp
        elif self.func == QasmRealUnaryFunctions.Ln:
            func = math.log