Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional check for >32 bit size registers used in wasm #1090

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading