From 2397bf7ff5f051345a709dad0a6072c8668b9ef9 Mon Sep 17 00:00:00 2001 From: HaYeong Lee <110161434+glorialeezero@users.noreply.github.com> Date: Fri, 22 Nov 2024 04:00:27 +0000 Subject: [PATCH] Update Gatemap creation --- qupsy/bin.py | 6 ++++++ qupsy/language.py | 7 +++++++ qupsy/spec.py | 10 +--------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/qupsy/bin.py b/qupsy/bin.py index aa84ad4..a40bd95 100644 --- a/qupsy/bin.py +++ b/qupsy/bin.py @@ -1,5 +1,6 @@ import argparse from pathlib import Path +from typing import cast from qupsy.spec import parse_spec from qupsy.utils import logger @@ -8,12 +9,17 @@ def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("-d", "--dry-run", action="store_true", help="Dry run") + parser.add_argument("-l", "--loglevel", default="WARNING", help="Log level") parser.add_argument( "specification", type=Path, metavar="SPEC", help="Specification file" ) args = parser.parse_args() + loglevel = cast(str, args.loglevel).upper() + logger.setLevel(loglevel) + logger.debug("CLI arguments: %s", args) + logger.debug("Specification file: %s", args.specification) spec = parse_spec(args.specification) diff --git a/qupsy/language.py b/qupsy/language.py index 65ac0c4..7b92c57 100644 --- a/qupsy/language.py +++ b/qupsy/language.py @@ -427,3 +427,10 @@ def cost(self) -> int: @property def depth(self) -> int: return self.body.depth + + +GATE_MAP: dict[str, type[Gate]] = { + g.__name__: g + for g in globals().values() + if isinstance(g, type) and issubclass(g, Gate) +} diff --git a/qupsy/spec.py b/qupsy/spec.py index f54533c..6a0f779 100644 --- a/qupsy/spec.py +++ b/qupsy/spec.py @@ -6,17 +6,9 @@ import numpy as np import numpy.typing as npt -from qupsy.language import CX, CRy, Gate, H, Ry, X +from qupsy.language import GATE_MAP, Gate from qupsy.utils import logger -GATE_MAP: dict[str, type[Gate]] = { - "H": H, - "X": X, - "Ry": Ry, - "CX": CX, - "CRy": CRy, -} - @dataclass class Spec: