-
Notifications
You must be signed in to change notification settings - Fork 212
Query programs by name #14
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
07460d7
query programs by name
kt474 85be645
refactor cache logic
kt474 7413496
Merge branch 'main' into query-program-name
rathishcholarajan 3c282e1
Merge branch 'main' into query-program-name
rathishcholarajan d2cc513
Merge branch 'main' into query-program-name
kt474 f733ee0
fix lint
kt474 b26f544
update tests
kt474 17d1f47
Merge branch 'main' into query-program-name
rathishcholarajan 610e8a0
refactor programs cache
kt474 ad53714
fix lint
kt474 7be7a77
Merge branch 'main' into query-program-name
kt474 bf87cae
unrelated lint fix
kt474 5a1d7c2
Merge branch 'query-program-name' of https://github.com/Qiskit/qiskit…
kt474 b9933c9
Merge branch 'main' into query-program-name
rathishcholarajan 830ddfc
Merge branch 'main' into query-program-name
rathishcholarajan ebacbee
update cache logic
kt474 d48e892
Merge branch 'main' into query-program-name
rathishcholarajan 0ab06e6
update cache logic
kt474 c188a14
Merge branch 'main' into query-program-name
kt474 8d287d9
Update qiskit_ibm_runtime/ibm_runtime_service.py
kt474 861cf00
update retrieve programs method
kt474 af309c7
refactor logic
kt474 ea04aa8
Merge branch 'main' into query-program-name
kt474 fca5a98
Merge branch 'main' into query-program-name
kt474 0bc0bca
Merge branch 'main' into query-program-name
kt474 6671b7d
add tests back in
kt474 851caa2
Merge branch 'main' into query-program-name
kt474 d33595e
Merge branch 'main' into query-program-name
kt474 5e827fe
fix list programs test
kt474 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -800,6 +800,7 @@ def pprint_programs( | |
| self, | ||
| refresh: bool = False, | ||
| detailed: bool = False, | ||
| name: Optional[str] = "", | ||
| limit: int = 20, | ||
| skip: int = 0, | ||
| ) -> None: | ||
|
|
@@ -809,11 +810,12 @@ def pprint_programs( | |
| 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: | ||
|
|
@@ -826,7 +828,11 @@ def pprint_programs( | |
| print(f" Description: {prog.description}") | ||
|
|
||
| def programs( | ||
| self, refresh: bool = False, limit: int = 20, skip: int = 0 | ||
| self, | ||
| refresh: bool = False, | ||
| name: Optional[str] = "", | ||
| limit: int = 20, | ||
| skip: int = 0, | ||
| ) -> List[RuntimeProgram]: | ||
| """Return available runtime programs. | ||
|
|
||
|
|
@@ -835,6 +841,7 @@ def programs( | |
| 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. | ||
|
|
||
|
|
@@ -843,13 +850,19 @@ def programs( | |
| """ | ||
| if skip is None: | ||
| skip = 0 | ||
| if name: | ||
| for program in list(self._programs.values())[skip : limit + skip]: | ||
| if program.name == name: | ||
| self._programs[program.program_id] = program | ||
| else: | ||
| del self._programs[program.program_id] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All this local filtering should happen only if refresh is not set to True and self._programs is non empty. We shouldn’t delete programs from self._programs since it’s usually lot of info that’ll have to be refetched from sever. |
||
| 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 | ||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this before limit and skip, just to maintain parameter order?