CQCL / guppylang

Pythonic quantum-classical programming language
https://pypi.org/project/guppylang
Apache License 2.0
33 stars 3 forks source link

Generic functions break arrays #629

Closed mark-koch closed 5 days ago

mark-koch commented 1 week ago

The Guppy type array[qubit, 42] is lowered to the Hugr type Array<Option<Qubit>> to allow non-linear indexing. The same also happens for array[T, 42] where T is a generic linear type variable.

However, when we subsitute T with a classical type (say int), it suddenly lowers to the Hugr type Array<Int<6>> without the Option! This results in ill-typed Hugrs whenever we invoke a generic array function with a classical type.

Short-term fix: Also use Option for classical values (but omitting the "replacing with None" logic). This is not very nice, but should solve the problem until we implement the proper solution.

Longer-term: Add a new Hugr extension for Guppy arrays that is lowered to regular arrays later on in the stack (after monomorphisation!). See #628.