matchcake.ml package¶
Subpackages¶
- matchcake.ml.kernels package
- Submodules
- matchcake.ml.kernels.fermionic_pqc_kernel module
FermionicPQCKernel
FermionicPQCKernel.__init__()
FermionicPQCKernel.ansatz()
FermionicPQCKernel.available_entangling_mth
FermionicPQCKernel.circuit()
FermionicPQCKernel.data_scaling
FermionicPQCKernel.depth
FermionicPQCKernel.initialize_parameters()
FermionicPQCKernel.rotations
FermionicPQCKernel.set_predict_request()
FermionicPQCKernel.set_transform_request()
StateVectorFermionicPQCKernel
- matchcake.ml.kernels.kernel_utils module
GramMatrixKernel
GramMatrixKernel.__init__()
GramMatrixKernel.close()
GramMatrixKernel.dtype
GramMatrixKernel.fill_diagonal()
GramMatrixKernel.is_square
GramMatrixKernel.make_batches_indexes_generator()
GramMatrixKernel.mirror()
GramMatrixKernel.shape
GramMatrixKernel.size
GramMatrixKernel.symmetrize()
GramMatrixKernel.tril_reflect()
GramMatrixKernel.triu_reflect()
mrot_zz_template()
- matchcake.ml.kernels.ml_kernel module
MLKernel
MLKernel.__init__()
MLKernel.batch_distance()
MLKernel.batch_distance_in_sequence()
MLKernel.cast_tensor_to_interface()
MLKernel.compute_gram_matrix()
MLKernel.fit()
MLKernel.fit_transform()
MLKernel.get_batch_size_for()
MLKernel.gram_diagonal_fill()
MLKernel.initialize_parameters()
MLKernel.make_batches_generator()
MLKernel.pairwise_distances()
MLKernel.pairwise_distances_in_batch()
MLKernel.pairwise_distances_in_sequence()
MLKernel.parameters
MLKernel.pre_initialize()
MLKernel.predict()
MLKernel.set_predict_request()
MLKernel.set_transform_request()
MLKernel.single_distance()
MLKernel.size
MLKernel.transform()
- matchcake.ml.kernels.nif_kernel module
NIFKernel
NIFKernel.UNPICKLABLE_ATTRIBUTES
NIFKernel.__init__()
NIFKernel.batch_distance()
NIFKernel.cast_tensor_to_interface()
NIFKernel.circuit()
NIFKernel.compile_qnode()
NIFKernel.draw()
NIFKernel.draw_mpl()
NIFKernel.fit()
NIFKernel.get_n_ops()
NIFKernel.get_n_params()
NIFKernel.initialize_parameters()
NIFKernel.n_ops
NIFKernel.n_params
NIFKernel.pre_initialize()
NIFKernel.qnode
NIFKernel.set_predict_request()
NIFKernel.set_transform_request()
NIFKernel.single_distance()
NIFKernel.tape
NIFKernel.wires
- Module contents
- matchcake.ml.optimizer_strategies package
- Submodules
- matchcake.ml.optimizer_strategies.adam_strategy module
- matchcake.ml.optimizer_strategies.adamw_strategy module
- matchcake.ml.optimizer_strategies.genetic_strategy module
- matchcake.ml.optimizer_strategies.optimizer_strategy module
OptimizerStrategy
OptimizerStrategy.NAME
OptimizerStrategy.OPTIONAL_HYPERPARAMETERS
OptimizerStrategy.REQUIRES_GRAD
OptimizerStrategy.REQUIRES_HYPERPARAMETERS
OptimizerStrategy.__init__()
OptimizerStrategy.check_required_hyperparameters()
OptimizerStrategy.jac()
OptimizerStrategy.optimize()
OptimizerStrategy.params_vector
OptimizerStrategy.set_optional_hyperparameters()
OptimizerStrategy.set_parameters()
OptimizerStrategy.step()
OptimizerStrategy.vector_to_parameters()
ScipyOptimizerStrategy
- matchcake.ml.optimizer_strategies.random_strategy module
- matchcake.ml.optimizer_strategies.scipy_strategies module
- matchcake.ml.optimizer_strategies.simulated_annealing_strategy module
SimulatedAnnealingStrategy
SimulatedAnnealingStrategy.DEFAULT_TEMPERATURE
SimulatedAnnealingStrategy.NAME
SimulatedAnnealingStrategy.OPTIONAL_HYPERPARAMETERS
SimulatedAnnealingStrategy.REQUIRES_HYPERPARAMETERS
SimulatedAnnealingStrategy.__init__()
SimulatedAnnealingStrategy.optimize()
SimulatedAnnealingStrategy.set_parameters()
SimulatedAnnealingStrategy.step()
- Module contents
- matchcake.ml.parameters_initialisation_strategies package
- Submodules
- matchcake.ml.parameters_initialisation_strategies.linear_strategy module
- matchcake.ml.parameters_initialisation_strategies.parameters_initialisation_strategy module
ParametersInitialisationStrategy
ParametersInitialisationStrategy.NAME
ParametersInitialisationStrategy.OPTIONAL_HYPERPARAMETERS
ParametersInitialisationStrategy.REQUIRES_HYPERPARAMETERS
ParametersInitialisationStrategy.__init__()
ParametersInitialisationStrategy.add_parameters_to_memory()
ParametersInitialisationStrategy.check_required_hyperparameters()
ParametersInitialisationStrategy.get_next_parameters()
ParametersInitialisationStrategy.initialise_parameters()
ParametersInitialisationStrategy.set_optional_hyperparameters()
- matchcake.ml.parameters_initialisation_strategies.random_strategy module
- Module contents
- matchcake.ml.torch_models package
- Submodules
- matchcake.ml.torch_models.nif_torch_model module
- matchcake.ml.torch_models.torch_model module
TorchModel
TorchModel.ATTRS_TO_HPARAMS
TorchModel.ATTRS_TO_JSON
TorchModel.ATTRS_TO_PICKLE
TorchModel.ATTRS_TO_STATE_DICT
TorchModel.DEFAULT_FIT_PATIENCE
TorchModel.DEFAULT_LEARNING_RATE
TorchModel.DEFAULT_LOG_FUNC()
TorchModel.DEFAULT_MAX_GRAD_NORM
TorchModel.DEFAULT_OPTIMIZER
TorchModel.DEFAULT_PARAMETERS_INITIALISATION_STRATEGY
TorchModel.DEFAULT_SAVE_DIR
TorchModel.DEFAULT_SAVE_ROOT
TorchModel.DEFAULT_SEED
TorchModel.DEFAULT_USE_CUDA
TorchModel.MODEL_NAME
TorchModel.__init__()
TorchModel.add_model_specific_args()
TorchModel.best_model_path
TorchModel.cast_tensor_to_interface()
TorchModel.cost()
TorchModel.default_save_dir_from_args()
TorchModel.draw_mpl()
TorchModel.fit()
TorchModel.fit_callback()
TorchModel.fit_closure()
TorchModel.forward()
TorchModel.from_folder()
TorchModel.from_folder_or_new()
TorchModel.hparams_path
TorchModel.initialize_parameters_()
TorchModel.jsons_path
TorchModel.load()
TorchModel.load_best()
TorchModel.load_best_if_exists()
TorchModel.load_hparams()
TorchModel.load_if_exists()
TorchModel.load_jsons()
TorchModel.load_pickles()
TorchModel.load_state_dict()
TorchModel.model_path
TorchModel.pickles_path
TorchModel.plot_fit_history()
TorchModel.predict()
TorchModel.save()
TorchModel.save_best()
TorchModel.save_hparams()
TorchModel.save_jsons()
TorchModel.save_metrics()
TorchModel.save_path
TorchModel.save_pickles()
TorchModel.score()
TorchModel.state_dict()
TorchModel.torch_device
TorchModel.update_parameters()
- Module contents
Submodules¶
matchcake.ml.std_estimator module¶
- class matchcake.ml.std_estimator.StdEstimator(**kwargs)¶
Bases:
BaseEstimator
- UNPICKLABLE_ATTRIBUTES = []¶
- __init__(**kwargs) None ¶
- check_is_fitted()¶
- fit(X, y=None, **kwargs) StdEstimator ¶
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.
- property is_fitted¶
- classmethod load(filepath) StdEstimator ¶
Load a model from a saved file. If the extension of the file is not specified, this method will try to load the model from the file with the “.joblib” extension. If the file does not exist, it will try to load the model from the file with the “.pkl” extension. Otherwise, it will try without any extension.
- Parameters:
filepath (str) – The path to the saved model.
- Returns:
The loaded model.
- Return type:
- save(filepath) StdEstimator ¶
Save the model to a joblib file. If the given filepath does not end with “.joblib”, it will be appended.
- Parameters:
filepath (str) – The path to save the model.
- Returns:
The model instance.
- Return type:
self.__class__
matchcake.ml.svm module¶
- class matchcake.ml.svm.FixedSizeSVC(kernel_cls: Type[MLKernel] | str, kernel_kwargs: dict | None = None, max_gram_size: int | None = inf, cache_size: int = 1024, random_state: int = 0, **kwargs)¶
Bases:
StdEstimator
- __init__(kernel_cls: Type[MLKernel] | str, kernel_kwargs: dict | None = None, max_gram_size: int | None = inf, cache_size: int = 1024, random_state: int = 0, **kwargs) None ¶
- 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_gram_matrices(X, **kwargs)¶
- get_gram_matrices_from_memory(X, **kwargs)¶
- get_gram_matrix(X)¶
- get_is_in_memory(X)¶
- get_pairwise_distances(x0, x1)¶
- get_pairwise_distances_matrices(x0, x1, **kwargs)¶
- property kernel¶
- property kernel_n_ops¶
- property kernel_n_params¶
- property kernel_size¶
- property n_features¶
- property n_kernels¶
- predict(X, **kwargs)¶
Predict the labels of the input data of shape (n_samples, n_features).
- Parameters:
X (np.ndarray or array-like) – The input data of shape (n_samples, n_features).
kwargs – Additional keyword arguments.
- Keyword Arguments:
cache – If True, the computed gram matrices will be stored in memory. Default is False.
- Returns:
The predicted labels of the input data.
- Return type:
np.ndarray of shape (n_samples,)
- push_to_memory(X, gram_matrices)¶
- score(X, y, **kwargs)¶
- split_data(x, y=None)¶
- class matchcake.ml.svm.SimpleSVC(kernel_cls: Type[MLKernel], kernel_kwargs: dict | None = None, cache_size: int = 1024, random_state: int = 0, **kwargs)¶
Bases:
StdEstimator
- __init__(kernel_cls: Type[MLKernel], kernel_kwargs: dict | None = None, cache_size: int = 1024, random_state: int = 0, **kwargs) None ¶
- fit(X, y=None, train_gram_matrix=None, **kwargs)¶
Fit the model to the input data of shape (n_samples, n_features). This process involves building the kernel object, computing the gram matrix, and fitting the SVM model. If the train_gram_matrix is provided, the kernel object will not be built and the gram matrix will be used directly.
- Parameters:
X – The input data of shape (n_samples, n_features).
y – The target labels of shape (n_samples,).
train_gram_matrix – The precomputed gram matrix of shape (n_samples, n_samples). This input is optional and is used to avoid recomputing the gram matrix.
kwargs – Additional keyword arguments to be passed to the kernel object and the compute_gram_matrix method.
- Returns:
The fitted model.
- get_gram_matrix_from_memory(X, **kwargs)¶
- get_is_in_memory(X)¶
- predict(X, **kwargs)¶
Predict the labels of the input data of shape (n_samples, n_features).
- Parameters:
X (np.ndarray or array-like) – The input data of shape (n_samples, n_features).
kwargs – Additional keyword arguments.
- Keyword Arguments:
cache – If True, the computed gram matrices will be stored in memory. Default is False.
- Returns:
The predicted labels of the input data.
- Return type:
np.ndarray of shape (n_samples,)
- push_to_memory(X, gram_matrix)¶
- score(X, y, **kwargs)¶
Get the accuracy of the model on the input data.
- Parameters:
X – The input data of shape (n_samples, n_features).
y – The target labels of shape (n_samples,).
kwargs – Additional keyword arguments to be passed to the predict method.
- Returns:
The accuracy of the model on the input data.
- set_fit_request(*, train_gram_matrix: bool | None | str = '$UNCHANGED$') SimpleSVC ¶
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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:
train_gram_matrix (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
train_gram_matrix
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- property train_gram_matrix¶
matchcake.ml.visualisation module¶
- class matchcake.ml.visualisation.ClassificationVisualizer(*, x: ndarray | None = None, x_reduced: ndarray | None = None, x_mesh: ndarray | None = None, reducer: Any | None = None, transform: Callable | None = None, inverse_transform: Callable | None = None, n_pts: int = 1000, seed: int | None = 0, **kwargs)¶
Bases:
Visualizer
- __init__(*, x: ndarray | None = None, x_reduced: ndarray | None = None, x_mesh: ndarray | None = None, reducer: Any | None = None, transform: Callable | None = None, inverse_transform: Callable | None = None, n_pts: int = 1000, seed: int | None = 0, **kwargs)¶
- compute_x_mesh(**kwargs)¶
- compute_x_reduced(**kwargs)¶
- gather_transforms(**kwargs)¶
If a transform and an inverse_transform functions are given, they will be returned. Otherwise, the transform and inverse_transform will be inferred from the given reducer. If the reducer is None, then it will be initialized as a PCA with 2 components.
- plot_2d_decision_boundaries(*, y: ndarray | None = None, model: Any | None = None, y_pred: ndarray | None = None, **kwargs)¶
- class matchcake.ml.visualisation.Visualizer¶
Bases:
object