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

Improve error message for mismatching unit ids when adding conditional gates #1580

Open
CalMacCQ opened this issue Sep 16, 2024 · 0 comments
Labels
classical-logic issues related to classical logical expressions enhancement New feature or request

Comments

@CalMacCQ
Copy link
Contributor

CalMacCQ commented Sep 16, 2024

The following method works fine for adding a condtional-X gate to a Circuit.

from pytket import Circuit

circ = Circuit()
q = circ.add_q_register("q", 1) # default "q" register
a = circ.add_c_register("a", 1)

circ.X(q[0], condition_bits=[a[0]], condition_value=1)

Notice how I am passing the Qubit q[0] into the Circuit.add_gate method.

However if I replace q[0] with 0....

from pytket import Circuit

circ = Circuit()
q = circ.add_q_register("q", 1) # default "q" register
a = circ.add_c_register("a", 1)

circ.X(0, condition_bits=[a[0]], condition_value=1)

I get the following RuntimeError

--
RuntimeError                              Traceback (most recent call last)
Cell In[16], line 1
----> 1 circ.X(0, condition_bits=[a[0]], condition_value=1)

RuntimeError: Unable to cast Python instance of type <class 'list'> to C++ type 'std::__1::vector<unsigned int, std::__1::allocator<unsigned int>>'

Its not at all obvoius from this error what has gone wrong here. This error message should make the fix clearer.

In fact, arguably this shouldn't give an error in pytket as in the current interface we support referencing qubits with Qubits and integers. However not sure how practical overload merging would be.

@CalMacCQ CalMacCQ added enhancement New feature or request classical-logic issues related to classical logical expressions labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
classical-logic issues related to classical logical expressions enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant