From aed9fe13bdc0d6d147b4ff0cfa7f7fa52cb37947 Mon Sep 17 00:00:00 2001 From: HaYeong Lee <110161434+glorialeezero@users.noreply.github.com> Date: Mon, 25 Nov 2024 04:46:39 +0000 Subject: [PATCH 1/4] Fix aexp next function --- qupsy/transition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qupsy/transition.py b/qupsy/transition.py index 52024de..e469f21 100644 --- a/qupsy/transition.py +++ b/qupsy/transition.py @@ -50,7 +50,7 @@ def visit_Aexp(self, aexp: Aexp) -> list[Aexp]: *(a.copy() for a in post_args), ) ) - + return ret return [] def visit_HoleGate(self, gate: HoleGate) -> list[Gate]: From 087236747b16b8e5348751bb038f7e1b64a6b3ea Mon Sep 17 00:00:00 2001 From: HaYeong Lee <110161434+glorialeezero@users.noreply.github.com> Date: Mon, 25 Nov 2024 04:47:07 +0000 Subject: [PATCH 2/4] Rename filled -> terminated --- qupsy/language.py | 18 +++++++++--------- qupsy/transition.py | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/qupsy/language.py b/qupsy/language.py index bbebd49..149da6a 100644 --- a/qupsy/language.py +++ b/qupsy/language.py @@ -34,9 +34,9 @@ def depth(self) -> int: ) @property - def filled(self) -> bool: + def terminated(self) -> bool: for aexp in self.children: - if not aexp.filled: + if not aexp.terminated: return False return True @@ -104,7 +104,7 @@ def children(self) -> list[Aexp]: return [] @property - def filled(self) -> bool: + def terminated(self) -> bool: return False @@ -227,9 +227,9 @@ def depth(self) -> int: ) @property - def filled(self) -> bool: + def terminated(self) -> bool: for aexp in self.children: - if not aexp.filled: + if not aexp.terminated: return False return True @@ -253,7 +253,7 @@ def children(self) -> list[Aexp]: return [] @property - def filled(self) -> bool: + def terminated(self) -> bool: return False @@ -410,9 +410,9 @@ def depth(self) -> int: ) @property - def filled(self) -> bool: + def terminated(self) -> bool: for child in self.children: - if not child.filled: + if not child.terminated: return False return True @@ -436,7 +436,7 @@ def children(self) -> list[Cmd | Gate | Aexp]: return [] @property - def filled(self) -> bool: + def terminated(self) -> bool: return False diff --git a/qupsy/transition.py b/qupsy/transition.py index e469f21..35e3759 100644 --- a/qupsy/transition.py +++ b/qupsy/transition.py @@ -36,7 +36,7 @@ def visit_Aexp(self, aexp: Aexp) -> list[Aexp]: return visitor(aexp) for i, child in enumerate(aexp.children): - if child.filled: + if child.terminated: continue next_children = self.visit_Aexp(child) pre_args = aexp.children[:i] @@ -63,7 +63,7 @@ def visit_Gate(self, gate: Gate) -> list[Gate]: return visitor(gate) for i, child in enumerate(gate.children): - if child.filled: + if child.terminated: continue next_children = self.visit_Aexp(child) pre_args = gate.children[:i] @@ -84,13 +84,13 @@ def visit_HoleCmd(self, cmd: HoleCmd) -> list[Cmd]: return [SeqCmd(), ForCmd(var=f"i{self.for_depth}"), GateCmd()] def visit_SeqCmd(self, cmd: SeqCmd) -> list[Cmd]: - if not cmd.pre.filled: + if not cmd.pre.terminated: pres = self.visit_Cmd(cmd.pre) ret: list[Cmd] = [] for pre in pres: ret.append(SeqCmd(pre=pre, post=cmd.post.copy())) return ret - if not cmd.post.filled: + if not cmd.post.terminated: posts = self.visit_Cmd(cmd.post) ret: list[Cmd] = [] for post in posts: @@ -99,7 +99,7 @@ def visit_SeqCmd(self, cmd: SeqCmd) -> list[Cmd]: return [] def visit_ForCmd(self, cmd: ForCmd) -> list[Cmd]: - if not cmd.start.filled: + if not cmd.start.terminated: starts = self.visit_Aexp(cmd.start) ret: list[Cmd] = [] for start in starts: @@ -112,7 +112,7 @@ def visit_ForCmd(self, cmd: ForCmd) -> list[Cmd]: ) ) return ret - if not cmd.end.filled: + if not cmd.end.terminated: ends = self.visit_Aexp(cmd.end) ret: list[Cmd] = [] for end in ends: @@ -125,7 +125,7 @@ def visit_ForCmd(self, cmd: ForCmd) -> list[Cmd]: ) ) return ret - if not cmd.body.filled: + if not cmd.body.terminated: self.for_depth += 1 bodies = self.visit_Cmd(cmd.body) self.for_depth -= 1 From daeec327ba992b76b61cf9774615adbbada1c5eb Mon Sep 17 00:00:00 2001 From: HaYeong Lee <110161434+glorialeezero@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:55:00 +0900 Subject: [PATCH 3/4] Add testcase for #10 --- tests/test_transition.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_transition.py b/tests/test_transition.py index 21010ec..4d34822 100644 --- a/tests/test_transition.py +++ b/tests/test_transition.py @@ -2,6 +2,7 @@ ALL_AEXPS, ALL_GATES, CX, + Add, Aexp, Cmd, ForCmd, @@ -78,3 +79,17 @@ def test_hole_aexp3(): if type(pgm.body.gate.qreg2) not in [Integer, Var]: aexp_types.remove(type(pgm.body.gate.qreg2)) assert len(aexp_types) == 3 + + +def test_next_aexp(): + pgm = Pgm("n", GateCmd(CX(Integer(0), Add()))) + aexp_types: list[type[Aexp]] = ALL_AEXPS.copy() + pgms = next(pgm) + for pgm in pgms: + assert isinstance(pgm.body, GateCmd) + assert isinstance(pgm.body.gate, CX) + assert isinstance(pgm.body.gate.qreg2, Add) + assert type(pgm.body.gate.qreg2.a) in aexp_types + if type(pgm.body.gate.qreg2.a) not in [Integer, Var]: + aexp_types.remove(type(pgm.body.gate.qreg2.a)) + assert len(aexp_types) == 3 From dc1c8138ceabf8515f13dd7d854d27e1ae1f2901 Mon Sep 17 00:00:00 2001 From: HaYeong Lee <110161434+glorialeezero@users.noreply.github.com> Date: Mon, 25 Nov 2024 04:56:59 +0000 Subject: [PATCH 4/4] Modify testcase --- tests/test_transition.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_transition.py b/tests/test_transition.py index 4d34822..fc2a4eb 100644 --- a/tests/test_transition.py +++ b/tests/test_transition.py @@ -9,6 +9,7 @@ Gate, GateCmd, H, + HoleAexp, Integer, Pgm, SeqCmd, @@ -92,4 +93,5 @@ def test_next_aexp(): assert type(pgm.body.gate.qreg2.a) in aexp_types if type(pgm.body.gate.qreg2.a) not in [Integer, Var]: aexp_types.remove(type(pgm.body.gate.qreg2.a)) + assert isinstance(pgm.body.gate.qreg2.b, HoleAexp) assert len(aexp_types) == 3