Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Show default hgp in active_account #349

Merged
merged 11 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions qiskit_ibm_provider/ibm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ def active_account(self) -> Optional[Dict[str, str]]:
Returns:
A dictionary with information about the account currently in the session.
"""
if not self._account.instance:
hgp = self._get_hgp()
self._account.instance = f"{hgp._hub}/{hgp._group}/{hgp._project}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._account.instance is never updated, even after a job is run - if a user wants to see the default hgp by calling active_account() we can use _get_hgp() which returns the default hgp

This doesn't seem like the cleanest solution but I couldn't find a better way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First hgp in the list of hgps will always be the one that is selected by default.
We need to always return this no matter what is already in self._account.
So something like below should work, please test it:

hgps = self._get_hgps()
active_account_dict = self._account.to_saved_format()
active_account_dict.update({ "instance": hgps[0].name })
return active_account_dict

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works as intended

return self._account.to_saved_format()

@staticmethod
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/show-default-hgp-4047cf5c5da04c09.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
upgrade:
- |
When instantiating :class:`~qiskit_ibm_provider.IBMProvider` and the h/g/p
is not specified, users can see the auto-selected h/g/p
with :meth:`~qiskit_ibm_provider.IBMProvider.active_account`