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

Experimental new program interface #908

Merged
merged 6 commits into from
Aug 28, 2023
Merged

Conversation

IceKhan13
Copy link
Member

@IceKhan13 IceKhan13 commented Aug 24, 2023

Summary

POC of new interface for program. It adds ability to define and run program inside one file, which is useful for notebook execution.

Details and comments

from quantum_serverless import get_arguments, save_result, distribute_task, distribute_program, get

from qiskit import QuantumCircuit
from qiskit.primitives import Sampler
from qiskit.circuit.random import random_circuit

@distribute_task(target={"cpu": 2})
def distributed_sample(circuit: QuantumCircuit):
    """Distributed task that returns quasi distribution for given circuit."""
    return Sampler().run(circuit).result().quasi_dists[0]


@distribute_program(provider=Provider(...))
def program_with_distributed_tasks(circuits):
    sample_task_references = [
        distributed_sample(circuit)
        for circuit in circuits
    ]
    results = get(sample_task_references)
    print(results)


circuits = []
for _ in range(3):
    circuit = random_circuit(2, 2)
    circuit.measure_all()
    circuits.append(circuit)

job = program_with_distributed_tasks(circuits=circuits)
job.result()
print(job.logs())

Notebook -> https://github.com/Qiskit-Extensions/quantum-serverless/blob/feature/program-decorator/docs/running/notebooks/06_running_programs_using_decorators.ipynb

@IceKhan13 IceKhan13 added WIP work in progress project: client Label to identify features related with client project labels Aug 24, 2023
@IceKhan13 IceKhan13 changed the title Client: poc new program interface POC new program interface Aug 24, 2023
@IceKhan13 IceKhan13 removed the WIP work in progress label Aug 25, 2023
@IceKhan13 IceKhan13 marked this pull request as ready for review August 25, 2023 20:05
@IceKhan13 IceKhan13 changed the title POC new program interface Experimental new program interface Aug 25, 2023
"""[Experimental] Program decorator to turn function into remotely executable program.

Example:
>>> @program(provider=Provider(...), dependencies=[...])
Copy link
Collaborator

Choose a reason for hiding this comment

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

@distributed_program?

Copy link
Member

@Tansito Tansito Aug 28, 2023

Choose a reason for hiding this comment

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

well, good question: is it @distributeD_program or @distribute_program here? 😂

Copy link
Member Author

@IceKhan13 IceKhan13 Aug 28, 2023

Choose a reason for hiding this comment

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

we have distribute_task, therefore I'm using distribute_program to be consistent :)

Copy link
Member

@Tansito Tansito Aug 28, 2023

Choose a reason for hiding this comment

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

well, that closes the question quite easily 😂

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then, the Example must be match to the name :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

that is true! fixed in 112cac7

@Tansito Tansito added the enhancement New feature or request label Aug 28, 2023
def distribute_program(
provider: Optional[Any] = None,
dependencies: Optional[List[str]] = None,
working_dir: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Multiple distributed programs that are executed at the same time with the same working directory may override the entry point file.

Copy link
Member Author

@IceKhan13 IceKhan13 Aug 28, 2023

Choose a reason for hiding this comment

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

good point!

Should we add some random id to autogenerated entrypoints and working directories names?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding random id to the entrypoint may be enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in c27d98f

Copy link
Collaborator

@akihikokuroda akihikokuroda left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@IceKhan13 IceKhan13 merged commit dcd2435 into main Aug 28, 2023
@IceKhan13 IceKhan13 deleted the feature/program-decorator branch August 28, 2023 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request project: client Label to identify features related with client project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants