Concrete ML
WebsiteLibrariesProducts & ServicesDevelopersSupport
1.3
1.3
  • What is Concrete ML?
  • Getting Started
    • Installation
    • Key Concepts
    • Inference in the Cloud
    • Demos and Tutorials
  • Built-in Models
    • Linear Models
    • Tree-based Models
    • Neural Networks
    • Nearest Neighbors
    • Pandas
    • Built-in Model Examples
  • Deep Learning
    • Using Torch
    • Using ONNX
    • Step-by-step Guide
    • Deep Learning Examples
    • Debugging Models
    • Optimizing Inference
  • Deployment
    • Prediction with FHE
    • Hybrid models
    • Production Deployment
    • Serialization
  • Advanced topics
    • Quantization
    • Pruning
    • Compilation
    • Advanced Features
  • Developer Guide
    • Workflow
      • Set Up the Project
      • Set Up Docker
      • Documentation
      • Support and Issues
      • Contributing
    • Inner Workings
      • Importing ONNX
      • Quantization Tools
      • FHE Op-graph Design
      • External Libraries
    • API
      • concrete.ml.common.check_inputs.md
      • concrete.ml.common.debugging.custom_assert.md
      • concrete.ml.common.debugging.md
      • concrete.ml.common.md
      • concrete.ml.common.serialization.decoder.md
      • concrete.ml.common.serialization.dumpers.md
      • concrete.ml.common.serialization.encoder.md
      • concrete.ml.common.serialization.loaders.md
      • concrete.ml.common.serialization.md
      • concrete.ml.common.utils.md
      • concrete.ml.deployment.deploy_to_aws.md
      • concrete.ml.deployment.deploy_to_docker.md
      • concrete.ml.deployment.fhe_client_server.md
      • concrete.ml.deployment.md
      • concrete.ml.deployment.server.md
      • concrete.ml.deployment.utils.md
      • concrete.ml.onnx.convert.md
      • concrete.ml.onnx.md
      • concrete.ml.onnx.onnx_impl_utils.md
      • concrete.ml.onnx.onnx_model_manipulations.md
      • concrete.ml.onnx.onnx_utils.md
      • concrete.ml.onnx.ops_impl.md
      • concrete.ml.pytest.md
      • concrete.ml.pytest.torch_models.md
      • concrete.ml.pytest.utils.md
      • concrete.ml.quantization.base_quantized_op.md
      • concrete.ml.quantization.md
      • concrete.ml.quantization.post_training.md
      • concrete.ml.quantization.quantized_module.md
      • concrete.ml.quantization.quantized_module_passes.md
      • concrete.ml.quantization.quantized_ops.md
      • concrete.ml.quantization.quantizers.md
      • concrete.ml.search_parameters.md
      • concrete.ml.search_parameters.p_error_search.md
      • concrete.ml.sklearn.base.md
      • concrete.ml.sklearn.glm.md
      • concrete.ml.sklearn.linear_model.md
      • concrete.ml.sklearn.md
      • concrete.ml.sklearn.neighbors.md
      • concrete.ml.sklearn.qnn.md
      • concrete.ml.sklearn.qnn_module.md
      • concrete.ml.sklearn.rf.md
      • concrete.ml.sklearn.svm.md
      • concrete.ml.sklearn.tree.md
      • concrete.ml.sklearn.tree_to_numpy.md
      • concrete.ml.sklearn.xgb.md
      • concrete.ml.torch.compile.md
      • concrete.ml.torch.hybrid_model.md
      • concrete.ml.torch.md
      • concrete.ml.torch.numpy_module.md
      • concrete.ml.version.md
Powered by GitBook

Libraries

  • TFHE-rs
  • Concrete
  • Concrete ML
  • fhEVM

Developers

  • Blog
  • Documentation
  • Github
  • FHE resources

Company

  • About
  • Introduction to FHE
  • Media
  • Careers
On this page
  • module concrete.ml.pytest.utils
  • Global Variables
  • function get_sklearn_linear_models_and_datasets
  • function get_sklearn_tree_models_and_datasets
  • function get_sklearn_neural_net_models_and_datasets
  • function get_sklearn_neighbors_models_and_datasets
  • function get_sklearn_all_models_and_datasets
  • function instantiate_model_generic
  • function data_calibration_processing
  • function load_torch_model
  • function values_are_equal
  • function check_serialization

Was this helpful?

Export as PDF
  1. Developer Guide
  2. API

concrete.ml.pytest.utils.md

Previousconcrete.ml.pytest.torch_models.mdNextconcrete.ml.quantization.base_quantized_op.md

Last updated 1 year ago

Was this helpful?

module concrete.ml.pytest.utils

Common functions or lists for test files, which can't be put in fixtures.

Global Variables

  • MODELS_AND_DATASETS

  • UNIQUE_MODELS_AND_DATASETS


function get_sklearn_linear_models_and_datasets

get_sklearn_linear_models_and_datasets(
    regressor: bool = True,
    classifier: bool = True,
    unique_models: bool = False,
    select: Optional[str, List[str]] = None,
    ignore: Optional[str, List[str]] = None
) → List

Get the pytest parameters to use for testing linear models.

Args:

  • regressor (bool): If regressors should be selected.

  • classifier (bool): If classifiers should be selected.

  • unique_models (bool): If each models should be represented only once.

  • select (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) match the given string or list of strings. Default to None.

  • ignore (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) do not match the given string or list of strings. Default to None.

Returns:

  • List: The pytest parameters to use for testing linear models.


function get_sklearn_tree_models_and_datasets

get_sklearn_tree_models_and_datasets(
    regressor: bool = True,
    classifier: bool = True,
    unique_models: bool = False,
    select: Optional[str, List[str]] = None,
    ignore: Optional[str, List[str]] = None
) → List

Get the pytest parameters to use for testing tree-based models.

Args:

  • regressor (bool): If regressors should be selected.

  • classifier (bool): If classifiers should be selected.

  • unique_models (bool): If each models should be represented only once.

  • select (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) match the given string or list of strings. Default to None.

  • ignore (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) do not match the given string or list of strings. Default to None.

Returns:

  • List: The pytest parameters to use for testing tree-based models.


function get_sklearn_neural_net_models_and_datasets

get_sklearn_neural_net_models_and_datasets(
    regressor: bool = True,
    classifier: bool = True,
    unique_models: bool = False,
    select: Optional[str, List[str]] = None,
    ignore: Optional[str, List[str]] = None
) → List

Get the pytest parameters to use for testing neural network models.

Args:

  • regressor (bool): If regressors should be selected.

  • classifier (bool): If classifiers should be selected.

  • unique_models (bool): If each models should be represented only once.

  • select (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) match the given string or list of strings. Default to None.

  • ignore (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) do not match the given string or list of strings. Default to None.

Returns:

  • List: The pytest parameters to use for testing neural network models.


function get_sklearn_neighbors_models_and_datasets

get_sklearn_neighbors_models_and_datasets(
    regressor: bool = True,
    classifier: bool = True,
    unique_models: bool = False,
    select: Optional[str, List[str]] = None,
    ignore: Optional[str, List[str]] = None
) → List

Get the pytest parameters to use for testing neighbor models.

Args:

  • regressor (bool): If regressors should be selected.

  • classifier (bool): If classifiers should be selected.

  • unique_models (bool): If each models should be represented only once.

  • select (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) match the given string or list of strings. Default to None.

  • ignore (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) do not match the given string or list of strings. Default to None.

Returns:

  • List: The pytest parameters to use for testing neighbor models.


function get_sklearn_all_models_and_datasets

get_sklearn_all_models_and_datasets(
    regressor: bool = True,
    classifier: bool = True,
    unique_models: bool = False,
    select: Optional[str, List[str]] = None,
    ignore: Optional[str, List[str]] = None
) → List

Get the pytest parameters to use for testing all models available in Concrete ML.

Args:

  • regressor (bool): If regressors should be selected.

  • classifier (bool): If classifiers should be selected.

  • unique_models (bool): If each models should be represented only once.

  • select (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) match the given string or list of strings. Default to None.

  • ignore (Optional[Union[str, List[str]]]): If not None, only return models which names (or a part of it) do not match the given string or list of strings. Default to None.

Returns:

  • List: The pytest parameters to use for testing all models available in Concrete ML.


function instantiate_model_generic

instantiate_model_generic(model_class, n_bits, **parameters)

Instantiate any Concrete ML model type.

Args:

  • model_class (class): The type of the model to instantiate.

  • n_bits (int): The number of quantization to use when initializing the model. For QNNs, default parameters are used based on whether n_bits is greater or smaller than 8.

  • parameters (dict): Hyper-parameters for the model instantiation. For QNNs, these parameters will override the matching default ones.

Returns:

  • model_name (str): The type of the model as a string.

  • model (object): The model instance.


function data_calibration_processing

data_calibration_processing(data, n_sample: int, targets=None)

Reduce size of the given data-set.

Args:

  • data: The input container to consider

  • n_sample (int): Number of samples to keep if the given data-set

  • targets: If dataset is a torch.utils.data.Dataset, it typically contains both the data and the corresponding targets. In this case, targets must be set to None. If data is instance of torch.Tensor or 'numpy.ndarray, targets` is expected.

Returns:

  • Tuple[numpy.ndarray, numpy.ndarray]: The input data and the target (respectively x and y).

Raises:

  • TypeError: If the 'data-set' does not match any expected type.


function load_torch_model

load_torch_model(
    model_class: Module,
    state_dict_or_path: Optional[str, Path, Dict[str, Any]],
    params: Dict,
    device: str = 'cpu'
) → Module

Load an object saved with torch.save() from a file or dict.

Args:

  • model_class (torch.nn.Module): A PyTorch or Brevitas network.

  • state_dict_or_path (Optional[Union[str, Path, Dict[str, Any]]]): Path or state_dict

  • params (Dict): Model's parameters

  • device (str): Device type.

Returns:

  • torch.nn.Module: A PyTorch or Brevitas network.


function values_are_equal

values_are_equal(value_1: Any, value_2: Any) → bool

Indicate if two values are equal.

This method takes into account objects of type None, numpy.ndarray, numpy.floating, numpy.integer, numpy.random.RandomState or any instance that provides a __eq__ method.

Args:

  • value_2 (Any): The first value to consider.

  • value_1 (Any): The second value to consider.

Returns:

  • bool: If the two values are equal.


function check_serialization

check_serialization(
    object_to_serialize: Any,
    expected_type: Type,
    equal_method: Optional[Callable] = None,
    check_str: bool = True
)

Check that the given object can properly be serialized.

This function serializes all objects using the dump, dumps, load and loads functions from Concrete ML. If the given object provides a dump and dumps method, they are also serialized using these.

Args:

  • object_to_serialize (Any): The object to serialize.

  • expected_type (Type): The object's expected type.

  • equal_method (Optional[Callable]): The function to use to compare the two loaded objects. Default to values_are_equal.

  • check_str (bool): If the JSON strings should also be checked. Default to True.