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

Sketch out resources + extension mechanism, update CustomType #186

Merged
merged 63 commits into from
Jul 7, 2023

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jun 20, 2023

Lots of gaps here, and many things are not as neat as they might be eventually. But various OpDef and CustomOp classes are removed and/or combined, as per the spec. Also update the spec re. "Int".

I haven't implemented the loading code here, beyond that CustomOp's should serialize only the names of the OpDefs to which they refer (the loading code is TODO atm 'coz I haven't figured out the necessary serde). A function resolve_extension_ops can be called after deserializing (which produces just names) to find the actual OpDefs from a "registry" (a Map<String, Resource>, see #188)

We have now ruled out Ops parameterized by float(s); these will have to be passed in as static inputs.

Other questions/follow-up issues...

  • ResourceSet in Signature #189 (ResourceSet in Signature) remains unresolved, but can become an issue after this is merged, as something needs doing.
  • What are CustomTypes? #198 Parameterization of CustomTypes now handled here too, but (following also Is "Map" core or extension? What about Hashable & constraints? #221) there is jira TKET-3305 it refactor the type hierarchy.
  • Make new issue to move many operations out into their own resource (and add arithmetic)
  • Make new issue for registering Extensions / building the "registry". This needs to combine both loading YAML and also binary code (perhaps through dynamic loading) whereby extensions "self-register" (the spec says). The current "API" expects any binary compute_signature functions to have registered themselves before the YAML is loaded, whereas try_lower implementations could be added after loading YAML - this is a bit inconsistent, but follows from that every OpDef much have some way of computing Signatures, but may not provide any way of lowering.

src/resource.rs Outdated
pub resource_reqs: ResourceSet,
name: ResourceId,
// Set of resource dependencies required by this resource.
// TODO I haven't seen where these are required yet. If they are,
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the case where someone wants to define a resource in terms of types provided by another resource?

This doesn't necessarily require any knowledge of the implementation of the other resource - one could have an operation on types from another resource which is defined in terms of that resources operations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, indeed. I'm not quite sure what this should look like. It may fall under the heading of "namespacing", which is one of the unresolved issues in this PR. Good point, thanks :)

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've kept this in as an "upper bound" of all signatures that might be returned by compute_signature functions, which can't be determined by inspection.

However, I'm not entirely sure how it's used. If I declare an operation that takes a MyType<Int,6> without the resource declaring the type MyType being around (even in YAML!), seems like I don't lose anything - it's just an early-warning that I the end-user-programmer may not be able to get very far. But the HUGR is still capable of passing such values around as serialized blobs, if I have operations that both create and consume those values. Really, the only information added by the "declaration" of the custom type is validity checking of the type arguments?!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's the way I was thinking about it - that we'd be checking the validity of type arguments specified in operations

src/types/simple.rs Outdated Show resolved Hide resolved
@@ -31,8 +32,6 @@ pub enum EdgeKind {
Const(ClassicType),
/// Explicitly enforce an ordering between nodes in a DDG.
StateOrder,
/// An edge specifying a resource set.
Resource(ResourceSet),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

src/types/type_arg.rs Outdated Show resolved Hide resolved
src/ops/custom.rs Outdated Show resolved Hide resolved
@acl-cqc
Copy link
Contributor Author

acl-cqc commented Jul 4, 2023

This has been sitting here awhile and @ss2165 is now away, but perhaps if @croyzor could review for direction and @aborgna-q for rustiness then that would be reasonable grounds to merge?

@aborgna-q aborgna-q requested review from aborgna-q and croyzor July 5, 2023 08:57
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

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

👍

Most of these comments reduce to "please add more docs". There's a load of new {Module, External, Custom} {Type, Op, Def, Param, Arg} that may confuse a first time reader. Perhaps a short resume of the structure as a top-level comment in resource would help...

src/resource.rs Outdated Show resolved Hide resolved
src/resource.rs Outdated Show resolved Hide resolved
src/resource.rs Show resolved Hide resolved
src/resource.rs Outdated
Comment on lines 98 to 99
#[serde(skip)]
None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this skipped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again just thinking of the YAML - if there's not a fixed hugr, which can be given (e.g. filename) in the YAML file, then either the Resource has binary code that self-registers the custom function, or there is no possibility of lowering.

src/resource.rs Show resolved Hide resolved
src/ops/custom.rs Outdated Show resolved Hide resolved
src/ops/custom.rs Show resolved Hide resolved
src/ops.rs Outdated Show resolved Hide resolved
src/types/type_param.rs Outdated Show resolved Hide resolved
src/types/type_param.rs Outdated Show resolved Hide resolved
@acl-cqc acl-cqc merged commit 8e38148 into main Jul 7, 2023
@acl-cqc acl-cqc deleted the sketch/resources branch July 7, 2023 12:01
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.

5 participants