MatchCake

matchcake.ml.kernels package

Submodules

matchcake.ml.kernels.fermionic_pqc_kernel module

class matchcake.ml.kernels.fermionic_pqc_kernel.FermionicPQCKernel(size: int | None = None, **kwargs)

Bases: NIFKernel

Inspired from: https://iopscience.iop.org/article/10.1088/2632-2153/acb0b4/meta#artAbst

By default, the size of the kernel is computed as

\[\text{size} = \max\left(2, \lceil\log_2(\text{n features} + 2)\rceil\right)\]

and the depth is computed as

\[\text{depth} = \max\left(1, \left(\frac{\text{n features}}{\text{size}} - 1\right)\right)\]
__init__(size: int | None = None, **kwargs)
ansatz(x)
available_entangling_mth = {'fswap', 'hadamard', 'identity'}
circuit(x0, x1)
property data_scaling
property depth
initialize_parameters()
property rotations
set_predict_request(*, x: bool | None | str = '$UNCHANGED$') FermionicPQCKernel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, x: bool | None | str = '$UNCHANGED$') FermionicPQCKernel

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in transform.

Returns:

self – The updated object.

Return type:

object

class matchcake.ml.kernels.fermionic_pqc_kernel.StateVectorFermionicPQCKernel(size: int | None = None, **kwargs)

Bases: FermionicPQCKernel

__init__(size: int | None = None, **kwargs)
ansatz(x)
pre_initialize()
set_predict_request(*, x: bool | None | str = '$UNCHANGED$') StateVectorFermionicPQCKernel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, x: bool | None | str = '$UNCHANGED$') StateVectorFermionicPQCKernel

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in transform.

Returns:

self – The updated object.

Return type:

object

matchcake.ml.kernels.kernel_utils module

class matchcake.ml.kernels.kernel_utils.GramMatrixKernel(shape: ~typing.Tuple[int, int], dtype: str | ~numpy.dtype | None = <class 'numpy.float64'>, array_type: str = 'table', **kwargs)

Bases: object

__init__(shape: ~typing.Tuple[int, int], dtype: str | ~numpy.dtype | None = <class 'numpy.float64'>, array_type: str = 'table', **kwargs)
close()
property dtype
fill_diagonal(value: float)
property is_square
make_batches_indexes_generator(batch_size: int) Tuple[iter, int]
mirror()
property shape
property size
symmetrize()
tril_reflect()
triu_reflect()
matchcake.ml.kernels.kernel_utils.mrot_zz_template(param0, param1, wires)

matchcake.ml.kernels.ml_kernel module

class matchcake.ml.kernels.ml_kernel.MLKernel(size: int | None = None, **kwargs)

Bases: StdEstimator

__init__(size: int | None = None, **kwargs)
batch_distance(x0, x1, **kwargs)
batch_distance_in_sequence(x0, x1, **kwargs)
cast_tensor_to_interface(tensor)
compute_gram_matrix(x, **kwargs)
fit(X, y=None, **kwargs)

Fit the model with the given data.

Parameters:
  • X – The input data.

  • y – The target values.

  • kwargs – Additional arguments.

Keyword Arguments:

check_X_y – Whether to check the input data and target values. Default is True.

Returns:

The fitted model.

fit_transform(X, y=None)
get_batch_size_for(length: int)
gram_diagonal_fill(gram)
initialize_parameters()
make_batches_generator(x, **kwargs) Tuple[iter, int]
pairwise_distances(x0, x1, **kwargs)

Compute pairwise distances between two sets of vectors.

Parameters:
  • x0 – First set of vectors of shape (n_samples_0, n_features)

  • x1 – Second set of vectors of shape (n_samples_1, n_features)

  • kwargs – Additional keyword arguments

Keyword Arguments:

check_array – Whether to check the input arrays. Default is True.

Returns:

Pairwise distances between x0 and x1 of shape (n_samples_0, n_samples_1)

pairwise_distances_in_batch(x0, x1, **kwargs)

Compute pairwise distances between two sets of vectors in batch.

Parameters:
  • x0 – First set of vectors of shape (n_samples_0, n_features)

  • x1 – Second set of vectors of shape (n_samples_1, n_features)

  • kwargs – Additional keyword arguments

Keyword Arguments:
  • check_array – Whether to check the input arrays. Default is True.

  • p_bar – Progress bar. Default is None.

Returns:

Pairwise distances between x0 and x1 of shape (n_samples_0, n_samples_1)

pairwise_distances_in_sequence(x0, x1, **kwargs)
property parameters
pre_initialize()
predict(x, **kwargs)
set_predict_request(*, x: bool | None | str = '$UNCHANGED$') MLKernel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, x: bool | None | str = '$UNCHANGED$') MLKernel

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in transform.

Returns:

self – The updated object.

Return type:

object

single_distance(x0, x1, **kwargs)
property size
transform(x)

matchcake.ml.kernels.nif_kernel module

class matchcake.ml.kernels.nif_kernel.NIFKernel(size: int | None = None, **kwargs)

Bases: MLKernel

UNPICKLABLE_ATTRIBUTES = ['_device', '_qnode']
__init__(size: int | None = None, **kwargs)
batch_distance(x0, x1, **kwargs)
cast_tensor_to_interface(tensor)
circuit(x0, x1)
compile_qnode()
draw(**kwargs)
draw_mpl(fig: Figure | None = None, ax: Axes | None = None, **kwargs)
fit(X, y=None, **kwargs)

Fit the model with the given data.

Parameters:
  • X – The input data.

  • y – The target values.

  • kwargs – Additional arguments.

Keyword Arguments:

check_X_y – Whether to check the input data and target values. Default is True.

Returns:

The fitted model.

get_n_ops()
get_n_params()
initialize_parameters()
property n_ops
property n_params
pre_initialize()
property qnode
set_predict_request(*, x: bool | None | str = '$UNCHANGED$') NIFKernel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, x: bool | None | str = '$UNCHANGED$') NIFKernel

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in transform.

Returns:

self – The updated object.

Return type:

object

single_distance(x0, x1, **kwargs)
property tape
property wires

Module contents