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

Incorrect bitwidth for QASM input with pytket 1.30.0 #203

Closed
qartik opened this issue Jul 15, 2024 · 3 comments · Fixed by #204
Closed

Incorrect bitwidth for QASM input with pytket 1.30.0 #203

qartik opened this issue Jul 15, 2024 · 3 comments · Fixed by #204
Labels
bug Something isn't working

Comments

@qartik
Copy link
Member

qartik commented Jul 15, 2024

Describe the bug
With upgrade to pytket==0.13.1, all tests involving range predicate fail (see here):

FAILED tests/test_api.py::TestApi::test_pytket_to_phir_no_machine_all[QasmFile.cond_1] - UnboundLocalError: cannot access local variable 'cond' where it is not associated with a value
FAILED tests/test_api.py::TestApi::test_pytket_to_phir_no_machine_all[QasmFile.cond_classical] - UnboundLocalError: cannot access local variable 'cond' where it is not associated with a value
FAILED tests/test_api.py::TestApi::test_pytket_to_phir_h1_1_all[QasmFile.cond_1] - UnboundLocalError: cannot access local variable 'cond' where it is not associated with a value
FAILED tests/test_api.py::TestApi::test_pytket_to_phir_h1_1_all[QasmFile.cond_classical] - UnboundLocalError: cannot access local variable 'cond' where it is not associated with a value

I believe this is because the change in #190 makes the value of UINTMAX depend on 64-bits but the pytket translation of QASM circuits is still using 32-bits for the range predicate translation. See

op = RangePredicate([2,4294967295]), cmd = RangePredicate([2,4294967295]) c[0], c[1], tk_SCRATCH_BIT[1];

    def convert_classicalevalop(op: tk.ClassicalEvalOp, cmd: tk.Command) -> JsonDict | None:  # noqa: PLR0912
[...]
            case tk.RangePredicateOp():  # where the condition is a range
                cond: JsonDict
                match op.lower, op.upper:
                    case l, u if l == u:
                        cond = {
                            "cop": "==",
                            "args": [args[0].reg_name, u],
                        }
                    case l, u if u == UINTMAX:
                        cond = {
                            "cop": ">=",
                            "args": [args[0].reg_name, l],
                        }
                    case 0, u:
                        cond = {
                            "cop": "<=",
                            "args": [args[0].reg_name, u],
                        }
                    case l, u:
>                       raise TypeError(f"{l=} {u=} {UINTMAX=}")
E                       TypeError: l=2 u=4294967295 UINTMAX=18446744073709551615

To Reproduce
Upgrade to pytket==0.13.1

Expected behavior
Tests should pass.

Additional context
Changes in #190

@qartik qartik added the bug Something isn't working label Jul 15, 2024
@qartik
Copy link
Member Author

qartik commented Jul 15, 2024

@cqc-alec do you think this is a bug in pytket or do we need to treat QASM inputs specially assuming max 32 bits?

cc: @dlucchetti

@cqc-alec
Copy link
Collaborator

@cqc-alec do you think this is a bug in pytket or do we need to treat QASM inputs specially assuming max 32 bits?

There is a maxwidth parameter to circuit_from_qasm, which defaults to 32. Would changing this to 64 in the get_qasm_as_circuit() method (or to 64 if pytket.__dict__.get("bit_width_64", False) else 32 as used in the definition of UINTMAX) fix the issue?

@cqc-alec
Copy link
Collaborator

Just tested locally and it looks like this does fix the errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants