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

/get targets refactor #788

Merged
merged 57 commits into from
Nov 10, 2023
Merged

/get targets refactor #788

merged 57 commits into from
Nov 10, 2023

Conversation

bharat-thotakura
Copy link
Contributor

@bharat-thotakura bharat-thotakura commented Sep 23, 2023

"""A class to store data returned from a /get_targets request."""

target: str
properties: Dict[str, bool]
Copy link
Contributor

Choose a reason for hiding this comment

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

can we flatten this so instead of properties we have e.g. TargetInfo.available?

this also might be a really place to start using pydantic - instead of a dataclass, we could use use

class TargetInfo(pydantic.BaseModel):
    """A class to store data returned from a /get_targets request."""

    target: str
    available: bool = False
    ...

so that we could instantiate it with e.g.

TargetInfo(target=target, **properties)

(and it will automatically handle defaults/validation/etc for us)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like the idea of using pydantic, will update. As for the decision to use properties, it was because I thought that if more fields were added, we wouldn't need to create a new variable for each one in the original dataclass. I was thinking that the user wouldn't use the TargetInfo dataclass directly, but instead would be able to do get_targets(available=True) or any keyword supported in properties

available: bool = False
retired: bool = False

def __repr__(self) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

worth confirming, but i think pydantic.BaseModel automatically defines this and __eq__ so we don't need to

Copy link
Contributor Author

@bharat-thotakura bharat-thotakura Oct 5, 2023

Choose a reason for hiding this comment

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

Yeah it does define __repr__ but its formatting looks like this (i.e., without the newlines from the dedicated one which I guess takes up more space):

[TargetInfo(target='aws_dm1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),
 TargetInfo(target='aws_sv1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),
 TargetInfo(target='aws_tn1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),
...

It does also handle the __eq__, I just had an assertion error in one of my earlier tests that was fixed by adding an __eq__ but that's not an issue anymore, so it's removed now.

general-superstaq/general_superstaq/superstaq_client.py Outdated Show resolved Hide resolved
general-superstaq/general_superstaq/superstaq_client.py Outdated Show resolved Hide resolved
general-superstaq/general_superstaq/superstaq_client.py Outdated Show resolved Hide resolved
general-superstaq/general_superstaq/typing.py Outdated Show resolved Hide resolved
@bharat-thotakura bharat-thotakura marked this pull request as draft October 6, 2023 19:03
bharat-thotakura and others added 5 commits October 26, 2023 14:10
use gss.TargetInfo

import fix

updated gss.testing import
Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com>
@bharat-thotakura bharat-thotakura marked this pull request as ready for review October 26, 2023 19:53
Copy link
Contributor

@richrines1 richrines1 left a comment

Choose a reason for hiding this comment

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

lgtm % deployment of server-side changes (and corresponding reversions here)!

bharat-thotakura added a commit that referenced this pull request Nov 9, 2023
Fixes Infleqtion/server-superstaq#2683. 

(`gss.testing.py` was added because it will be further used by
#788)
@bharat-thotakura bharat-thotakura merged commit b1eb2e2 into main Nov 10, 2023
16 checks passed
@bharat-thotakura bharat-thotakura deleted the get_targets_refactor branch November 10, 2023 04:05
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.

None yet

2 participants