Skip to content

Commit

Permalink
mypy fix (#82)
Browse files Browse the repository at this point in the history
* fix error message

* fix mypy

* format

* add int as type to func
  • Loading branch information
cqc-melf authored Oct 17, 2023
1 parent 55cf60d commit f1f3206
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
14 changes: 5 additions & 9 deletions pytket/qir/conversion/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,13 @@ def _get_c_regs_from_com(self, command: Command) -> tuple[list[str], list[str]]:
com_bits = args[:in_width]
args = args[in_width:]
regname = com_bits[0].reg_name
if com_bits != list(self.cregs[regname]): # type: ignore
if com_bits != list(self.cregs[regname]):
raise ValueError("WASM ops must act on entire registers.")
reglist.append(regname)
return inputs, outputs

def _get_ssa_from_cl_reg_op(
self, reg: Union[BitRegister, RegAnd, RegOr, RegXor], module: tketqirModule
self, reg: Union[BitRegister, RegAnd, RegOr, RegXor, int], module: tketqirModule
) -> Value:
if type(reg) in _TK_CLOPS_TO_PYQIR_REG:
assert len(reg.args) == 2 # type: ignore
Expand Down Expand Up @@ -900,15 +900,11 @@ def condition_block() -> None:
# classical ops acting on bits returning bit
ssa_left = cast( # type: ignore
Value,
self._get_ssa_from_cl_bit_op(
op.get_exp().args[0], module # type: ignore
),
self._get_ssa_from_cl_bit_op(op.get_exp().args[0], module),
)
ssa_right = cast( # type: ignore
Value,
self._get_ssa_from_cl_bit_op(
op.get_exp().args[1], module # type: ignore
),
self._get_ssa_from_cl_bit_op(op.get_exp().args[1], module),
)

# add function to module
Expand Down Expand Up @@ -940,7 +936,7 @@ def condition_block() -> None:
](module.builder)(ssa_left, ssa_right)

else:
raise ValueError(" unexpected classical op")
raise ValueError(f"unexpected classical op {type(op.get_exp())}")

if returntypebool:
# the return value of the some classical ops is bool in qir,
Expand Down
10 changes: 5 additions & 5 deletions tests/conversion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_pytket_qir_8() -> None:
c.add_c_setbits([True], [a[2]])
c.add_c_setbits([True], [a[1]])
c.add_c_setbits([True], [a[7]])
c.add_c_setbits([False, True] + [False] * 6, list(a)) # type: ignore
c.add_c_setbits([False, True] + [False] * 6, list(a))

result = pytket_to_qir(c, name="test_pytket_qir_8", qir_format=QIRFormat.STRING)

Expand Down Expand Up @@ -237,8 +237,8 @@ def test_pytket_qir_14() -> None:
d = c.add_c_register("d", 10)

c.add_c_setbits([True], [a[0]])
c.add_c_setbits([False, True] + [False] * 6, list(a)) # type: ignore
c.add_c_setbits([True, True] + [False] * 8, list(b)) # type: ignore
c.add_c_setbits([False, True] + [False] * 6, list(a))
c.add_c_setbits([True, True] + [False] * 8, list(b))

c.add_c_setreg(23, a)
c.add_c_copyreg(a, b)
Expand Down Expand Up @@ -276,8 +276,8 @@ def test_pytket_qir_14_b() -> None:
d = c.add_c_register("d", 32)

c.add_c_setbits([True], [a[0]])
c.add_c_setbits([False, True] + [False] * 30, list(a)) # type: ignore
c.add_c_setbits([True, True] + [False] * 30, list(b)) # type: ignore
c.add_c_setbits([False, True] + [False] * 30, list(a))
c.add_c_setbits([True, True] + [False] * 30, list(b))

c.add_c_setreg(23, a)
c.add_c_copyreg(a, b)
Expand Down

0 comments on commit f1f3206

Please sign in to comment.