From 1d0e17722326ea4f03642cf502e8284af6de2de5 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Tue, 17 May 2022 16:20:55 -0400 Subject: [PATCH 01/25] added status parameter to job list, TypeError with parameter however --- xcc/commands.py | 5 +++-- xcc/job.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/xcc/commands.py b/xcc/commands.py index 200f0ef..aaf493b 100644 --- a/xcc/commands.py +++ b/xcc/commands.py @@ -257,18 +257,19 @@ def get_job( @beautify -def list_jobs(limit: int = 5, ids: List[str] = None) -> Sequence[Mapping]: +def list_jobs(limit: int = 5, ids: List[str] = None, status: str = None) -> Sequence[Mapping]: """Lists jobs submitted to the Xanadu Cloud. Args: limit (int): Maximum number of jobs to display. ids (List[str], optional): IDs of the jobs to display. If at least one ID is specified, the limit flag will be set to the number of IDs. + status (str): Status parameter used to filter returned jobs based on given status. Returns: Sequence[Mapping]: Overview of each job submitted to the Xanadu Cloud. """ - jobs = Job.list(connection=load_connection(), limit=limit, ids=ids) + jobs = Job.list(connection=load_connection(), limit=limit, ids=ids, status=status) return [job.overview for job in jobs] diff --git a/xcc/job.py b/xcc/job.py index a7a125a..d10fb07 100644 --- a/xcc/job.py +++ b/xcc/job.py @@ -5,6 +5,7 @@ from __future__ import annotations import io +from os import stat import time from datetime import datetime, timedelta from itertools import count, takewhile @@ -93,22 +94,29 @@ class Job: @staticmethod def list( - connection: Connection, limit: int = 5, ids: Optional[Collection[str]] = None + connection: Connection, + limit: int = 5, + ids: Optional[Collection[str]] = None, + test: str = None ) -> Sequence[Job]: """Returns jobs submitted to the Xanadu Cloud. + Args: connection (Connection): connection to the Xanadu Cloud limit (int): maximum number of jobs to retrieve ids (Collection[str], optional): IDs of the jobs to retrieve; if at least one ID is specified, ``limit`` will be set to the length of the ID collection + status (str): optional status parameter used to filter the jobs list. + If status is empty, return all the jobs Returns: Sequence[Job]: jobs which were submitted on the Xanadu Cloud by the user associated with the Xanadu Cloud connection """ - size = len(ids) if ids else limit + size = len(ids) if ids else limit # fix this to find all jobs instead. + # size = len(ids) response = connection.request("GET", "/jobs", params={"size": size, "id": ids}) jobs = [] @@ -118,7 +126,9 @@ def list( job._details = details # pylint: disable=protected-access jobs.append(job) - return jobs + filtered_jobs = list(filter(lambda job: (job.status == test), jobs)) + + return filtered_jobs if test else jobs @staticmethod def submit( From 3662b58aed4faaddb360addb98f19f97b5c2c6f2 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Thu, 26 May 2022 14:15:42 -0400 Subject: [PATCH 02/25] Add status parameter to job list --- tests/test_commands.py | 2 +- xcc/job.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 3a15b1b..10e0248 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -47,7 +47,7 @@ class MockJob(xcc.Job): """ @staticmethod - def list(connection, limit=10, ids=None): + def list(connection, limit=10, ids=None, status= None): connection = xcc.commands.load_connection() return [MockJob(id_, connection) for id_ in ("foo", "bar", "baz")][:limit] diff --git a/xcc/job.py b/xcc/job.py index d10fb07..8fe5e43 100644 --- a/xcc/job.py +++ b/xcc/job.py @@ -97,7 +97,7 @@ def list( connection: Connection, limit: int = 5, ids: Optional[Collection[str]] = None, - test: str = None + status: str = None ) -> Sequence[Job]: """Returns jobs submitted to the Xanadu Cloud. @@ -108,16 +108,16 @@ def list( ids (Collection[str], optional): IDs of the jobs to retrieve; if at least one ID is specified, ``limit`` will be set to the length of the ID collection - status (str): optional status parameter used to filter the jobs list. + status (str, optional): status parameter used to filter the jobs list. If status is empty, return all the jobs Returns: Sequence[Job]: jobs which were submitted on the Xanadu Cloud by the user associated with the Xanadu Cloud connection """ - size = len(ids) if ids else limit # fix this to find all jobs instead. - # size = len(ids) - response = connection.request("GET", "/jobs", params={"size": size, "id": ids}) + size = len(ids) if ids else limit + + response = connection.request("GET", "/jobs", params={"size": size, "id": ids, "status": status}) jobs = [] @@ -126,9 +126,8 @@ def list( job._details = details # pylint: disable=protected-access jobs.append(job) - filtered_jobs = list(filter(lambda job: (job.status == test), jobs)) + return jobs - return filtered_jobs if test else jobs @staticmethod def submit( From 5bdcd5149f1a4fa384f0fd0d2e1b33e58e7cf98c Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Fri, 27 May 2022 13:22:14 -0400 Subject: [PATCH 03/25] Added tests for job status filter --- docs/conf.py | 8 +--- tests/test_commands.py | 2 +- tests/test_job.py | 89 +++++++++++++++++++++++++++++++++++++++++- xcc/commands.py | 2 +- xcc/job.py | 33 ++++++++++------ 5 files changed, 114 insertions(+), 20 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 38edfbd..16531c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -59,9 +59,7 @@ # Tell sphinx what the pygments highlight language should be. highlight_language = "py" -mathjax_path = ( - "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" -) +mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" nbsphinx_requirejs_path = "" # Add any paths that contain templates here, relative to this directory. @@ -85,6 +83,7 @@ # # The full version, including alpha/beta/rc tags. import xcc + release = xcc.__version__ # The short X.Y version. @@ -253,7 +252,6 @@ html_theme_options = { "navbar_name": "Xanadu Cloud Client", "navbar_logo_colour": "#78909c", - "navbar_right_links": [ { "name": "GitHub", @@ -261,14 +259,12 @@ "icon": "fab fa-github", } ], - "border_colour": "#78909c", "prev_next_button_colour": "#607d8b", "prev_next_button_hover_colour": "#34515e", "toc_marker_colour": "#78909c", "table_header_background_colour": "#78909c", "text_accent_colour": "#78909c", - } edit_on_github_project = "XanaduAI/xanadu-cloud-client" diff --git a/tests/test_commands.py b/tests/test_commands.py index 10e0248..a182f67 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -47,7 +47,7 @@ class MockJob(xcc.Job): """ @staticmethod - def list(connection, limit=10, ids=None, status= None): + def list(connection, limit=10, ids=None, status=None): connection = xcc.commands.load_connection() return [MockJob(id_, connection) for id_ in ("foo", "bar", "baz")][:limit] diff --git a/tests/test_job.py b/tests/test_job.py index 82e229a..e1f245d 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -123,6 +123,87 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name have_params = responses.calls[0].request.params # pyright: reportGeneralTypeIssues=false assert have_params == want_params + @pytest.mark.parametrize( + "limit, ids, status, want_params, want_names", + [ + ( + 1, + None, + "queued", + {"size": "1", "status": "queued"}, + ["foo"], + ), + ( + 2, + None, + "", + {"size": "2"}, + ["foo", "bar"], + ), + ( + 2, + None, + "invalid", + {"size": "2", "status": "invalid"}, + [], + ), + ( + 2, + [ + "00000000-0000-0000-0000-000000000001", + "00000000-0000-0000-0000-000000000002", + "00000000-0000-0000-0000-000000000003", + ], + "complete", + { + "size": "3", + "id": [ + "00000000-0000-0000-0000-000000000001", + "00000000-0000-0000-0000-000000000002", + "00000000-0000-0000-0000-000000000003", + ], + "status": "complete", + }, + ["bar"], + ), + ], + ) + @responses.activate + def test_list_status( + self, connection, add_response, limit, ids, status, want_params, want_names + ): + """Tests that the correct jobs are listed and that the correct query + parameters are encoded in the HTTP request to the Xanadu Cloud platform. + We ensure that the jobs are filtered by the given status. + """ + data = [ + { + "id": "00000000-0000-0000-0000-000000000001", + "name": "foo", + "status": "queued", + "target": "qpu", + "created_at": "2020-01-03T12:34:56.789012+00:00", + }, + { + "id": "00000000-0000-0000-0000-000000000002", + "name": "bar", + "status": "complete", + "target": "qpu", + "created_at": "2020-01-03T12:34:56.789012+00:00", + "finished_at": "2020-01-03T12:34:56.789013+00:00", + }, + ][:limit] + + add_response(body={"data": data}, path="/jobs") + + have_names = [ + job.name for job in xcc.Job.list(connection, limit=limit, ids=ids, status=status) + ] + assert have_names == want_names + + have_params = responses.calls[0].request.params # pyright: reportGeneralTypeIssues=false + assert have_params == want_params + @pytest.mark.parametrize("name", [None, "foo"]) @responses.activate def test_submit(self, job_id, connection, name): @@ -167,7 +248,13 @@ def test_result(self, connection, job): with io.BytesIO() as buffer: # The public savez() function does not allow pickling to be disabled. savez = numpy.lib.npyio._savez # pylint: disable=protected-access - savez(file=buffer, args=output, kwds=metadata, compress=False, allow_pickle=False) + savez( + file=buffer, + args=output, + kwds=metadata, + compress=False, + allow_pickle=False, + ) buffer.seek(0) body = buffer.read() diff --git a/xcc/commands.py b/xcc/commands.py index aaf493b..03e6c40 100644 --- a/xcc/commands.py +++ b/xcc/commands.py @@ -264,7 +264,7 @@ def list_jobs(limit: int = 5, ids: List[str] = None, status: str = None) -> Sequ limit (int): Maximum number of jobs to display. ids (List[str], optional): IDs of the jobs to display. If at least one ID is specified, the limit flag will be set to the number of IDs. - status (str): Status parameter used to filter returned jobs based on given status. + status (str): Status parameter used to filter returned jobs based on given status. Returns: Sequence[Mapping]: Overview of each job submitted to the Xanadu Cloud. diff --git a/xcc/job.py b/xcc/job.py index 8fe5e43..3606021 100644 --- a/xcc/job.py +++ b/xcc/job.py @@ -5,7 +5,6 @@ from __future__ import annotations import io -from os import stat import time from datetime import datetime, timedelta from itertools import count, takewhile @@ -94,10 +93,10 @@ class Job: @staticmethod def list( - connection: Connection, - limit: int = 5, + connection: Connection, + limit: int = 5, ids: Optional[Collection[str]] = None, - status: str = None + status: str = None, ) -> Sequence[Job]: """Returns jobs submitted to the Xanadu Cloud. @@ -108,16 +107,18 @@ def list( ids (Collection[str], optional): IDs of the jobs to retrieve; if at least one ID is specified, ``limit`` will be set to the length of the ID collection - status (str, optional): status parameter used to filter the jobs list. - If status is empty, return all the jobs + status (str, optional): status parameter used to filter the jobs list. + If status is empty, return all the jobs Returns: Sequence[Job]: jobs which were submitted on the Xanadu Cloud by the user associated with the Xanadu Cloud connection """ - size = len(ids) if ids else limit + size = len(ids) if ids else limit - response = connection.request("GET", "/jobs", params={"size": size, "id": ids, "status": status}) + response = connection.request( + "GET", "/jobs", params={"size": size, "id": ids, "status": status} + ) jobs = [] @@ -126,12 +127,17 @@ def list( job._details = details # pylint: disable=protected-access jobs.append(job) - return jobs + filtered_jobs = list(filter(lambda job: (job.status == status), jobs)) + return filtered_jobs if status else jobs @staticmethod def submit( - connection: Connection, name: Optional[str], target: str, circuit: str, language: str + connection: Connection, + name: Optional[str], + target: str, + circuit: str, + language: str, ) -> Job: """Submits a job to the Xanadu Cloud. @@ -145,7 +151,12 @@ def submit( Returns: Job: job submitted to the Xanadu Cloud """ - payload = {"name": name, "target": target, "circuit": circuit, "language": language} + payload = { + "name": name, + "target": target, + "circuit": circuit, + "language": language, + } response = connection.request("POST", "/jobs", json=payload) details = response.json() From bd4de4ec69ac070a6b86ff2bfbb69af2c9f7a2b5 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Fri, 27 May 2022 17:16:29 -0400 Subject: [PATCH 04/25] Modified tests job status filteration --- tests/test_job.py | 13 +++++++++---- xcc/job.py | 4 +--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index e1f245d..b7009e9 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -136,7 +136,7 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name ( 2, None, - "", + None, {"size": "2"}, ["foo", "bar"], ), @@ -195,10 +195,15 @@ def test_list_status( ][:limit] add_response(body={"data": data}, path="/jobs") + if status is not None: + have_names = [ + job.name + for job in xcc.Job.list(connection, limit=limit, ids=ids, status=status) + if status is not None and job.status == status + ] + else: + have_names = [job.name for job in xcc.Job.list(connection, limit=limit, ids=ids)] - have_names = [ - job.name for job in xcc.Job.list(connection, limit=limit, ids=ids, status=status) - ] assert have_names == want_names have_params = responses.calls[0].request.params # pyright: reportGeneralTypeIssues=false diff --git a/xcc/job.py b/xcc/job.py index 3606021..1726255 100644 --- a/xcc/job.py +++ b/xcc/job.py @@ -127,9 +127,7 @@ def list( job._details = details # pylint: disable=protected-access jobs.append(job) - filtered_jobs = list(filter(lambda job: (job.status == status), jobs)) - - return filtered_jobs if status else jobs + return jobs @staticmethod def submit( From 473e66e4b51accc3ec0cd0e90d997cd53d4fb62d Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Fri, 27 May 2022 17:39:55 -0400 Subject: [PATCH 05/25] Make CHANGELOG.md changes --- .github/CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 8921d7f..306240c 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -40,6 +40,21 @@ This release contains contributions from (in alphabetical order): ### New features since last release +* Job lists can now be filtered by status as well. + [(#30)](https://github.com/XanaduAI/xanadu-cloud-client/pull/30) + + Using the CLI: + + ```bash + xcc job list --status '' + ``` + + Using the Python API: + + ```python + xcc.Job.list(connection, status='') + ``` + * The Connection class can now load a Connection from a Settings instance. [(#22)](https://github.com/XanaduAI/xanadu-cloud-client/pull/22) From 821188662f5d4e901bc65ece81189ee2719e6a06 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Tue, 31 May 2022 13:43:22 -0400 Subject: [PATCH 06/25] Update .github/CHANGELOG.md Co-authored-by: Paul Finlay <50180049+doctorperceptron@users.noreply.github.com> --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 306240c..e653567 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -40,7 +40,7 @@ This release contains contributions from (in alphabetical order): ### New features since last release -* Job lists can now be filtered by status as well. +* Job lists can now be filtered by status. [(#30)](https://github.com/XanaduAI/xanadu-cloud-client/pull/30) Using the CLI: From 307487a9f5e14af154af2c97daf7791bf8390989 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Tue, 31 May 2022 14:19:26 -0400 Subject: [PATCH 07/25] Change CHANGELOG --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 306240c..e653567 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -40,7 +40,7 @@ This release contains contributions from (in alphabetical order): ### New features since last release -* Job lists can now be filtered by status as well. +* Job lists can now be filtered by status. [(#30)](https://github.com/XanaduAI/xanadu-cloud-client/pull/30) Using the CLI: From e3c06d8cb9b5aa2b1e669dbb3dc462553087789d Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Tue, 31 May 2022 15:56:37 -0400 Subject: [PATCH 08/25] Fix issue --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index e653567..306240c 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -40,7 +40,7 @@ This release contains contributions from (in alphabetical order): ### New features since last release -* Job lists can now be filtered by status. +* Job lists can now be filtered by status as well. [(#30)](https://github.com/XanaduAI/xanadu-cloud-client/pull/30) Using the CLI: From de7bf5571a5553ed422064eff9b576837d6567b9 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Tue, 31 May 2022 16:25:09 -0400 Subject: [PATCH 09/25] Change language for conf.py to 'en' --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 16531c3..36ba5a3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -94,7 +94,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: From 85dea1025a87ed0cebc1a2b1f96a836a1ebea6e8 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Tue, 31 May 2022 16:36:34 -0400 Subject: [PATCH 10/25] Change sphinx version to 4.5.0 --- docs/conf.py | 2 +- docs/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 36ba5a3..16531c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -94,7 +94,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = "en" +language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: diff --git a/docs/requirements.txt b/docs/requirements.txt index 63ed2bf..377e4ca 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,5 @@ docutils m2r2 nbsphinx sphinx-copybutton -sphinx>=3.1.0 +sphinx==4.5.0 xanadu-sphinx-theme==0.1.0 From 16290b5aa41f14615198227130a201a558cc687d Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Tue, 31 May 2022 16:53:43 -0400 Subject: [PATCH 11/25] Change traitlets to working version --- docs/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/requirements.txt b/docs/requirements.txt index 377e4ca..86c6220 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,3 +4,4 @@ nbsphinx sphinx-copybutton sphinx==4.5.0 xanadu-sphinx-theme==0.1.0 +traitlets==5.2.0 From 51c9c4e7ae4d6219b50a8b946757eef614fb0ee8 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Wed, 1 Jun 2022 16:36:47 -0400 Subject: [PATCH 12/25] Fix minor issues and changes --- .github/CHANGELOG.md | 36 +++++++++++---------- docs/conf.py | 4 ++- docs/requirements.txt | 1 - tests/test_job.py | 73 +++++++------------------------------------ xcc/commands.py | 2 +- xcc/job.py | 11 +++---- 6 files changed, 39 insertions(+), 88 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 306240c..f6e459e 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,9 +1,28 @@ ## Release 0.3.0 (development release) +### New features since last release + +* Job lists can now be filtered by status. + [(#30)](https://github.com/XanaduAI/xanadu-cloud-client/pull/30) + + Using the CLI: + + ```bash + xcc job list --status '' + ``` + + Using the Python API: + + ```python + xcc.Job.list(connection, status="") + ``` + ### Contributors This release contains contributions from (in alphabetical order): +[Hudhayfa Zaheem](https://github.com/HudZah). + ## Release 0.2.1 (current release) ### New features since last release @@ -38,23 +57,6 @@ This release contains contributions from (in alphabetical order): ## Release 0.2.0 -### New features since last release - -* Job lists can now be filtered by status as well. - [(#30)](https://github.com/XanaduAI/xanadu-cloud-client/pull/30) - - Using the CLI: - - ```bash - xcc job list --status '' - ``` - - Using the Python API: - - ```python - xcc.Job.list(connection, status='') - ``` - * The Connection class can now load a Connection from a Settings instance. [(#22)](https://github.com/XanaduAI/xanadu-cloud-client/pull/22) diff --git a/docs/conf.py b/docs/conf.py index 16531c3..a53e364 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -59,7 +59,9 @@ # Tell sphinx what the pygments highlight language should be. highlight_language = "py" -mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" +mathjax_path = ( + "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" + ) nbsphinx_requirejs_path = "" # Add any paths that contain templates here, relative to this directory. diff --git a/docs/requirements.txt b/docs/requirements.txt index 86c6220..377e4ca 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,4 +4,3 @@ nbsphinx sphinx-copybutton sphinx==4.5.0 xanadu-sphinx-theme==0.1.0 -traitlets==5.2.0 diff --git a/tests/test_job.py b/tests/test_job.py index b7009e9..69f658c 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -124,29 +124,16 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name assert have_params == want_params @pytest.mark.parametrize( - "limit, ids, status, want_params, want_names", + "limit, ids, status, want_status_param", [ - ( - 1, - None, - "queued", - {"size": "1", "status": "queued"}, - ["foo"], - ), + (1, None, "queued", "queued"), ( 2, None, None, - {"size": "2"}, - ["foo", "bar"], - ), - ( - 2, None, - "invalid", - {"size": "2", "status": "invalid"}, - [], ), + (2, None, "invalid", "invalid"), ( 2, [ @@ -155,59 +142,21 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name "00000000-0000-0000-0000-000000000003", ], "complete", - { - "size": "3", - "id": [ - "00000000-0000-0000-0000-000000000001", - "00000000-0000-0000-0000-000000000002", - "00000000-0000-0000-0000-000000000003", - ], - "status": "complete", - }, - ["bar"], + "complete", ), ], ) @responses.activate - def test_list_status( - self, connection, add_response, limit, ids, status, want_params, want_names - ): - """Tests that the correct jobs are listed and that the correct query - parameters are encoded in the HTTP request to the Xanadu Cloud platform. - We ensure that the jobs are filtered by the given status. + def test_list_status(self, connection, add_response, limit, ids, status, want_status_param): + """Tests that the correct jobs are listed and that the correct status + parameter is encoded in the HTTP request to the Xanadu Cloud platform. """ - data = [ - { - "id": "00000000-0000-0000-0000-000000000001", - "name": "foo", - "status": "queued", - "target": "qpu", - "created_at": "2020-01-03T12:34:56.789012+00:00", - }, - { - "id": "00000000-0000-0000-0000-000000000002", - "name": "bar", - "status": "complete", - "target": "qpu", - "created_at": "2020-01-03T12:34:56.789012+00:00", - "finished_at": "2020-01-03T12:34:56.789013+00:00", - }, - ][:limit] - - add_response(body={"data": data}, path="/jobs") - if status is not None: - have_names = [ - job.name - for job in xcc.Job.list(connection, limit=limit, ids=ids, status=status) - if status is not None and job.status == status - ] - else: - have_names = [job.name for job in xcc.Job.list(connection, limit=limit, ids=ids)] - - assert have_names == want_names + add_response(body={"data": []}, path="/jobs") + xcc.Job.list(connection, limit=limit, status=status) have_params = responses.calls[0].request.params # pyright: reportGeneralTypeIssues=false - assert have_params == want_params + have_status_param = have_params.get("status") + assert have_status_param == want_status_param @pytest.mark.parametrize("name", [None, "foo"]) @responses.activate diff --git a/xcc/commands.py b/xcc/commands.py index 03e6c40..94cc708 100644 --- a/xcc/commands.py +++ b/xcc/commands.py @@ -264,7 +264,7 @@ def list_jobs(limit: int = 5, ids: List[str] = None, status: str = None) -> Sequ limit (int): Maximum number of jobs to display. ids (List[str], optional): IDs of the jobs to display. If at least one ID is specified, the limit flag will be set to the number of IDs. - status (str): Status parameter used to filter returned jobs based on given status. + status (str, optional): If specificed, filter returned jobs by the given status. Returns: Sequence[Mapping]: Overview of each job submitted to the Xanadu Cloud. diff --git a/xcc/job.py b/xcc/job.py index 1726255..591c3fe 100644 --- a/xcc/job.py +++ b/xcc/job.py @@ -96,7 +96,7 @@ def list( connection: Connection, limit: int = 5, ids: Optional[Collection[str]] = None, - status: str = None, + status: Optional[str] = None, ) -> Sequence[Job]: """Returns jobs submitted to the Xanadu Cloud. @@ -107,8 +107,7 @@ def list( ids (Collection[str], optional): IDs of the jobs to retrieve; if at least one ID is specified, ``limit`` will be set to the length of the ID collection - status (str, optional): status parameter used to filter the jobs list. - If status is empty, return all the jobs + status (str, optional): filter jobs by the given status (if not ``None``) Returns: Sequence[Job]: jobs which were submitted on the Xanadu Cloud by the @@ -116,10 +115,10 @@ def list( """ size = len(ids) if ids else limit - response = connection.request( - "GET", "/jobs", params={"size": size, "id": ids, "status": status} - ) + params = {"size": size, "id": ids, "status": status} + response = connection.request("GET", "/jobs", params=params) + print(response.url) jobs = [] for details in response.json()["data"]: From 4c705e3df4b2c6d78c1d315034f934afad74fc78 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Wed, 1 Jun 2022 16:37:35 -0400 Subject: [PATCH 13/25] Update sphinx version --- docs/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 377e4ca..30a2c3a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,5 @@ docutils m2r2 nbsphinx sphinx-copybutton -sphinx==4.5.0 -xanadu-sphinx-theme==0.1.0 +sphinx>=3.1.0 +xanadu-sphinx-theme==0.1.0 \ No newline at end of file From 374348eb9e0bc8a9f7c7227905afb33c52e40b16 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem Date: Wed, 1 Jun 2022 17:02:20 -0400 Subject: [PATCH 14/25] Modify requirements.txt --- docs/requirements.txt | 5 +++-- tests/test_job.py | 14 ++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 30a2c3a..86c6220 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ docutils m2r2 nbsphinx sphinx-copybutton -sphinx>=3.1.0 -xanadu-sphinx-theme==0.1.0 \ No newline at end of file +sphinx==4.5.0 +xanadu-sphinx-theme==0.1.0 +traitlets==5.2.0 diff --git a/tests/test_job.py b/tests/test_job.py index 69f658c..e3f90cd 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -124,30 +124,24 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name assert have_params == want_params @pytest.mark.parametrize( - "limit, ids, status, want_status_param", + "limit, status, want_status_param", [ - (1, None, "queued", "queued"), + (1, "queued", "queued"), ( 2, None, None, - None, ), - (2, None, "invalid", "invalid"), + (2, "invalid", "invalid"), ( 2, - [ - "00000000-0000-0000-0000-000000000001", - "00000000-0000-0000-0000-000000000002", - "00000000-0000-0000-0000-000000000003", - ], "complete", "complete", ), ], ) @responses.activate - def test_list_status(self, connection, add_response, limit, ids, status, want_status_param): + def test_list_status(self, connection, add_response, limit, status, want_status_param): """Tests that the correct jobs are listed and that the correct status parameter is encoded in the HTTP request to the Xanadu Cloud platform. """ From be57696b40b788aa64350f71f9fa9ab265f82a0e Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:22:19 -0400 Subject: [PATCH 15/25] Update .github/CHANGELOG.md Co-authored-by: Mikhail Andrenkov --- .github/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index f6e459e..384762d 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,4 +1,5 @@ ## Release 0.3.0 (development release) + ### New features since last release * Job lists can now be filtered by status. From b42de8fdc46d8e7b9a63530e7977bdb39dda1687 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:22:26 -0400 Subject: [PATCH 16/25] Update docs/conf.py Co-authored-by: Mikhail Andrenkov --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a53e364..08bd623 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -61,7 +61,7 @@ mathjax_path = ( "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" - ) +) nbsphinx_requirejs_path = "" # Add any paths that contain templates here, relative to this directory. From fba2f8501682121718d4ed428252ecb9bb0971b5 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:22:42 -0400 Subject: [PATCH 17/25] Update tests/test_job.py Co-authored-by: Mikhail Andrenkov --- tests/test_job.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index e3f90cd..3ee03fe 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -127,17 +127,9 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name "limit, status, want_status_param", [ (1, "queued", "queued"), - ( - 2, - None, - None, - ), + (2, None, None), (2, "invalid", "invalid"), - ( - 2, - "complete", - "complete", - ), + (2, "complete", "complete"), ], ) @responses.activate From 60fe4b287a87b408330ee136913dbada648a5c82 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:22:54 -0400 Subject: [PATCH 18/25] Update tests/test_job.py Co-authored-by: Mikhail Andrenkov --- tests/test_job.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index 3ee03fe..395a1e4 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -134,8 +134,8 @@ def test_list(self, connection, add_response, limit, ids, want_params, want_name ) @responses.activate def test_list_status(self, connection, add_response, limit, status, want_status_param): - """Tests that the correct jobs are listed and that the correct status - parameter is encoded in the HTTP request to the Xanadu Cloud platform. + """Tests that the correct status parameter is encoded in the HTTP + request to the Xanadu Cloud platform when listing jobs. """ add_response(body={"data": []}, path="/jobs") xcc.Job.list(connection, limit=limit, status=status) From fad822702a92e83148b1b91a166f1930ecd816b4 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:23:01 -0400 Subject: [PATCH 19/25] Update xcc/job.py Co-authored-by: Mikhail Andrenkov --- xcc/job.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xcc/job.py b/xcc/job.py index 591c3fe..a2ca946 100644 --- a/xcc/job.py +++ b/xcc/job.py @@ -118,7 +118,6 @@ def list( params = {"size": size, "id": ids, "status": status} response = connection.request("GET", "/jobs", params=params) - print(response.url) jobs = [] for details in response.json()["data"]: From 0ec2c9d1ed3c48d9045b711b5ff6280fbe69e0e9 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:23:11 -0400 Subject: [PATCH 20/25] Update docs/requirements.txt Co-authored-by: Mikhail Andrenkov --- docs/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 86c6220..377e4ca 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,4 +4,3 @@ nbsphinx sphinx-copybutton sphinx==4.5.0 xanadu-sphinx-theme==0.1.0 -traitlets==5.2.0 From 1cbe32cdf26506248320c4a17bfc59265c7cea92 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:27:58 -0400 Subject: [PATCH 21/25] Update sphinx version. Co-authored-by: Mikhail Andrenkov --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 377e4ca..f4fb46a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,5 @@ docutils m2r2 nbsphinx sphinx-copybutton -sphinx==4.5.0 +sphinx<5.0.0 xanadu-sphinx-theme==0.1.0 From 9395a59509109849ae186673de2e3cc2d8e08d8c Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:45:58 -0400 Subject: [PATCH 22/25] Update sphinx to working version. --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index f4fb46a..9eed5e6 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,5 @@ docutils m2r2 nbsphinx sphinx-copybutton -sphinx<5.0.0 +sphinx<=4.5.0 xanadu-sphinx-theme==0.1.0 From 6da7c6dc7c924c8037ed1a2a731dd8963242d20f Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:53:33 -0400 Subject: [PATCH 23/25] Pin Jinja version See https://github.com/readthedocs/readthedocs.org/issues/9038 --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 9eed5e6..2dee36a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ docutils m2r2 nbsphinx sphinx-copybutton -sphinx<=4.5.0 +Jinja2<3.1 +sphinx<5.0.0 xanadu-sphinx-theme==0.1.0 From 5912fd74ef5e8dd06134190621cb83aa53a664b0 Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:56:22 -0400 Subject: [PATCH 24/25] Update requirements.txt --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 2dee36a..d2fe16c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,5 +3,5 @@ m2r2 nbsphinx sphinx-copybutton Jinja2<3.1 -sphinx<5.0.0 +sphinx<=4.5.0 xanadu-sphinx-theme==0.1.0 From 169d88b1588601ae9b051168cb51114a5356291d Mon Sep 17 00:00:00 2001 From: Hudhayfa Zaheem <56107325+HudZah@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:58:51 -0400 Subject: [PATCH 25/25] Update requirements.txt --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index d2fe16c..c1379c5 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,5 +3,5 @@ m2r2 nbsphinx sphinx-copybutton Jinja2<3.1 -sphinx<=4.5.0 +sphinx==4.5.0 xanadu-sphinx-theme==0.1.0