pytket.wasm

Handler for wasm files in pytket

class pytket.wasm.wasm.WasmFileHandler(filepath, check_file=True, int_size=32)[source]

Construct and optionally check a wasm module from a file for use in wasm Ops.

__init__(filepath, check_file=True, int_size=32)[source]

Construct a wasm file handler using a filepath to read a wasm module into memory.

Parameters:
  • filepath (str) – Path to the wasm file

  • check_file (bool) – If True checks file for compatibility with wasm standards. If False checks are skipped.

  • int_size (int) – length of the integer that is used in the wasm file

class pytket.wasm.wasm.WasmModuleHandler(wasm_module, check=True, int_size=32)[source]

Construct and optionally check a wasm module for use in wasm Ops.

__init__(wasm_module, check=True, int_size=32)[source]

Construct a wasm module handler

Parameters:
  • wasm_module (bytes) – A wasm module in binary format.

  • check (bool) – If True checks file for compatibility with wasm standards. If False checks are skipped.

  • int_size (int) – length of the integer that is used in the wasm file

__repr__()[source]

str representation of the contents of the wasm file.

Return type:

str

__str__()[source]

str representation of the wasm module

Return type:

str

bytecode()[source]

The wasm content as bytecode

Return type:

bytes

check()[source]

Collect functions from the module that can be used with pytket.

Populates the internal list of supported and unsupported functions and marks the module as checked so that subsequent checking is not required.

Return type:

None

check_function(function_name, number_of_parameters, number_of_returns)[source]

Checks a given function name and signature if it is included and the module has previously been checked.

If the module has not been checked this function with will raise a ValueError.

Parameters:
  • function_name (str) – name of the function that is checked

  • number_of_parameters (int) – number of integer parameters of the function

  • number_of_returns (int) – number of integer return values of the function

Return type:

bool

Returns:

true if the signature and the name of the function is correct

property bytecode_base64: bytes

The wasm content as base64 encoded bytecode.

property functions: dict[str, tuple[int, int]]

Retrieve the names of functions with the number of input and out arguments.

If the module has not been checked this function with will raise a ValueError.

property uid: str

A unique identifier for the module calculated from its’ checksum.

property unsupported_functions: list[str]

Retrieve the names of unsupported functions as a list of strings.

If the module has not been checked this function with will raise a ValueError.