guppylang icon indicating copy to clipboard operation
guppylang copied to clipboard

User hint for maximum number of qubits allocated

Open ss2165 opened this issue 3 months ago • 3 comments

Suggested syntax

from guppylang.hints import max_qubits

N_QB = 4
@max_qubits(N_QB)
@guppy
def foo() -> None:
    a = array(qubit() for _ in range(py(N_QB))
    discard_array(a)

Compilation

Attach as standard metadata key to entrypoint op. Key should be specified in tket2.

Usage

n_qubits parameter to emulator can now be optional:

foo.emulator().run() # will raise error if `foo` is not annotated

ss2165 avatar Oct 13 '25 12:10 ss2165

What would happen if the user is wrong in hinting how many qubits they need? Would Selene crash? Or would this hint just apply to cases where its easy to figure out?

CalMacCQ avatar Oct 16 '25 09:10 CalMacCQ

yes crash, same as now though with the n_qubits parameter. This is basically about attaching that same information to the program, so that it can also be used for other purposes (e.g. ancilla budget tracking in synthesis)

ss2165 avatar Oct 16 '25 12:10 ss2165

Instead of a new decorator, we could also consider a kwarg for the @guppy decorator similar to how we did @guppy(unitary=True)?

mark-koch avatar Nov 19 '25 10:11 mark-koch