-
Notifications
You must be signed in to change notification settings - Fork 7
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
Allow TypeArg for a row of types #787
Comments
Discussion from #804: [ @doug-q ]: I instead understand the value to be to allow operations with variadic inputs/outputs to be defined. The cost of not allowing these to be defined is that one is forced, by their absence, to instead work with tuples. The requisite UnpackTuple operations introduce barriers to parallelism. |
So the concern here is, if MakeTuple etc. need to be "special" (defined in core Hugr) because they can't be defined in an extension - who says we've got all the other operations that also need to be special? In particular, the core does not include such Tierkreis staples as
However, we can do arbitrary computation (using |
This is a good point. However we are free to add row variables at any time without breaking anything. We can change from builtin ops to prelude ops without breaking serialisation, although this would likely break rust users. If we do add row variables there is no strict obligation to remove the builtin ops. There is no urgency if we do not have a use case.
One can write a |
This is an interesting possibility! At the moment the "TierkreisGraph" protobuf closely matches the Rust structs internal to the interpreter (modulo things like types, perhaps), and one option is that this becomes the Hugr IR. I think that whatever input (or "source") format we use, is probably what error-mitigation protocols and other composable algorithm components are written in (i.e. is an interchange format), and that this format includes "partial" and "eval" at a similarly high level of abstraction as they are now. (Rather than much lower-level representation by mangling to FuncDefns etc.) However perhaps instead we translate from a high-level input format (that is not Hugr) to a lower-level Hugr format that is only internal to the runtime. (Indeed things like Tierkreis type inference might happen in this translation.) @ss2165 One possible downside is that this might lead to us wanting to do rewrites (as optimization) at both levels, which would seem like a shame compared to doing them only at the Hugr level. |
My view is that if I don't see now that they do need to be reasoned about as-is, but I wouldn't necessarily expect to :).
is 816 right here? My understanding is that we surely do need row vars for that(and that in any case it is nothing but a tidying up). In any case, I do agree we should delay a decision here until we understand Tierkreis. EDIT: I think you mean writing |
Yes, writing Lines 79 to 80 in 18ac277
|
I think this issue highlights a current tension in the design: HUGR is very machine friendly and hence can use fairly arcane expressions over the small-ish spec to express complicated things (e.g. the "compilation patterns" @doug-q refers to). However, Tierkreis is currently human writable and readable. If we instead say that guppy is going to take on the writing role, what about reading? For example, when viewing a tierkreis computation in progress in a nexus visualisation, does the compilation pattern for My hope is that adding these higher order operations with
to see what this wouldn't cover. |
So let's think about having say an Without #787, However, what we can do is - anywhere we'd have a row of types - we statically pass just the length to I think this "trick" gets us a reasonable distance, and applies to #816 also. Obviously all arities must be fixed statically, and this'll be the main restriction on what we can express. (Never mind that this is not the easiest interface!) |
This is a good point. I don't think readiblity should be a design goal of HUGR. I claim readability can and should be accomplished by labelling nodes with metadata, and tooling that uses that metadata to reconstruct a view that is useful to a user. Surely this is sufficient to cover |
I like this. Don't we also need bounds on each of these type variables though? The point of friction with row variables is that an op must have a fixed number of {in,out}ports, this idea seems to capture this sharply. One issue with row variables which I have not previously noted is that (I claim) we do not want to find ourselves in the position of needing the type system to inspect type rows (e.g. length, uncons). A static length helps here. |
* Add a RowVariable variant of Type(Enum) that stands for potentially multiple types, created via Type::new_row_var_use. * This can appear in a TypeRow, i.e. the TypeRow is then of variable length; and can be instantiated with a list of types (including row vars) or a single row variable * Validation enforces that RowVariables are not used directly as wire/port types, but can appear *inside* other types * OpDef's may be polymorphic over RowVariables (allowing "varargs"-like operators equivalent to e.g. MakeTuple); these must be replaced by non-rowvar types when instantiating the OpDef to an OpType * FuncDefn's/FuncDecl's may also be polymorphic over RowVariables as long as these are not directly argument/result types * Also add TypeParam::new_sequence closes #787 BREAKING CHANGE: Type::validate takes extra bool (allow_rowvars); renamed {FunctionType, PolyFuncType}::(validate=>validate_var_len). --------- Co-authored-by: doug-q <[email protected]>
TypeParam::List / TypeArg::List allows one to declare a list of types, and provide them as type args (also other kinds of list, not relevant here). But there's no way to use these outside a custom binary function. We should allow should a parameter to be used inside a tuple, sum, or function type (inputs or outputs), or anywhere a row is expected, so one can say e.g.
unpack_tuple
has aTypeParam::List(TypeParam::Type)
and then inputsTuple(TypeArg::new_variable(0, TypeParam::List(TypeParam::Type))
and outputs that type variable.The text was updated successfully, but these errors were encountered: