Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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})'
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
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})'
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})'
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})'
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
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:
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
_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)}, ' + \