Skip to content

Commit

Permalink
Merge branch 'develop' into feature/Add-OpTypes-for-CS-and-CSdg
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-cqc authored Oct 24, 2023
2 parents f283563 + 75caa93 commit 998caca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pytket/pytket/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ def overload_add_wasm_to_reg(
if args_wasm is None:
args_wasm = [0]

if filehandler._check_file:
for reg in list_i:
if reg.size > 32:
raise ValueError(
"""wasm is only supporting 32 bit size registers,
please use only registers of at most 32 bits"""
)

for reg in list_o:
if reg.size > 32:
raise ValueError(
"""wasm is only supporting 32 bit size registers,
please use only registers of at most 32 bits"""
)

if filehandler.check_function(funcname, len(list_i), len(list_o)):
if (len(args_wasm)) > 0:
self._add_w_register(max(args_wasm) + 1)
Expand Down
43 changes: 42 additions & 1 deletion pytket/tests/classical_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,51 @@ def test_wasm_function_check_5() -> None:
c = Circuit(20, 20)
c0 = c.add_c_register("c0", 53)
c1 = c.add_c_register("c1", 4)

with pytest.raises(ValueError):
c.add_wasm_to_reg("add_one", w, [c0], [c1])


def test_wasm_function_check_6() -> None:
w = wasm.WasmFileHandler("testfile.wasm")
c = Circuit(20, 20)
c0 = c.add_c_register("c0", 32)
c1 = c.add_c_register("c1", 4)

c.add_wasm_to_reg("add_one", w, [c0], [c1])
assert c.depth() == 1


def test_wasm_function_check_7() -> None:
w = wasm.WasmFileHandler("testfile.wasm", int_size=32)
c = Circuit(20, 20)
c0 = c.add_c_register("c0", 32)
c1 = c.add_c_register("c1", 4)

c.add_wasm_to_reg("add_one", w, [c0], [c1])
assert c.depth() == 1


def test_wasm_function_check_8() -> None:
w = wasm.WasmFileHandler("testfile.wasm", int_size=64)
c = Circuit(20, 20)
c0 = c.add_c_register("c0", 32)
c1 = c.add_c_register("c1", 4)
c2 = c.add_c_register("c2", 5)

c.add_wasm_to_reg("add_something", w, [c0], [c1])
assert c.depth() == 1


def test_wasm_function_check_9() -> None:
w = wasm.WasmFileHandler("testfile.wasm", int_size=64)
c = Circuit(20, 20)
c0 = c.add_c_register("c0", 53)
c1 = c.add_c_register("c1", 4)
c2 = c.add_c_register("c2", 5)

with pytest.raises(ValueError):
c.add_wasm_to_reg("add_one", w, [c0], [c1, c2])
c.add_wasm_to_reg("add_something", w, [c0], [c1])


def test_add_wasm_to_reg() -> None:
Expand Down

0 comments on commit 998caca

Please sign in to comment.