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

Add support for wasm #755

Open
doug-q opened this issue Jan 7, 2025 · 0 comments
Open

Add support for wasm #755

doug-q opened this issue Jan 7, 2025 · 0 comments

Comments

@doug-q
Copy link
Contributor

doug-q commented Jan 7, 2025

See CQCL/tket2#737 for proposed extension spec.

  • Model stateful WASM context with affine type.
  • WASM functions can take have form:
E = int | bool | float
T = E | array[E, N]

def foo(*args: T) -> E: ...
def void(*args: T) -> None: ...

Require standard library guppy.std.wasm with functions:

@guppy.struct
class WASMContext:
  """Affine type representing state of environment."""
  
def new_wasm_checked() -> Option[WASMContext]:
  """Returns a new WASM environment if available else None."""

def new_wasm() -> WASMContext:
"""Panicking version of `new_wasm_checked`""".
  new = new_wasm_checked()
  if new.is_some():
    return new.unwrap()
  panic("No more WASM environments available")

Example:

# all declared wasm signatures are treated as belonging to single wasm module

@guppy.wasm
def add_one(x: int) -> int: ...

@guppy.wasm
def add_syndrome(syndrome: array[bool, 3]) -> None: ...

@guppy.wasm
def decode() -> int: ...



@guppy
def main() -> None:
wasm1 = new_wasm()
wasm2 = new_wasm()
y = wasm1.add_one(x) # all methods take WASMContext as inout
wasm2.add_syndrome(array(True, False, False))
decoded = wasm2.decode()
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

No branches or pull requests

1 participant