Skip to content

Nexus worker improvements, graphs and docs#207

Merged
mwpb merged 21 commits into
mainfrom
docs/nexus-worker
Sep 23, 2025
Merged

Nexus worker improvements, graphs and docs#207
mwpb merged 21 commits into
mainfrom
docs/nexus-worker

Conversation

@mwpb
Copy link
Copy Markdown
Collaborator

@mwpb mwpb commented Sep 22, 2025

EDIT: have set this to auto-merge even though I haven't written the docs part. It should be useful to have in for the pytket-worker branch as similar issue have arisen there.

  • Move stubs from example_workers to tierkreis core package. (Just use worker name.)
  • Create Nexus polling example that submits a circuit and polls for results. Include the graph in the core tierkreis library so others can easily access.
  • Work around UnionType problem by relying more on format_generic_type and de-emphasising format_ptype in codegen.
  • (Make the stubs tests output a file so that we can check it lints and that it hasn't unexpectedly changed its output.)
  • Add builtin sleep node for quick solution to rate limiting.
  • (Allow GraphBuilder in run_graph.)
  • Quick solution to coercing union types; revisit if performs badly with large unions.
  • Strip Annotation from types and just use underlying type. Required to deal with BackendConfig.
  • Re-work Nexus worker to more closely match the corresponding methods in qnexus.

@mwpb mwpb force-pushed the docs/nexus-worker branch from 7cfa175 to b08cf56 Compare September 22, 2025 14:25
@mwpb mwpb requested a review from philipp-seitz September 22, 2025 15:20
@mwpb mwpb marked this pull request as ready for review September 22, 2025 15:20
@mwpb mwpb enabled auto-merge (squash) September 22, 2025 15:21
cx q[20],q[21];
cx q[21],q[22];
barrier q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10],q[11],q[12],q[13],q[14],q[15],q[16],q[17],q[18],q[19],q[20],q[21],q[22];
measure q[0] -> meas[0];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think its possible to do measure q -> meas

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No doubt you have a better idea than me. I'm using this (from https://github.com/pnnl/QASMBench/tree/master/medium/ghz_state_n23).

OPENQASM 2.0;
include "qelib1.inc";
qreg q[23];
creg c[23];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we need this?

return g


def nexus_submit_and_poll(polling_interval: float = 30.0):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a specific reason this is not an additional input?

return backend_results


## DEPRECATED TASKS ##
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This made me think: should we add a way to forward other function decorators from tasks? e.g. if we used @deprecated() here

Copy link
Copy Markdown
Collaborator Author

@mwpb mwpb Sep 23, 2025

Choose a reason for hiding this comment

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

In short yes. I've created https://github.com/orgs/CQCL/projects/18/views/1?pane=issue&itemId=130214819. I remember trying@deprecated and running into a problem though I don't recall what it was.

if _is_union(annotation):
for t in get_args(annotation):
try:
return coerce_from_annotation(ser, t)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this is working correctly in combination with the basemodel. I constructed an example in this commit where the success of the test depends on whether you use the type hints test__(val: A | B) or test__(val B | A).
I must admit, though, that this is a very contrived example, so if you think this is not a concern, I'm happy to merge the version as is

Copy link
Copy Markdown
Collaborator Author

@mwpb mwpb Sep 23, 2025

Choose a reason for hiding this comment

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

Good thinking, this just does 'left to right' resolution because that is easiest. In future we could try to implement a 'smart mode' similar to https://docs.pydantic.dev/latest/concepts/unions/ though this is still very much at the level of heuristic. Note that at this point we only have the JSON so to use a discriminated union we would have to change our serialisation also, which might put us in hot water when interfacing with workers that don't use our library. Of course the user can always add an extra field to create a discriminator.

@mwpb mwpb merged commit 28df43b into main Sep 23, 2025
6 checks passed
@mwpb mwpb deleted the docs/nexus-worker branch September 23, 2025 08:20
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.

2 participants