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

Use LocalProvider for test #1212

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 38 additions & 0 deletions .github/workflows/notebook-local-verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Notebook LocalProvider tests

on:
pull_request:
branches: [ main ]

jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: patch notebooks
shell: bash
run: |
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/examples/02_qaoa.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/examples/01_vqe.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/experimental/running_programs_using_decorators.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/experimental/manage_data_directory.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/experimental/file_download.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/basic/02_arguments_and_results.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/basic/04_distributed_workloads.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/basic/05_retrieving_past_results.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/basic/03_dependencies.ipynb
sed -i "s/import ServerlessProvider/import LocalProvider/;s/= ServerlessProvider(/= LocalProvider(/;/token=os\.environ\.get/d;/host=os\.environ\.get/d" docs/getting_started/basic/01_running_program.ipynb
- name: install dependencies
shell: bash
run: pip install client/ && pip install nbmake pytest
- name: Run basic notebooks
shell: bash
run: IN_TEST=True pytest --nbmake docs/getting_started/basic/
- name: Run experimental notebooks
shell: bash
run: IN_TEST=True pytest --nbmake docs/getting_started/experimental/

6 changes: 5 additions & 1 deletion client/quantum_serverless/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def get(self, job_id) -> Optional["Job"]:
def list(self, **kwargs) -> List["Job"]:
return [job["job"] for job in list(self._jobs.values())]

def filtered_logs(self, job_id: str, **kwargs):
"""Return filtered logs."""
raise NotImplementedError

def run(
self,
program: QiskitPattern,
Expand Down Expand Up @@ -362,7 +366,7 @@ def run_existing( # pylint: disable=too-many-locals

def get_programs(self, **kwargs):
"""Returns list of programs."""
raise NotImplementedError
return self._patterns


class GatewayJobClient(BaseJobClient):
Expand Down
38 changes: 38 additions & 0 deletions client/quantum_serverless/core/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import logging
import warnings
import os.path
import os
from dataclasses import dataclass
from typing import Optional, List, Dict, Any, Union

Expand Down Expand Up @@ -608,6 +609,7 @@ def __init__(self):
"""
super().__init__("local-provier")
self.client = LocalJobClient()
self.in_test = os.getenv("IN_TEST")

def run(
self,
Expand All @@ -629,3 +631,39 @@ def get_jobs(self, **kwargs) -> List[Job]:

def upload(self, program: QiskitPattern):
return self.client.upload(program)

def widget(self):
"""Widget for information about provider and jobs."""
return Widget(self).show()

def get_programs(self, **kwargs) -> List[QiskitPattern]:
return self.client.get_programs(**kwargs)

def files(self) -> List[str]:
if self.in_test:
logging.warning("files method is not implemented in LocalProvider.")
return []
raise NotImplementedError("files method is not implemented in LocalProvider.")

def file_upload(self, file: str):
if self.in_test:
logging.warning("file_upload method is not implemented in LocalProvider.")
return
raise NotImplementedError("files method is not implemented in LocalProvider.")

def file_download(
self,
file: str,
target_name: Optional[str] = None,
download_location: str = "./",
):
if self.in_test:
logging.warning("file_download method is not implemented in LocalProvider.")
return None
raise NotImplementedError("files method is not implemented in LocalProvider.")

def file_delete(self, file: str):
if self.in_test:
logging.warning("file_delete method is not implemented in LocalProvider.")
return None
raise NotImplementedError("files method is not implemented in LocalProvider.")
1 change: 1 addition & 0 deletions client/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requests>=2.31.0
importlib-metadata>=5.2.0
qiskit>=0.45.2
qiskit-ibm-runtime>=0.18.0
qiskit-ibm-provider>=0.8.0
# TODO: make sure ray node and notebook node have the same version of cloudpickle
cloudpickle==2.2.1
tqdm>=4.65.0
Expand Down
Loading