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

Add models for new server I/O #1123

Merged
merged 5 commits into from
Dec 13, 2024
Merged

Add models for new server I/O #1123

merged 5 commits into from
Dec 13, 2024

Conversation

cdbf1
Copy link
Contributor

@cdbf1 cdbf1 commented Dec 11, 2024

Adds data models that will be needed for v0.3.0 of the superstaq server

vtomole
vtomole previously approved these changes Dec 11, 2024
Copy link
Member

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -0,0 +1,291 @@
"""Data models used when communicating with the superstaq server."""

# pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

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

This will need to be removed once client-side starts using these models.

Copy link
Member

@vtomole vtomole Dec 11, 2024

Choose a reason for hiding this comment

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

Remind me why these aren't server side for now? https://github.com/Infleqtion/client-superstaq/pull/1106/files doesn't use these models either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/Infleqtion/client-superstaq/pull/1106/files does use the models when handling server responses (it validates that the response is in the expected format). See for instance gss.client._SuperstaqClient_v0_3_0.create_job()`

I'm adding them to client side now so that I can import them server side.

Copy link
Member

@vtomole vtomole Dec 11, 2024

Choose a reason for hiding this comment

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

I see. Why is coverage being ignore for _model.py in that PR then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because for now there are no tests that use any of these models (because they are just data structures)

@vtomole vtomole dismissed their stale review December 11, 2024 17:13

One more question

Copy link
Member

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

LGTM

target: str
circuits: str
circuit_type: CircuitType
compiled_circuits: str | None = pydantic.Field(default=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this not work?

Suggested change
compiled_circuits: str | None = pydantic.Field(default=None)
compiled_circuits: str | None = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is needed server-side to play nicely with fastapi.

final_logical_to_physicals: list[str | None]


class NewJob(DefaultPydanticModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

is this intended for jobs sent from the user to superstaq? if so why does it require both compiled and uncompiled circuits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intended to replace the "verbatim=True" option. On the server, if the compiled_circuits is provided then the server skips the compiling step

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok. imo it would be nicer to just include the verbatim flag and a single circuits field, unless there is some case in which we'd need both

]


class DefaultPydanticModel(pydantic.BaseModel, use_enum_values=True, extra="forbid"):
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to rethink extra="forbid" - it'd be nice to add new fields server-side and not have it break existing clients

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My feeling is that for ease of use, self-documentation and secure coding, any I/O models should be fully enumerated. I agree it's a little less flexible though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From dev meeting: Set extra=ignore for now.

dry_run: bool = pydantic.Field(default=False)
sim_method: SimMethod | None = pydantic.Field(default=None, validate_default=True)
priority: int = pydantic.Field(default=0)
options_dict: dict[str, Any] = pydantic.Field(default={})
Copy link
Contributor

Choose a reason for hiding this comment

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

this might be a good time to think about retiring the options dict. it was originally mostly intended as a stopgap so that we could make things flexible as we refined our interfaces, now that we're defining these models we should maybe to start breaking things into their own fields/models (and maybe just use for extra="allow" for experimental/wip/non-publicized fields?)

(not sure how we want to organize things though - we could put everything in the top level model, or keep a single options field w/ a model for possible arguments, or start separating e.g. compilation options/user credentials/simulation parameters into their own models...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is top of my to-do list once the initial server is up and running. As per my comment above about extra="forbid", the client side models should be fully enumerated.

I imagine that the best approach will be to have different models for different types of jobs etc., set up in some hierarchical way this will ensure that everything gets validated automatically by the server. This is part of the job refactor to-do list

For now I suggest we keep the options_dict field to maintain compatibility with existing Superstaq method.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep totally agree, just wanted to flag it in case it had any implications for how we go about organizing things

general-superstaq/general_superstaq/_models.py Outdated Show resolved Hide resolved
"""Target is simulator"""


class GetTargetsFilterModel(DefaultPydanticModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

could this and the above model be combined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although the field names are the same they represent different things so I feel they should remain as separate models. Also on server side some logic is added to the to the FilterModel

Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com>
]


class DefaultPydanticModel(pydantic.BaseModel, use_enum_values=True, extra="forbid"):
Copy link
Contributor

Choose a reason for hiding this comment

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

two other options that are nice imo: validate_assignment=True and validate_default=True

@cdbf1 cdbf1 merged commit 2ed5424 into main Dec 13, 2024
21 checks passed
@cdbf1 cdbf1 deleted the feature/v0.3.0_io_models branch December 13, 2024 10:28
cdbf1 added a commit that referenced this pull request Dec 13, 2024
Adds data models that will be needed for v0.3.0 of the superstaq server

---------

Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com>
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.

3 participants