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

Issue 69 | Nested programs interface #85

Merged
merged 6 commits into from
Dec 15, 2022

Conversation

IceKhan13
Copy link
Member

@IceKhan13 IceKhan13 commented Dec 15, 2022

Summary

Nested programs interface

Now we provide a way to execute async nested programs in a following manner

from quantum_serverless import QuantumServerless, Program

serverless = QuantumServerless(...)

my_program = Program(
    name="my_program",
    entrypoint=script.py,
    dependencies=["requests", "pyscf==2.0.3"],
    version="0.0.1"
)

serverless.set_provider("provider")
job = serverless.run_program(my_program) # this will run program on provider
job.status() # to get status
job.logs() # to get logs

serverless.set_provider("another_provider")
another_job = serverless.run_program(my_program) # this will run program on another_provider

where script.py has our program code of interest for example

# script.py
from quantum_serverless import QuantumServerless, run_qiskit_remote, get

@run_qiskit_remote()
def ultimate():
    return 42


with QuantumServerless():
    result = get([ultimate() for _ in range(10)])

print(result)

Moreover we provide interface for program storage backend that can be implemented for example for local storage

from quantum_serverless.core.program import ProgramStorageBackend


class LocalStorageBackend(ProgramStorageBackend):
     ...

program_storage = LocalStorageBackend()

# to save program
program_storage.save_program(my_program)

# to load program
recovered_program = program_storage.get_program("my_program")

Details and comments

Co-authored with @Tansito

Closes #69

@IceKhan13 IceKhan13 added the enhancement New feature or request label Dec 15, 2022
@IceKhan13 IceKhan13 added this to the 0.1.0 milestone Dec 15, 2022
@IceKhan13 IceKhan13 marked this pull request as ready for review December 15, 2022 16:58
@IceKhan13 IceKhan13 requested review from pacomf and Tansito December 15, 2022 21:34
Copy link
Member

@pacomf pacomf left a comment

Choose a reason for hiding this comment

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

LGTM like first approach!

Some questions:

  1. How to concatenate different programs in a workflow? Any use example?
  2. How to invoke programs from cloud? I mean, the private/hide version of a program to allow users run a program without get the source code of it. Any thoughts or idea to implement it?
  3. In the example, Job can be named like program, right? Because inside of a program we can run several runtime jobs, for example
  4. In the section not implemented yet ProgramStorageBackend, what is the meaning of Backend? can we use another naming to avoid confusion?

@IceKhan13
Copy link
Member Author

IceKhan13 commented Dec 15, 2022

How to concatenate different programs in a workflow? Any use example?

I think workflows will be inside as tasks and program is just an entrypoint to execution

# program.py

@run_qiskit_remote()
def step_1():
    ...

@run_qiskit_remote()
def step_2():
    ...

@run_qiskit_remote()
def combine_results_step2(step_1_res, step_2_res):
    ...

with serverless:
    result = get(combine_results_step2(step_1(...), step_2(...)))

How to invoke programs from cloud? I mean, the private/hide version of a program to allow users run a program without get the source code of it. Any thoughts or idea to implement it?

later on Program class will local/remote flag. So, if program is remote then run_program will serialize payload and send it over to cloud.

You will still be able to call get_program on private programs to get Program instance, but this instance will only have name of the program to run, no actual data

In the example, Job can be named like program, right? Because inside of a program we can run several runtime jobs, for example

Yes, I'm planning to update docs a little bit in a following PR. Good suggestion on naming and examples!

In the section not implemented yet ProgramStorageBackend, what is the meaning of Backend? can we use another naming to avoid confusion?

Good suggestion, I will remote Backend from name

@IceKhan13 IceKhan13 merged commit ea6ee69 into main Dec 15, 2022
@IceKhan13 IceKhan13 deleted the issue-69/nested-programs-interface branch December 15, 2022 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create new interface: Nested Programs
2 participants