Skip to content

Commit

Permalink
refactor: raise TypeError on passing less than min_args
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik committed Sep 11, 2024
1 parent a64cec7 commit d511345
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pytket/phir/phirgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,13 @@ def convert_classicalevalop(op: tk.ClassicalEvalOp, cmd: tk.Command) -> JsonDict

def multi_bit_condition(args: "list[UnitID]", value: int) -> JsonDict:
"""Construct bitwise condition."""
val_bits = deque(map(int, f"{value:0{len(args)}b}"))
min_args = 2
if len(args) < min_args:
msg = "multi_bit_condition requires at least two arguments"
raise TypeError(msg)

def nested_cop(cop: str, args: "deque[UnitID]", val_bits: deque[int]) -> JsonDict:
if len(args) == 2: # noqa: PLR2004
if len(args) == min_args:
return {
"cop": cop,
"args": [
Expand All @@ -376,7 +379,7 @@ def nested_cop(cop: str, args: "deque[UnitID]", val_bits: deque[int]) -> JsonDic
],
}

return nested_cop("&", deque(args), val_bits)
return nested_cop("&", deque(args), deque(map(int, f"{value:0{len(args)}b}")))


def convert_subcmd(op: tk.Op, cmd: tk.Command) -> JsonDict | None: # noqa: PLR0912
Expand Down

0 comments on commit d511345

Please sign in to comment.