Utils that can be re-used by other pieces of code in the module.

Global Variables


function replace_invalid_arg_name_chars

replace_invalid_arg_name_chars(arg_name: str)str

Sanitize arg_name, replacing invalid chars by _.

This does not check that the starting character of arg_name is valid.


  • arg_name (str): the arg name to sanitize.


  • str: the sanitized arg name, with only chars in _VALID_ARG_CHARS.

function generate_proxy_function

    function_to_proxy: Callable,
    desired_functions_arg_names: Iterable[str]
) → Tuple[Callable, Dict[str, str]]

Generate a proxy function for a function accepting only *args type arguments.

This returns a runtime compiled function with the sanitized argument names passed in desired_functions_arg_names as the arguments to the function.


  • function_to_proxy (Callable): the function defined like def f(*args) for which to return a function like f_proxy(arg_1, arg_2) for any number of arguments.

  • desired_functions_arg_names (Iterable[str]): the argument names to use, these names are sanitized and the mapping between the original argument name to the sanitized one is returned in a dictionary. Only the sanitized names will work for a call to the proxy function.


  • Tuple[Callable, Dict[str, str]]: the proxy function and the mapping of the original arg name to the new and sanitized arg names.

function get_onnx_opset_version

get_onnx_opset_version(onnx_model: ModelProto)int

Return the ONNX opset_version.


  • onnx_model (onnx.ModelProto): the model.


  • int: the version of the model

function manage_parameters_for_pbs_errors

    p_error: Optional[float] = None,
    global_p_error: Optional[float] = None

Return (p_error, global_p_error) that we want to give to Concrete-Numpy and the compiler.

The returned (p_error, global_p_error) depends on user's parameters and the way we want to manage defaults in Concrete-ML, which may be different from the way defaults are managed in Concrete-Numpy

Principle: - if none are set, we set global_p_error to a default value of our choice - if both are set, we raise an error - if one is set, we use it and forward it to Concrete-Numpy and the compiler

Note that global_p_error is currently not simulated by the VL, i.e., taken as 0.


  • p_error (Optional[float]): probability of error of a single PBS.

  • global_p_error (Optional[float]): probability of error of the full circuit.


  • (p_error, global_p_error): parameters to give to the compiler


  • ValueError: if the two parameters are set (this is not as in Concrete-Numpy)

function check_there_is_no_p_error_options_in_configuration


Check the user did not set p_error or global_p_error in configuration.

It would be dangerous, since we set them in direct arguments in our calls to Concrete-Numpy.


  • configuration: Configuration object to use during compilation

Last updated