service
¶
Classes:
-
TranspilerServiceImpl–Implementation of the TranspilerService gRPC service.
Functions:
-
assign_environ–Expand environment variables and the user directory "~" in the values of
dict. -
parse_json–Parse a JSON string into a dictionary or return None if the input is invalid.
-
parse_str–Parse the input string and return a valid string or None.
-
serve–Start the gRPC server with the specified configuration and logging settings.
TranspilerServiceImpl
¶
TranspilerServiceImpl()
Implementation of the TranspilerService gRPC service.
This class provides the Transpile function, which handles requests to transpile
quantum programs. It utilizes the Tranqu library to perform transpilation and
prepares the response with the transpiled program, associated statistics, and
virtual-physical qubit mapping.
Functions:
-
Transpile–Handle a gRPC request to transpile a quantum program.
Transpile
¶
Handle a gRPC request to transpile a quantum program.
This method processes a transpilation request, parses the inputs, calls the
Tranqu library to perform the transpilation, and constructs the response
with the results. If an exception occurs during transpilation, an error
response is returned.
Parameters:
-
(request¶TranspileRequest) –The gRPC request containing the program and related parameters for transpilation.
-
(context¶ServicerContext) –The gRPC context for the request.
Returns:
-
TranspileResponse–tranqu_pb2.TranspileResponse: The gRPC response containing the transpiled program, statistics, and virtual-physical qubit mapping. The
statusfield indicates the result of the transpilation, where0represents a successful transpilation and1indicates an error occurred.
assign_environ
¶
assign_environ(config: dict) -> dict
Expand environment variables and the user directory "~" in the values of dict.
Parameters:
-
(config¶dict) –dictthat expands environment variables and the user directory "~" in its values.
Returns:
-
dict(dict) –expanded
dict.
parse_json
¶
parse_json(raw_str: str) -> dict[Any, Any] | None
Parse a JSON string into a dictionary or return None if the input is invalid.
This function takes a raw string and attempts to parse it as a JSON object.
If the input string is empty or None, it returns None. Otherwise, it parses
the string into a Python dictionary.
Parameters:
-
(raw_str¶str) –The input JSON string to be parsed.
Returns:
-
dict[Any, Any] | None–dict[Any, Any] | None: A dictionary representation of the JSON string if
-
dict[Any, Any] | None–parsing is successful, or
Noneif the input is empty orNone.
parse_str
¶
parse_str(raw_str: str) -> str | None
Parse the input string and return a valid string or None.
This function checks if the input string is empty or None-like. If the input
is an empty string ("") or None, it returns None. Otherwise, it returns
the input string as is.
Parameters:
-
(raw_str¶str) –The input string to be parsed.
Returns:
-
str | None–str | None: The input string if it is valid, or
Noneif the input is -
str | None–empty or None-like.
serve
¶
serve(config_yaml_path: str, logging_yaml_path: str) -> None
Start the gRPC server with the specified configuration and logging settings.
This function initializes and starts a gRPC server using the configuration provided in the YAML files for the server and logging. It sets up a transpiler service, configures the server's address and worker threads, and waits for the server to terminate.
Parameters: