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

Migrate run end-point and use function.run instead of client.run #1320

Merged
merged 28 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3d01a7a
All old run references removed
Tansito May 7, 2024
9f9f084
Updated tests
Tansito May 7, 2024
3ae2575
Update serializers from run_existing to run
Tansito May 7, 2024
99c7c54
Main changes to run and run_existing applied
Tansito May 8, 2024
30a14fe
Fixed some typos
Tansito May 8, 2024
89d6ae0
Comment test_program by now
Tansito May 8, 2024
8259fff
Added changes to decorators
Tansito May 8, 2024
175dc3d
Comment the entire test
Tansito May 8, 2024
9635eb1
Add upload in test_program
Tansito May 8, 2024
500a3d2
Remove upload
Tansito May 8, 2024
486d2e8
Update from provider to client
Tansito May 8, 2024
968a63b
Updated tests with list
Tansito May 8, 2024
2ad9e52
Use provider instead of client
Tansito May 8, 2024
d9e0dab
Removed tests to review errors
Tansito May 8, 2024
c32a276
Modify local test to use client instead of provider
Tansito May 8, 2024
7300396
Add list method to local client
Tansito May 8, 2024
6bd21fc
Fixed typo
Tansito May 8, 2024
ffa5bc2
Return array of Qiskit Functions in local client
Tansito May 8, 2024
3ecd6a9
Added second test
Tansito May 8, 2024
e192b60
Added third test
Tansito May 8, 2024
7645fa4
Updated fourth test
Tansito May 8, 2024
5a24cc0
Fix typo
Tansito May 8, 2024
90df14e
Added fifth test
Tansito May 8, 2024
dfffe3f
Fixed run typos
Tansito May 8, 2024
59983f5
Added second experimental test
Tansito May 8, 2024
c9b6f20
Add last test
Tansito May 9, 2024
2363e98
Remove run_existing references
Tansito May 9, 2024
3f0bf29
Remove run_existing references in the project
Tansito May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@ jobs:
if: ${{ failure() }}
run: |
docker compose logs gateway
docker compose logs jupyter
6 changes: 3 additions & 3 deletions .github/workflows/notebook-local-verify.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Notebook LocalProvider tests
name: Notebook LocalClient tests

on:
pull_request:
Expand All @@ -16,8 +16,8 @@ jobs:
- name: patch notebooks
shell: bash
run: |
for f in tests/basic/*.py; do sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" "$f"; done
for f in tests/experimental/*.py; do sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" "$f"; done
for f in tests/basic/*.py; do sed -i "s/import ServerlessClient/import LocalClient/;s/= ServerlessClient(/= LocalClient(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" "$f"; done
for f in tests/experimental/*.py; do sed -i "s/import ServerlessClient/import LocalClient/;s/= ServerlessClient(/= LocalClient(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" "$f"; done
- name: install dependencies
shell: bash
run: pip install client/
Expand Down
2 changes: 1 addition & 1 deletion client/qiskit_serverless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
BaseProvider,
BaseClient,
distribute_task,
distribute_qiskit_pattern,
distribute_qiskit_function,
get,
put,
get_refs_by_status,
Expand Down
4 changes: 2 additions & 2 deletions client/qiskit_serverless/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
fetch_execution_meta
distribute_task
distribute_program
distribute_qiskit_pattern
distribute_qiskit_function
get
put
get_refs_by_status
Expand Down Expand Up @@ -82,7 +82,7 @@
get_refs_by_status,
fetch_execution_meta,
distribute_task,
distribute_qiskit_pattern,
distribute_qiskit_function,
distribute_program,
Target,
CircuitMeta,
Expand Down
23 changes: 19 additions & 4 deletions client/qiskit_serverless/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,16 @@ def run(
) -> Job:
tracer = trace.get_tracer("client.tracer")
with tracer.start_as_current_span("Provider.run"):
warnings.warn(
"`run` method has been deprecated. "
"And will be removed in future releases. "
"Please, use `function.run` instead.",
DeprecationWarning,
)
if isinstance(program, QiskitFunction) and program.entrypoint is not None:
job = self._job_client.run(program, arguments, config)
job = self._job_client.run(program.title, arguments, config)
else:
job = self._job_client.run_existing(program, arguments, config)
job = self._job_client.run(program, arguments, config)
return job

def upload(self, program: QiskitFunction):
Expand Down Expand Up @@ -661,10 +667,16 @@ def run(
arguments: Optional[Dict[str, Any]] = None,
config: Optional[Configuration] = None,
) -> Job:
warnings.warn(
"`client.run` method has been deprecated. "
"And will be removed in future releases. "
"Please, use `function.run` instead.",
DeprecationWarning,
)
if isinstance(program, QiskitFunction) and program.entrypoint is not None:
job = self.client.run(program, arguments)
job = self.client.run(program.title, arguments, config)
else:
job = self.client.run_existing(program, arguments)
job = self.client.run(program, arguments, config)
return job

def get_job_by_id(self, job_id: str) -> Optional[Job]:
Expand Down Expand Up @@ -712,6 +724,9 @@ def file_delete(self, file: str):
return None
raise NotImplementedError("files method is not implemented in LocalProvider.")

def list(self, **kwargs):
return self.client.get_programs(**kwargs)


class LocalProvider(LocalClient):
"""
Expand Down
18 changes: 10 additions & 8 deletions client/qiskit_serverless/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ def wrapper(*args, **kwargs):
"""


def distribute_qiskit_pattern(
def distribute_qiskit_function(
provider: Optional[Any] = None,
dependencies: Optional[List[str]] = None,
working_dir: Optional[str] = None,
):
"""[Experimental] QiskitPattern decorator to turn function into remotely executable program.
"""[Experimental] QiskitFunction decorator to turn function into remotely executable program.

Example:
>>> @distribute_qiskit_pattern(provider=ServerlessProvider(...), dependencies=[...])
>>> @distribute_qiskit_function(provider=ServerlessProvider(...), dependencies=[...])
>>> def my_program():
>>> print("Hola!")
>>>
Expand All @@ -357,7 +357,7 @@ def distribute_qiskit_pattern(
"""
# pylint: disable=import-outside-toplevel,cyclic-import
from qiskit_serverless import QiskitServerlessException
from qiskit_serverless.core.function import QiskitPattern
from qiskit_serverless.core.function import QiskitFunction
from qiskit_serverless.core.client import ServerlessProvider

# create provider
Expand Down Expand Up @@ -412,14 +412,16 @@ def wrapper(*args, **kwargs):
file.write(ENTRYPOINT_CONTENT.format(file_name=pickle_file_name))

# create program
wrapped_program = QiskitPattern(
wrapped_program = QiskitFunction(
title=function.__name__,
entrypoint=entrypoint_file_name,
working_dir=working_directory,
dependencies=dependencies,
description="QiskitPattern execution using @distribute_program decorator.",
description="QiskitFunction execution using @distribute_program decorator.",
)

provider.upload(wrapped_program)

# run program
job = provider.run(wrapped_program, arguments=kwargs)

Expand All @@ -446,6 +448,6 @@ def distribute_program(
warnings.warn(
"`distribute_program` has been deprecated "
"and will be removed in future releases. "
"Please, use `distribute_qiskit_pattern` instead."
"Please, use `distribute_qiskit_function` instead."
)
return distribute_qiskit_pattern(provider, dependencies, working_dir)
return distribute_qiskit_function(provider, dependencies, working_dir)
14 changes: 6 additions & 8 deletions client/qiskit_serverless/core/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,19 @@ def run(self, **kwargs):
raise ValueError("No clients specified for a function.")

if self.validate:
is_valid, validation_errors = self._validate_funciton()
is_valid, validation_errors = self._validate_function()
if not is_valid:
error_string = "\n".join(validation_errors)
raise ValueError(
f"Function validation failed. Validation errors:\n {error_string}",
)

if self._is_local_function():
return self.job_client.run(program=self, arguments=kwargs)
return self.job_client.run_existing(program=self.title, arguments=kwargs)
config = kwargs.pop("config", None)
return self.job_client.run_existing(
program=self.title, arguments=kwargs, config=config
)

def _is_local_function(self) -> bool:
return self.entrypoint is not None and self.working_dir is not None

def _validate_funciton(self) -> Tuple[bool, List[str]]:
def _validate_function(self) -> Tuple[bool, List[str]]:
"""Validate function arguments using schema provided.

Returns:
Expand Down
Loading
Loading