guppylang
guppylang copied to clipboard
Support generic comptime functions
Would be cool to have this. I can imagine cases where you would want to write generic functions whilst having full Python expressivity via comptime.
For instance encode_integer(n: int) -> array[qubit, k]. We could just take n as input and use the bin builtin to get a string of 0,1 and apply x gates for the binary encoding. I don't think we can interate through strings in guppy atm.
EDIT: I suppose you could just take an array of bools as an argument in this case instead of an int.
Would be very useful to have this.
I need this
I also need this.
There is a workaround of sorts that may not be satisfactory for your use case.
def build_ladder_prog(n_qb: int) -> GuppyFunctionDefinition:
@guppy.comptime
def ladder(qs: array[qubit, comptime(n_qb)]) -> None:
for q1, q2 in zip(qs[1:], qs[:-1]):
print("Applying CX")
cx(q1, q2)
return ladder
ladder_func5 = build_ladder_prog(5)
ladder_func5.compile_function()
Here I am defining my Guppy comptime function inside a Python function where the number of qubits is passed as a parameter.
Would be nicer to have generic comptime functions of course.