Skip to main content

Components for machine learning

Project description

TNO Quantum: Machine Learning - Components

TNO Quantum provides generic software components aimed at facilitating the development of quantum applications.

This package contains generic components for our machine learning packages.

Limitations in (end-)use: the content of this software package may solely be used for applications that comply with international export control laws.

Documentation

Documentation of the tno.quantum.ml.components package can be found here.

Install

Easily install the tno.quantum.ml.components package using pip:

$ python -m pip install tno.quantum.ml.components

Usage

The Quantum Machine Learning Components package allows you to define custom scikit-learn-compatible estimators that depend on solving QUBO problems.

from __future__ import annotations

from typing import TYPE_CHECKING, Self

import numpy as np
from numpy.typing import NDArray
from sklearn.base import ClusterMixin

from tno.quantum.ml.components import QUBOEstimator

if TYPE_CHECKING:
    from tno.quantum.optimization.qubo.components import QUBO
    from tno.quantum.utils import BitVectorLike


class CustomQUBOClustering(ClusterMixin, QUBOEstimator):
    """Custom QUBO clustering for demonstration purposes.

    This is **NOT** a functional clustering class but serves as an example of how to 
      implement a QUBO estimator in the TNO Quantum framework.
    """

    def _check_X_and_y(
        self, X: NDArray[np.float64], y: NDArray[np.float64] | None = None
    ) -> None:
        if y is None:
            error_msg = (
                "This estimator requires target values (y) to be provided for training."
            )
            raise ValueError(error_msg)

    def _make_qubo(
        self, X: NDArray[np.float64], y: NDArray[np.float64] | None = None
    ) -> QUBO:
        # Create here the QUBO matrix based on the input data.
        pass

    def _check_constraints(self, bit_vector: BitVectorLike) -> bool:
        # No specific constraints for this classifier.
        return True

    def _decode_bit_vector(self, bit_vector: BitVectorLike) -> Self:
        # Decode the bit vector to return the classifier instance.
        return self

For a more complete and functional example, see the QKMedoids implementation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tno_quantum_ml_components-2.0.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tno_quantum_ml_components-2.0.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file tno_quantum_ml_components-2.0.3.tar.gz.

File metadata

File hashes

Hashes for tno_quantum_ml_components-2.0.3.tar.gz
Algorithm Hash digest
SHA256 4e968705dee79806c2212e3adb109a693b2654ffb69fb8e6b79fac7c8f296a88
MD5 c55981eb7312dde12ce6f2707a9cc1bc
BLAKE2b-256 30825de9b9dd59de4a044df0b5e31d31e69d37d52882f7bd494f8b261ad49844

See more details on using hashes here.

File details

Details for the file tno_quantum_ml_components-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for tno_quantum_ml_components-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2ab67ee0622eeb740506e610b2dfa17368ec49d386f089ddd4db3bf3ffd3f748
MD5 00ff7d0ff9e75af6d6551b2cc0ec54b9
BLAKE2b-256 381875a6398aa5d6ca2a22d5e3da47212471148ae9df0a4e7f409ef771171ae8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page