Skip to content

quast_decisiontree.algorithms.classical.base

quast_decisiontree.algorithms.classical.base

Base class for classical (non-quantum) optimization algorithms.

ClassicalAlgorithm

Bases: ABC

Abstract base class for classical solvers.

Classical solvers take a fully specified optimization problem and return a result synchronously via :meth:execute. Unlike hybrid algorithms, they involve no quantum backend, input lifecycle, or builder integration.

Subclasses may override :meth:check_input to validate problem inputs.

Source code in src/quast_decisiontree/algorithms/classical/base.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class ClassicalAlgorithm(ABC):
    """Abstract base class for classical solvers.

    Classical solvers take a fully specified optimization problem and return a
    result synchronously via :meth:`execute`. Unlike hybrid algorithms, they
    involve no quantum backend, input lifecycle, or builder integration.

    Subclasses may override :meth:`check_input` to validate problem inputs.
    """

    @abstractmethod
    def execute(self, opt_problem: Any, classical_args: Any = None) -> Any:
        """Run the algorithm on ``opt_problem`` and return the result.

        Args:
            opt_problem: The optimization problem to solve.
            classical_args: Optional algorithm-specific arguments.

        Returns:
            An algorithm-specific result.
        """

    @classmethod
    def check_input(cls, opt_problem: Any) -> bool:
        """Check whether ``opt_problem`` is a valid input for this algorithm.

        The default implementation accepts any input; override to validate.

        Args:
            opt_problem: The optimization problem to validate.

        Returns:
            True if the input is valid, False otherwise.
        """
        return True

execute abstractmethod

execute(opt_problem, classical_args=None)

Run the algorithm on opt_problem and return the result.

Parameters:

Name Type Description Default
opt_problem Any

The optimization problem to solve.

required
classical_args Any

Optional algorithm-specific arguments.

None

Returns:

Type Description
Any

An algorithm-specific result.

Source code in src/quast_decisiontree/algorithms/classical/base.py
25
26
27
28
29
30
31
32
33
34
35
@abstractmethod
def execute(self, opt_problem: Any, classical_args: Any = None) -> Any:
    """Run the algorithm on ``opt_problem`` and return the result.

    Args:
        opt_problem: The optimization problem to solve.
        classical_args: Optional algorithm-specific arguments.

    Returns:
        An algorithm-specific result.
    """

check_input classmethod

check_input(opt_problem)

Check whether opt_problem is a valid input for this algorithm.

The default implementation accepts any input; override to validate.

Parameters:

Name Type Description Default
opt_problem Any

The optimization problem to validate.

required

Returns:

Type Description
bool

True if the input is valid, False otherwise.

Source code in src/quast_decisiontree/algorithms/classical/base.py
37
38
39
40
41
42
43
44
45
46
47
48
49
@classmethod
def check_input(cls, opt_problem: Any) -> bool:
    """Check whether ``opt_problem`` is a valid input for this algorithm.

    The default implementation accepts any input; override to validate.

    Args:
        opt_problem: The optimization problem to validate.

    Returns:
        True if the input is valid, False otherwise.
    """
    return True