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

Allow IBMServerlessProvider users to save their credentials to disk #1048

Merged
merged 15 commits into from
Oct 20, 2023

Conversation

caleb-johnson
Copy link
Collaborator

Fixes #1042

@caleb-johnson caleb-johnson marked this pull request as ready for review October 20, 2023 17:18
@caleb-johnson caleb-johnson changed the title Save account Allow IBMServerlessProvider users to save their credentials to disk Oct 20, 2023
Copy link
Member

@IceKhan13 IceKhan13 left a comment

Choose a reason for hiding this comment

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

Should we use what QiskitRuntimeService already have? 🤔

https://github.com/Qiskit/qiskit-ibm-runtime/blob/dc3b1d0d4a8f9426726e5dd9cc74d6373fd68709/qiskit_ibm_runtime/qiskit_runtime_service.py#L683

then implementation would be something like this:

class IBMServerlessProvider(...):
    def __init__(self, token: Optional[str] = None, name: Optional[str] = None):
         if token is None:
              self.token = QiskitRuntimeService(name=name).token
         else:
              self.token = token

    @classmethod
    def save_account(cls, token: Union[str, QiskitRuntimeService], overwrite: bool = True):
           if isinstance(token, QiskitRuntimeService):
               QiskitRuntimeService.save_acoount(**token.get_account())
           else:
               # token string
               QiskitRuntimeService.save_account(token=token, channel=..., ...)

In that case it will be same file as runtime is using.

But in general I'm ok with any option :)

@caleb-johnson
Copy link
Collaborator Author

Should we use what QiskitRuntimeService already have? 🤔

https://github.com/Qiskit/qiskit-ibm-runtime/blob/dc3b1d0d4a8f9426726e5dd9cc74d6373fd68709/qiskit_ibm_runtime/qiskit_runtime_service.py#L683

then implementation would be something like this:

class IBMServerlessProvider(...):
    def __init__(self, token: Optional[str] = None, name: Optional[str] = None):
         if token is None:
              self.token = QiskitRuntimeService(name=name).token
         else:
              self.token = token

    @classmethod
    def save_account(cls, token: Union[str, QiskitRuntimeService], overwrite: bool = True):
           if isinstance(token, QiskitRuntimeService):
               QiskitRuntimeService.save_acoount(**token.get_account())
           else:
               # token string
               QiskitRuntimeService.save_account(token=token, channel=..., ...)

In that case it will be same file as runtime is using.

But in general I'm ok with any option :)

Yes, I think this is a better solution. Let me take a look..

Copy link
Member

@IceKhan13 IceKhan13 left a comment

Choose a reason for hiding this comment

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

Looks clean! :)

Feel free to merge after docstring update

@caleb-johnson caleb-johnson merged commit 4d97552 into Qiskit:main Oct 20, 2023
6 checks passed
@caleb-johnson caleb-johnson deleted the save-account branch October 20, 2023 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Provider.save_account method
2 participants