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

Modifications to callable_from_qua #178

Merged
merged 20 commits into from
Feb 1, 2024

Conversation

nulinspiratie
Copy link
Contributor

@nulinspiratie nulinspiratie commented Dec 8, 2023

This is a PR attempting to implement the changes required for callable_from_qua.
@TheoLaudatQM I'm not able to run this locally, so there are likely to be several bugs. can you try this out nonetheless?

Following our earlier conversation with @TheoLaudatQM @yonatanrqm @yomach I'll try to implement the changes related to inheriting from Program and QuantumMachine.

The goal is that we no longer need to run the following:

with prog.local_run(qm):
    job = qm.execute(prog)

but can instead directly run

job = qm.execute(prog)

Usage:

from qualang_tools.callable_from_qua import *
patch_callable_from_qua()  # Patch qua classes
enable_callable_from_qua()  # Attach callable_from_qua addon

@callable_from_qua
def execute_function():
    print("I'm being run locally")

with program() as prog:
   execute_function()

qmm = QuantumMachinesManager(...)
config = ...
qm = qmm.open_qm(config)
qm.execute(program).

I think the following items should be done

  • Inherit from QuantumMachine, add QuantumMachine.callables which get executed when calling qm.execute()
  • Patch Program, add program.addons
  • Rename @local_run back to @callable_from_qua
  • Rename LocalRunManager to QuaCallableEventManager
  • Move callable_from_qua away from qualang_tools/addons to qualang_tools/callable_from_qua. @yomach do you agree

Open questions

  • Should the CallableEventManager be opened in the main thread or in a separate thread while the program is executing on the machine?
    I think the best is if it by default opens in a separate thread, but the user can specify to run it in the main thread, in which case it's blocking.
  • How to pass additional callables?
    E.g. we can currently run with prog.local_run(qm, funcs=[live_plot]): to also add live plotting

Copy link

github-actions bot commented Dec 8, 2023

Unit Test Results

0 tests   - 337   0 ✔️  - 336   0s ⏱️ -18s
0 suites  -     1   0 💤  -     1 
0 files    -     1   0 ±    0 

Results for commit 29d53bd. ± Comparison against base commit be6cf48.

♻️ This comment has been updated with latest results.

@yomach
Copy link
Collaborator

yomach commented Dec 10, 2023

I agree with what you wrote (haven't looked at the code yet).
@TheoLaudatQM - Note that this is a PR to merge to your branch, not to main.
So we please test it locally and if it's good, we'll merge it there and continue development from there.

@yomach yomach requested a review from yonatanrqm December 10, 2023 19:39
Copy link
Contributor

@TheoLaudatQM TheoLaudatQM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test programs don't run because a running job is needed before it is actually created

compiler_options: Optional[CompilerOptionArguments] = None,
) -> RunningQmJob:
for program_addon in program.addons.values():
program_addon.execute_program(program=program, quantum_machine=self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In execute_program(), you're trying to get the running job job = quantum_machine.get_running_job() which doesn't already exist since it will be created in the next line. This prevents the program from running and I am not sure how to fix it myself...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, maybe the solution is then to run the addons after starting the main program.

In this case we need to make sure that if QUA performs a callable_from_qua before the addon programs are started, it won't cause issues. We can do this by e.g. adding a few seconds delay between executing the program and starting the addons. @TheoLaudatQM could you try this out?

@TheoLaudatQM TheoLaudatQM merged commit cc2ef67 into callable_from_qua Feb 1, 2024
1 of 2 checks passed
@TheoLaudatQM TheoLaudatQM deleted the callable_from_qua_serwan branch February 1, 2024 11:07
TheoLaudatQM added a commit that referenced this pull request Mar 18, 2024
* move callable_from_qua away from addons

* rename folders

* Rename run_local -> callable_from_qua

* add patches to qua classes

* add to import

* Added patches

* patches and transformed to ProgramAddon

* add creation of QuaCallableEventManager

* rename everything to qua_callable

* Add callables attr

* add enable_callable_from_qua

* fix: classmethods

* fixed bugs related to class

* update tests

* Switch order in execute and addons execution

* fix bug

* qua_patches decoupled

* work in progress

* remove "enable_callable"

* get program from scope

---------

Co-authored-by: TheoQM <[email protected]>
TheoLaudatQM added a commit that referenced this pull request Mar 20, 2024
* working version

* Callable from QUA tests

* Working version for serwan

* More examples

* after code session with Serwan

* clean + readme + examples

* Update examples

* Modifications to callable_from_qua (#178)

* move callable_from_qua away from addons

* rename folders

* Rename run_local -> callable_from_qua

* add patches to qua classes

* add to import

* Added patches

* patches and transformed to ProgramAddon

* add creation of QuaCallableEventManager

* rename everything to qua_callable

* Add callables attr

* add enable_callable_from_qua

* fix: classmethods

* fixed bugs related to class

* update tests

* Switch order in execute and addons execution

* fix bug

* qua_patches decoupled

* work in progress

* remove "enable_callable"

* get program from scope

---------

Co-authored-by: TheoQM <[email protected]>

* _get_root_program_scope() + black

* fix black formatting

* second attempt black formatting

* Rewrite patch_qua_program_addons, improve qm.execute patch

* Conf_test, basic test

* Example files

* Example readme

* default config

* readme and changelog

* black

* remove example

* Add example with small c

---------

Co-authored-by: Serwan Asaad <[email protected]>
Co-authored-by: Serwan Asaad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants