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

basic_example.json fails during routine verification #104

Closed
bdg221 opened this issue Aug 7, 2024 · 3 comments · Fixed by #105
Closed

basic_example.json fails during routine verification #104

bdg221 opened this issue Aug 7, 2024 · 3 comments · Fixed by #105
Labels
bug Something isn't working

Comments

@bdg221
Copy link
Contributor

bdg221 commented Aug 7, 2024

Describe the bug

After reading in basic_example.json, trying to run compile_routine results in the following error:

Traceback (most recent call last):
  File "/Users/xxx/Documents/PsiQuantum/brian/bartiq/src/bartiq/test2.py", line 10, in <module>
    compiled_routine = compile_routine(uncompiled_routine)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/PsiQuantum/brian/bartiq/src/bartiq/compilation/_compile.py", line 86, in compile_routine
    return _compile_routine(routine, backend, precompilation_stages, global_functions, functions_map, skip_verification)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/PsiQuantum/brian/bartiq/src/bartiq/compilation/_compile.py", line 102, in _compile_routine
    raise BartiqCompilationError(
bartiq.errors.BartiqCompilationError: Found the following issues with the provided routine before the compilation started: ['N is present in linked_params, but not in input_params.\n']

This is the result of changes made in #76 which introduced routine verification.

How to Reproduce

The following code will reproduce the error:

import json
from bartiq import Routine, compile_routine, evaluate
from bartiq.integrations import qref_to_bartiq

with open("docs/data/basic_example.json", "r") as f:
    routine_dict = json.load(f)

uncompiled_routine = qref_to_bartiq(routine_dict)
compiled_routine = compile_routine(uncompiled_routine)

Expected behavior

It is expected that the provided JSON file can be read and used to generated a compiled routine.

Actual behavior

An error is thrown:

bartiq.errors.BartiqCompilationError: Found the following issues with the provided routine before the compilation started: ['N is present in linked_params, but not in input_params.\n']

Environment:**

  • OS: OSX,
  • Bartiq 0.5.0
  • Python 3.11.9
@bdg221 bdg221 added the bug Something isn't working label Aug 7, 2024
@bdg221
Copy link
Contributor Author

bdg221 commented Aug 7, 2024

Adding N in input_params for my_algorithm does correct this error. However, it then results in the following warning:

/Users/xxx/Documents/PsiQuantum/brian/bartiq/src/bartiq/compilation/_compile.py:117: UserWarning: Found the following issues with the provided routine after the compilation has finished: ["Symbol N_b found in subroutine: my_algorithm.b, which is not among top level params: {'N'}."]
  warnings.warn(

This is also seen in the tutorials/01_basic_example (https://psiq.github.io/bartiq/latest/tutorials/01_basic_example/):
image

This is a bit odd as both the test with the code snippet above, as well as the tutorial, have my_algorithm.a with N_a (or n_a) and there are not warnings for that.

If this should be addressed in a separate issue, please let me know.

@bdg221
Copy link
Contributor Author

bdg221 commented Aug 7, 2024

After more research, it appears that the warning is a result of a bug. Before the compilation (after precompile), the resources have the following values:
a -> {'T_gates': <Resource name="T_gates" value="2*N_a">}
b -> {'T_gates': <Resource name="T_gates" value="N_b*ceil(log_2(N_b))">}

After compilation, the resources have the following values:
a -> {'T_gates': <Resource name="T_gates" value="2*N">}
b -> {'T_gates': <Resource name="T_gates" value="N_b*ceiling(log2(N_b))">}

During the compilation N_b is not replaced with N. This explains why the warning is only for N_b.

@mstechly, it looks like you saw a similar warning before and mentioned it in #72 I am happy to continue tracking this down. Do you think I should do that work with #72 or open a new issue?

I will leave this issue for correcting basic_example.json to include input_params.

@mstechly
Copy link
Contributor

mstechly commented Aug 7, 2024

Hey @bdg221, thanks a lot for finding this!
Please put it on hold for now, as we're making some refactors which might solve it and I don't want you to waste time on this if that's the case.

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

Successfully merging a pull request may close this issue.

2 participants