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

Load circuit as a function definition #657

Open
ss2165 opened this issue Nov 19, 2024 · 1 comment · May be fixed by #672
Open

Load circuit as a function definition #657

ss2165 opened this issue Nov 19, 2024 · 1 comment · May be fixed by #672
Assignees

Comments

@ss2165
Copy link
Member

ss2165 commented Nov 19, 2024

So that function value execution isn't required

Use uuids for circuits - can use circuit names or custom names in future once we have #563 and use that for circuits

@ss2165 ss2165 assigned ss2165 and tatiana-s and unassigned ss2165 Nov 19, 2024
@mark-koch
Copy link
Collaborator

We want to allow users to declare pytket circuits to be used within Guppy at the module level:

from pytket import Circuit

pytket_circ = Circuit(2)
pytket_circ.H(0)
pytket_circ.CX(0, 1)

@guppy.pytket(pytket_circ)
def guppy_circ(q1: qubit, q2: qubit) -> None:
   """Explicit stub for the circuit."""

# Alternatively, we also want to support loading without declaring a stub
guppy_circ = guppy.load_pytket(circ)

@guppy
def main() -> None:
   q1, q2 = qubit(), qubit()
   guppy_circ(q1, q2)
   measure(q1)
   measure(q2)

The benefit of the stub approach is that it will allow the user to specify whether they want to use arrays for registers or pass qubits one by one.

To implement this feature, we need to add new kind of Definition:

  • RawPytketDef that holds a reference to the Python stub function and implements ParsableDef. The parse method should check that the provided stub signature makes sense for the circuit.
  • ParsedPytketDef that holds the parsed circuit signature and implements CallableDef and CheckableDef. guppy.load_pytket should directly lower to that.
  • CompiledPytketDef that holds a reference to the Hugr FuncDefn that was generated for the circuit and implements CompiledCallableDef.

In decorator.py, we need to add the appropriate guppy_circ and load_pytket functions that construct a RawPytketDef or a PytketDef respectively, and register it with the current module.

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 a pull request may close this issue.

3 participants