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

Update docstrings in credential_storage.py #516

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

yao-cqc
Copy link
Contributor

@yao-cqc yao-cqc commented Oct 17, 2024

Description

Please summarise the changes.

Related issues

Resolves #483

Checklist

  • I have performed a self-review of my code.
  • I have commented hard-to-understand parts of my code.
  • I have made corresponding changes to the public API documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the changelog with any user-facing changes.

@yao-cqc yao-cqc marked this pull request as ready for review October 17, 2024 15:47
@yao-cqc yao-cqc requested a review from cqc-alec October 17, 2024 15:48
Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

I think what is missing here is an explanation of what the tokens are and how to obtain them (given a username and password) in the first place.

"""Store username and tokens in the default pytket configuration file.

This storage option allows authentication status to persist beyond the current
session, and reducing the need to re-enter credentials when constructing new
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
session, and reducing the need to re-enter credentials when constructing new
session, reducing the need to re-enter credentials when constructing new

@yao-cqc
Copy link
Contributor Author

yao-cqc commented Oct 21, 2024

I think what is missing here is an explanation of what the tokens are and how to obtain them (given a username and password) in the first place.

I've added a brief explanation to the base class. Let me know if you think it should be more detailed.

@yao-cqc yao-cqc requested a review from cqc-alec October 21, 2024 12:17
@cqc-alec
Copy link
Collaborator

cqc-alec commented Oct 21, 2024

Thanks, I do think it needs more detail. Could you walk through the process of setting up the tokens? I still can't get it to work :-(

I've tried doing this:

from pytket.extensions.quantinuum import QuantinuumAPI
from pytket.extensions.quantinuum.backends.credential_storage import (
    QuantinuumConfigCredentialStorage,
)

api = QuantinuumAPI()
id_token = api.login()
storage = QuantinuumConfigCredentialStorage()
storage.save_id_token(id_token)

followed by

from pytket.extensions.quantinuum import QuantinuumBackend

print(QuantinuumBackend.available_devices())

but I am still prompted for my password at the last stage. Obviously I'm doing something wrong here...

@yao-cqc
Copy link
Contributor Author

yao-cqc commented Oct 21, 2024

Thanks, I do think it needs more detail. Could you walk through the process of setting up the tokens? I still can't get it to work :-(

I've tried doing this:

from pytket.extensions.quantinuum import QuantinuumAPI
from pytket.extensions.quantinuum.backends.credential_storage import (
    QuantinuumConfigCredentialStorage,
)

api = QuantinuumAPI()
id_token = api.login()
storage = QuantinuumConfigCredentialStorage()
storage.save_id_token(id_token)

followed by

from pytket.extensions.quantinuum import QuantinuumBackend

print(QuantinuumBackend.available_devices())

but I am still prompted for my password at the last stage. Obviously I'm doing something wrong here...

I see...

QuantinuumBackend needs a QuantinuumAPI which needs a CredentialStorage.

QuantinuumBackend uses the DEFAULT_API_HANDLER by default, which has the MemoryCredentialStorage. Class methods of QuantinuumBackend also use the DEFAULT_API_HANDLER by default.

QuantinuumAPI will always save the username and tokens to its CredentialStorage after a successive login. Manually saving the tokens is usually not needed.

This should work:

from pytket.extensions.quantinuum import QuantinuumAPI
from pytket.extensions.quantinuum.backends.credential_storage import (
    QuantinuumConfigCredentialStorage,
)
storage = QuantinuumConfigCredentialStorage()
api = QuantinuumAPI(token_store=storage)
api.login()

followed by

from pytket.extensions.quantinuum import QuantinuumBackend
storage2 = QuantinuumConfigCredentialStorage()
api2 = QuantinuumAPI(token_store=storage2)
print(QuantinuumBackend.available_devices(api_handler=api2))

@cqc-alec
Copy link
Collaborator

This should work:

Thanks for the explanation, clearly I was barking up the wrong tree. I don't think this is really explained anywhere in the docs -- maybe the section "Persistent Authentication Token Storage" in docs/index.rst could be expanded a little with the above workflow?

Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

Thanks!

@yao-cqc yao-cqc merged commit f76ca6c into main Oct 22, 2024
13 checks passed
@yao-cqc yao-cqc deleted the docs/docstrings-for-credential-storages branch October 22, 2024 08:50
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 doc strings to constructors in credential_storage.py
2 participants