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 Type System part of spec wrt "types redux" #401

Merged
merged 4 commits into from
Aug 14, 2023
Merged

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Aug 11, 2023

Not done function polymorphism, and have not added array (or indeed prelude) to standard library. @ss2165 were you in the process of doing that?

@acl-cqc acl-cqc requested a review from cqc-alec August 11, 2023 15:24


### Resources
<!--### Resources
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 seemed to duplicate what was written earlier in the "Extension Implementation" section....shall I remove altogether?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I think so.

```
<!-- Graph(TypeParams, #, #, Resources) -- polymorphic, so move TypeParams section here
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not going here yet, until #285 fully resolved; if we do do this, we probably want to restructure so that Type System comes before Extension

The type system will resemble the tierkreis type system, but with some
extensions. Namely, the things the tierkreis type system is missing are:
There are three classes of type, distinguished by the operations possible on (runtime) values of that type. (These loosely correspond to Tierkreis' notion of "constraints".)
- For the broadest class ("Any" type), the only operation supported is the identity operation (aka no-op, or `lift` - see [Resource Tracking](#resource-tracking) below). Specifically, these values cannot necessarily be copied or discarded, hence the linearity requirement that outports of these types must have exactly one edge. (All incoming ports must have exactly one edge connected to them.)
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
- For the broadest class ("Any" type), the only operation supported is the identity operation (aka no-op, or `lift` - see [Resource Tracking](#resource-tracking) below). Specifically, these values cannot necessarily be copied or discarded, hence the linearity requirement that outports of these types must have exactly one edge. (All incoming ports must have exactly one edge connected to them.)
- For the broadest class ("Any" type), the only operation supported is the identity operation (aka no-op, or `lift` - see [Resource Tracking](#resource-tracking) below). Specifically, these values cannot necessarily be copied or discarded, hence the requirement that outports of linear types must have exactly one edge. (All incoming ports must have exactly one edge connected to them.)


**Row Types** The `#` is a *row type* which consists of zero or more types. Types in the row can optionally be given names in metadata i.e. this does not affect behaviour of the HUGR.

The core does not define any types** , only type constructors (that must be instantiated into types by providing some collection of types as arguments). These are given in the following grammar:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should try and avoid footnotes; can you work the footnote text into the paragraph?

Graphs are annotated with the resources that they need to run and, when
run, their outputs are annotated with those resources. Keeping track of
the resource requirements of graphs allows plugin designers and backends
** the empty tuple type, aka `unit`, with exactly one instance (so 0 bits of data); the empty sum, with no instances; and the empty Graph (void -> void), are the only "leaf" types here.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose that other graph signatures such as Sum((), ()) --> Sum((), ()) are also possible leaf nodes (not just void -> void)? Maybe even non-empty ones, such as "rotate the Tuple"? (I mean they can be defined without reference to any extension, but perhaps you mean something different...)

the resource requirements of graphs allows plugin designers and backends
** the empty tuple type, aka `unit`, with exactly one instance (so 0 bits of data); the empty sum, with no instances; and the empty Graph (void -> void), are the only "leaf" types here.

Graphs are Copyable, but not Equatable (as they represent functions: it is undecidable whether two functions produce the same result for all possible inputs, or similarly whether one computation graphs can be rewritten into another by semantic-preserving rewrites).
Copy link
Collaborator

Choose a reason for hiding this comment

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

"one computation graphs"?


### Resource Tracking

The type of `Graph` includes a set of resources (that is, [Extensions](#extension-implementation)) which are required to execute the graph. Every node in the HUGR is annotated with the set of resources required to produce its inputs, and the set of resources required to execute the node; the union of these two must match the set of resources on each successor node.
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
The type of `Graph` includes a set of resources (that is, [Extensions](#extension-implementation)) which are required to execute the graph. Every node in the HUGR is annotated with the set of resources required to produce its inputs, and the set of resources required to execute the node; the union of these two must match the set of resources on each successor node.
The type of `Graph` includes a set of resources (that is, [Extensions](#extension-implementation)) which are required to execute the graph. Every node in the HUGR is annotated with the set of resources required to produce its inputs, and the set of resources required to execute the node; the union of these two must be a superset of the set of resources on each successor node.

?
I'm thinking e.g. of a quantum node whose outputs are just some bits for classical post-processing (not requiring the quantum resource).

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 you'd demarcate the part you want to run into the quantum computer in a separate graph, and then run in via a (Tierkreis, so probably higher-order) run_remote node (i.e. that takes a Graph[Quantum](...) and yet itself only needs Tierkreis resources). We don't want resource requirements to be dropped/forgotten or we'd conclude the containing graph could run anywhere when it actually needs quantum hardware...

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, makes sense.



### Resources
<!--### Resources
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I think so.

it so, we will have an operations called **lift** and **liftGraph**
which can add a resource constraints to values.
To allow resource annotations on nodes to be made equal, we will have operations
**lift** and **liftGraph** which can add a resource constraints to values.
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
**lift** and **liftGraph** which can add a resource constraints to values.
**lift** and **liftGraph** which can add resource constraints to values.

@acl-cqc acl-cqc requested a review from cqc-alec August 11, 2023 16:25
@acl-cqc
Copy link
Contributor Author

acl-cqc commented Aug 11, 2023

Thanks Alec, many good points there. Feel free to take over, or merge when ready, @ss2165 and @aborgna-q too.

Resources ::= (Resource)* -- a set, not a list

Type ::= Tuple(#) -- fixed-arity, heterogenous components
| Sum(#) -- disjoint union of other types, ??tagged by unsigned int??
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 tagged by unsigned int was in here (a bit further down) before, and relates to the implementation and/or the tag operation, defined elsewhere. So this might want rewording. can be tagged by USize perhaps? or remove it, either with an implementation note elsewhere, or in whatever part of the prelude that defines the tag op ?

@cqc-alec cqc-alec added this pull request to the merge queue Aug 14, 2023
Merged via the queue into main with commit bf51c93 Aug 14, 2023
5 checks passed
@cqc-alec cqc-alec deleted the spec/types-redux branch August 14, 2023 08:04
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