Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
464192f
Remove version field from runtime program (#152)
rathishcholarajan Oct 18, 2021
abb98d0
Rename isPublic to is_public when creating or reading runtime program…
rathishcholarajan Oct 18, 2021
31fdd4b
Update programId to program_id when running program (#139)
renier Oct 18, 2021
0d5ebf8
Add support to view program update date (#160)
rathishcholarajan Oct 18, 2021
767afeb
Upload runtime program using 'data' field (#157)
rathishcholarajan Oct 19, 2021
24dfa95
Read programs from "programs" array in response (#161)
rathishcholarajan Oct 19, 2021
79cd9bd
Remove version field from runtime program (#152)
rathishcholarajan Oct 18, 2021
45ab0b2
Rename isPublic to is_public when creating or reading runtime program…
rathishcholarajan Oct 18, 2021
faff4e2
Update programId to program_id when running program (#139)
renier Oct 18, 2021
bcc27fb
Add support to view program update date (#160)
rathishcholarajan Oct 18, 2021
866d045
Upload runtime program using 'data' field (#157)
rathishcholarajan Oct 19, 2021
eda2a51
Read programs from "programs" array in response (#161)
rathishcholarajan Oct 19, 2021
ab33b52
Pass program as base64 string to update (#168)
rathishcholarajan Oct 21, 2021
a8fe605
Accept JSON schema as program metadata (#158)
rathishcholarajan Oct 25, 2021
1b26e0b
Merge branch 'runtime-release-q4' of https://github.com/Qiskit-Partne…
kt474 Oct 26, 2021
df4eb81
Pass program params as object (#171)
rathishcholarajan Oct 27, 2021
e3e4315
Fix integration tests
rathishcholarajan Oct 27, 2021
f5712bc
Merge branch 'runtime-release-q4' of https://github.com/Qiskit-Partne…
kt474 Oct 28, 2021
0f95825
Use count to reduce one last extra call to API (#172)
rathishcholarajan Oct 28, 2021
b532b14
Allow updating runtime metadata in place (#188)
jyu00 Oct 29, 2021
c1065f0
Merge branch 'runtime-release-q4' of https://github.com/Qiskit-Partne…
kt474 Nov 1, 2021
f5b4e54
Remove version field from runtime program (#152)
rathishcholarajan Oct 18, 2021
93a2b85
Rename isPublic to is_public when creating or reading runtime program…
rathishcholarajan Oct 18, 2021
966d42a
Update programId to program_id when running program (#139)
renier Oct 18, 2021
031fc25
Add support to view program update date (#160)
rathishcholarajan Oct 18, 2021
1561a9b
Upload runtime program using 'data' field (#157)
rathishcholarajan Oct 19, 2021
b656ece
Read programs from "programs" array in response (#161)
rathishcholarajan Oct 19, 2021
8fb3669
Pass program as base64 string to update (#168)
rathishcholarajan Oct 21, 2021
74472c5
Accept JSON schema as program metadata (#158)
rathishcholarajan Oct 25, 2021
ee76158
Pass program params as object (#171)
rathishcholarajan Oct 27, 2021
da52271
Fix integration tests
rathishcholarajan Oct 27, 2021
f3033b8
Use count to reduce one last extra call to API (#172)
rathishcholarajan Oct 28, 2021
aea236b
Allow updating runtime metadata in place (#188)
jyu00 Oct 29, 2021
e71b402
Merge branch 'runtime-release-q4' of https://github.com/Qiskit-Partne…
kt474 Nov 2, 2021
f72a108
wip program name query
kt474 Nov 2, 2021
4102480
Allow filtering runtime jobs by program ID (#193)
rathishcholarajan Nov 4, 2021
8e8bcb3
Allow runtime program authors to retrieve program data (#174)
kt474 Nov 4, 2021
9dbbeb6
Merge branch 'runtime-release-q4' into program-name-query
kt474 Nov 4, 2021
90484cc
add test case, refactor logic
kt474 Nov 4, 2021
07f0d53
Update cache after updating program (#196)
rathishcholarajan Nov 5, 2021
304387c
Merge branch 'runtime-release-q4' into program-name-query
rathishcholarajan Nov 5, 2021
91e4ba8
add integration test
kt474 Nov 5, 2021
b458efc
update doc strings
kt474 Nov 5, 2021
4b48ec0
Update releasenotes/notes/query-program-name-823e8e7cfef44f50.yaml
kt474 Nov 5, 2021
87a5429
Update test/ibm/runtime/test_runtime.py
kt474 Nov 5, 2021
1d6e8ff
Update test/ibm/runtime/test_runtime.py
kt474 Nov 5, 2021
005a5d4
Update test/ibm/runtime/test_runtime_integration.py
kt474 Nov 5, 2021
15655ec
Update test/ibm/runtime/test_runtime_integration.py
kt474 Nov 5, 2021
35a9879
Update test/ibm/runtime/test_runtime_integration.py
kt474 Nov 5, 2021
8b01221
Update test/ibm/runtime/test_runtime.py
kt474 Nov 5, 2021
8133076
Allow filtering runtime jobs by provider (#197)
kt474 Nov 8, 2021
bbcf7b5
Merge branch 'runtime-release-q4' into program-name-query
rathishcholarajan Nov 8, 2021
7f474e9
Update qiskit_ibm/api/rest/runtime.py
rathishcholarajan Nov 8, 2021
4522d9b
Support pagination for retrieving runtime programs (#170)
kt474 Nov 8, 2021
b40df0f
Merge branch 'runtime-release-q4' into program-name-query
kt474 Nov 8, 2021
d35b56f
update program name
kt474 Nov 8, 2021
a960d8e
Merge branch 'main' into program-name-query
kt474 Nov 10, 2021
caa749a
Merge branch 'main' into program-name-query
kt474 Nov 12, 2021
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
6 changes: 3 additions & 3 deletions qiskit_ibm/api/clients/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ def __init__(
**credentials.connection_parameters())
self.api = Runtime(self._session)

def list_programs(self, limit: int = None, skip: int = None) -> Dict[str, Any]:
def list_programs(self, name: str = "", limit: int = None, skip: int = None) -> Dict[str, Any]:
"""Return a list of runtime programs.

Args:
limit: The number of programs to return.
skip: The number of programs to skip.

name: Name of the program.
Returns:
A list of runtime programs.
"""
Comment thread
kt474 marked this conversation as resolved.
return self.api.list_programs(limit, skip)
return self.api.list_programs(name, limit, skip)

def program_create(
self,
Expand Down
8 changes: 5 additions & 3 deletions qiskit_ibm/api/rest/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ def program_job(self, job_id: str) -> 'ProgramJob':
"""
return ProgramJob(self.session, job_id)

def list_programs(self, limit: int = None, skip: int = None) -> Dict[str, Any]:
def list_programs(self, name: str = "", limit: int = None, skip: int = None) -> Dict[str, Any]:
"""Return a list of runtime programs.

Args:
limit: The number of programs to return.
skip: The number of programs to skip.

name: Name of the program.
Returns:
A list of runtime programs.
"""
Comment thread
kt474 marked this conversation as resolved.
url = self.get_url('programs')
payload: Dict[str, int] = {}
payload: Dict[str, Union[int, str]] = {}
Comment thread
rathishcholarajan marked this conversation as resolved.
if name:
payload['name'] = name
if limit:
payload['limit'] = limit
if skip:
Expand Down
19 changes: 15 additions & 4 deletions qiskit_ibm/runtime/ibm_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@ def __init__(self, provider: 'ibm_provider.IBMProvider') -> None:
self._programs = {} # type: Dict

def pprint_programs(self, refresh: bool = False, detailed: bool = False,
limit: int = 20, skip: int = 0) -> None:
name: Optional[str] = "", limit: int = 20, skip: int = 0) -> None:
"""Pretty print information about available runtime programs.

Args:
refresh: If ``True``, re-query the server for the programs. Otherwise
return the cached value.
detailed: If ``True`` print all details about available runtime programs.
name: Only retrieve programs with the exact program name given.
limit: The number of programs returned at a time. Default and maximum
value of 20.
skip: The number of programs to skip.
"""
programs = self.programs(refresh, limit, skip)
programs = self.programs(refresh, name, limit, skip)
for prog in programs:
print("="*50)
if detailed:
Expand All @@ -129,7 +130,7 @@ def pprint_programs(self, refresh: bool = False, detailed: bool = False,
print(f" Name: {prog.name}")
print(f" Description: {prog.description}")

def programs(self, refresh: bool = False,
def programs(self, refresh: bool = False, name: Optional[str] = "",
limit: int = 20, skip: int = 0) -> List[RuntimeProgram]:
"""Return available runtime programs.

Expand All @@ -138,6 +139,7 @@ def programs(self, refresh: bool = False,
Args:
refresh: If ``True``, re-query the server for the programs. Otherwise
return the cached value.
name: Only retrieve programs with the exact program name given.
limit: The number of programs returned at a time. ``None`` means no limit.
skip: The number of programs to skip.

Expand All @@ -146,12 +148,21 @@ def programs(self, refresh: bool = False,
"""
if skip is None:
skip = 0
if name:
matched_programs = []
for prog in list(self._programs.values())[skip:limit+skip]:
if prog.name == name:
matched_programs.append(prog)
if matched_programs:
return matched_programs
refresh = True
if not self._programs or refresh:
self._programs = {}
current_page_limit = 20
offset = 0
while True:
response = self._api_client.list_programs(limit=current_page_limit, skip=offset)
response = self._api_client.list_programs(name=name, limit=current_page_limit,
skip=offset)
program_page = response.get("programs", [])
# count is the total number of programs that would be returned if
# there was no limit or skip
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/query-program-name-823e8e7cfef44f50.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
upgrade:
- |
The ``name`` parameter has been added to
:meth:`qiskit_ibm.runtime.IBMRuntimeService.programs` and
:meth:`qiskit_ibm.runtime.IBMRuntimeService.pprint_programs`
which can be used to filter by a specific program name. The
``name`` given must be an exact match with an actual program name.
9 changes: 6 additions & 3 deletions test/ibm/runtime/fake_runtime_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,15 @@ def set_final_status(self, final_status):
"""Set job status to passed in final status instantly."""
self._final_status = final_status

def list_programs(self, limit, skip):
def list_programs(self, name, limit, skip):
"""List all programs."""
programs = []
for prog in self._programs.values():
programs.append(prog.to_dict())
return {"programs": programs[skip:limit+skip], "count": len(self._programs)}
if not name:
programs.append(prog.to_dict())
if name == prog.to_dict()['name']:
programs.append(prog.to_dict())
return {"programs": programs[skip:limit+skip], "count": len(programs)}

def program_create(self, program_data, name, description, max_execution_time,
spec=None, is_public=False):
Expand Down
10 changes: 10 additions & 0 deletions test/ibm/runtime/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ def test_list_programs(self):
all_ids = [prog.program_id for prog in programs]
self.assertIn(program_id, all_ids)

def test_filter_programs_with_program_name(self):
"""Test filter programs with the program name"""
program_id = self._upload_program(name="qiskit-test-sample")
programs = self.runtime.programs(name="qiskit-test-sample")
all_ids = [prog.program_id for prog in programs]
self.assertIn(program_id, all_ids)
programs = self.runtime.programs(name="qiskit-test")
all_ids = [prog.program_id for prog in programs]
self.assertNotIn(program_id, all_ids)

def test_list_programs_with_limit_skip(self):
"""Test listing programs with limit and skip."""
program_1 = self._upload_program()
Expand Down
10 changes: 10 additions & 0 deletions test/ibm/runtime/test_runtime_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ def test_list_programs(self):
found = True
self.assertTrue(found, f"Program {self.program_id} not found!")

def test_filter_programs_with_program_name(self):
"""Test filter programs with program name."""
program_id = self._upload_program(name="qiskit-test-sample")
programs = self.provider.runtime.programs(name="qiskit-test-sample")
all_ids = [prog.program_id for prog in programs]
self.assertIn(program_id, all_ids)
programs = self.provider.runtime.programs(name="qiskit-test")
all_ids = [prog.program_id for prog in programs]
self.assertNotIn(program_id, all_ids)

def test_list_programs_with_limit_skip(self):
"""Test listing programs with limit and skip."""
self._upload_program()
Expand Down