How to use the blueqat.qasmparser.QasmNode 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.params = params
        self.qregs = qregs

    def __repr__(self):
        return f'QasmApplyGate({self.gate}, {self.params}, {self.qregs})'


class QasmBarrier(QasmNode):
    def __init__(self, qregs):
        self.qregs = qregs

    def __repr__(self):
        return f'QasmBarrier({self.qregs})'


class QasmIf(QasmNode):
    def __init__(self, creg: str, num: int, node: QasmNode):
        self.creg = creg
        self.num = num
        self.node = node

    def __repr__(self):
        return f'QasmIf({self.creg}, {self.num}, {self.node})'


class QasmReset(QasmNode):
    def __init__(self, qregs):
        self.qregs = qregs

    def __repr__(self):
        return f'QasmReset({self.qregs})'
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
self.num = num
        self.node = node

    def __repr__(self):
        return f'QasmIf({self.creg}, {self.num}, {self.node})'


class QasmReset(QasmNode):
    def __init__(self, qregs):
        self.qregs = qregs

    def __repr__(self):
        return f'QasmReset({self.qregs})'


class QasmMeasure(QasmNode):
    def __init__(self, qregs, cregs):
        self.qregs = qregs
        self.cregs = cregs

    def __repr__(self):
        return f'QasmMeasure({self.qregs}, {self.cregs})'


class QasmGateApply(QasmNode):
    def __init__(self,
                 gate: 'QasmAbstractGate',
                 params: List[QasmRealExpr],
                 qregs: List[Tuple[str, int]]) -> None:
        self.gate = gate
        self.params = params
        self.qregs = qregs
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
class QasmGateDecl(QasmNode):
    pass


class QasmApplyGate(QasmNode):
    def __init__(self, gate, params, qregs):
        self.gate = gate
        self.params = params
        self.qregs = qregs

    def __repr__(self):
        return f'QasmApplyGate({self.gate}, {self.params}, {self.qregs})'


class QasmBarrier(QasmNode):
    def __init__(self, qregs):
        self.qregs = qregs

    def __repr__(self):
        return f'QasmBarrier({self.qregs})'


class QasmIf(QasmNode):
    def __init__(self, creg: str, num: int, node: QasmNode):
        self.creg = creg
        self.num = num
        self.node = node

    def __repr__(self):
        return f'QasmIf({self.creg}, {self.num}, {self.node})'
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
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):
        self.gate = gate
        self.params = params
        self.qregs = qregs

    def __repr__(self):
        return f'QasmApplyGate({self.gate}, {self.params}, {self.qregs})'


class QasmBarrier(QasmNode):
    def __init__(self, qregs):
        self.qregs = qregs

    def __repr__(self):
        return f'QasmBarrier({self.qregs})'
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
def __repr__(self):
        return f'QasmBarrier({self.qregs})'


class QasmIf(QasmNode):
    def __init__(self, creg: str, num: int, node: QasmNode):
        self.creg = creg
        self.num = num
        self.node = node

    def __repr__(self):
        return f'QasmIf({self.creg}, {self.num}, {self.node})'


class QasmReset(QasmNode):
    def __init__(self, qregs):
        self.qregs = qregs

    def __repr__(self):
        return f'QasmReset({self.qregs})'


class QasmMeasure(QasmNode):
    def __init__(self, qregs, cregs):
        self.qregs = qregs
        self.cregs = cregs

    def __repr__(self):
        return f'QasmMeasure({self.qregs}, {self.cregs})'
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
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):
        self.gate = gate
        self.params = params
        self.qregs = qregs

    def __repr__(self):
        return f'QasmApplyGate({self.gate}, {self.params}, {self.qregs})'


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

    def __repr__(self):
        return f'QasmReset({self.qregs})'


class QasmMeasure(QasmNode):
    def __init__(self, qregs, cregs):
        self.qregs = qregs
        self.cregs = cregs

    def __repr__(self):
        return f'QasmMeasure({self.qregs}, {self.cregs})'


class QasmGateApply(QasmNode):
    def __init__(self,
                 gate: 'QasmAbstractGate',
                 params: List[QasmRealExpr],
                 qregs: List[Tuple[str, int]]) -> None:
        self.gate = gate
        self.params = params
        self.qregs = qregs

    def __repr__(self) -> str:
        return f'QasmGateApply({repr(self.gate)}, {self.params}, {self.qregs})'


QasmGateType = Enum('QasmGateType', 'Gate Opaque Builtin')


class QasmAbstractGate:
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
gates: Dict[str, Any],
                 included: Set[str]) -> None:
        self.statements = statements
        self.qregs = qregs
        self.cregs = cregs
        self.gates = gates
        self.included = included


    def __repr__(self) -> str:
        return f'QasmProgram({repr(self.statements)}, ' + \
               f'{repr(self.qregs)}, {repr(self.cregs)}, ' + \
               f'{repr(self.gates)}, {repr(self.included)})'


class QasmExpr(QasmNode):
    @abstractmethod
    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
github Blueqat / Blueqat / blueqat / qasmparser.py View on Github external
_parse_statements(tokens, stmts, gates, qregs, cregs, included)
    return QasmProgram(stmts, gates, qregs, cregs, included)


def parse_qasmf(qasmfile: Union[str, TextIO], *args, **kwargs) -> 'QasmProgram':
    if isinstance(qasmfile, str):
        with open(qasmfile) as f:
            return parse_qasmf(f, *args, **kwargs)
    return parse_qasm(qasmfile.read(), *args, **kwargs)


class QasmNode:
    pass


class QasmProgram(QasmNode):
    def __init__(self,
                 statements: List[Any],
                 qregs: Dict[str, int],
                 cregs: Dict[str, int],
                 gates: Dict[str, Any],
                 included: Set[str]) -> None:
        self.statements = statements
        self.qregs = qregs
        self.cregs = cregs
        self.gates = gates
        self.included = included


    def __repr__(self) -> str:
        return f'QasmProgram({repr(self.statements)}, ' + \
               f'{repr(self.qregs)}, {repr(self.cregs)}, ' + \