moptipy.tests package

Code for testing of implementations of different parts of the moptipy API.

In this package, we provide code that can be used to test different parts of the moptipy API and implementation. These are not unit tests, but rather code that can be used to build unit tests. If you want to use moptipy in your code, then likely you will implement own algorithms and operators. If you want to test whether they comply with the moptipy specifications, then the functions here will be helpful.

Submodules

moptipy.tests.algorithm module

Functions that can be used to test algorithm implementations.

moptipy.tests.algorithm.validate_algorithm(algorithm, solution_space, objective, search_space=None, encoding=None, max_fes=100, required_result=None, uses_all_fes_if_goal_not_reached=True, is_encoding_deterministic=True, post=None)[source]

Check whether an algorithm follows the moptipy API specification.

Parameters:
  • algorithm (Algorithm) – the algorithm to test

  • solution_space (Space) – the solution space

  • objective (Objective) – the objective function

  • search_space (Space | None, default: None) – the optional search space

  • encoding (Encoding | None, default: None) – the optional encoding

  • max_fes (int, default: 100) – the maximum number of FEs

  • required_result (int | float | None, default: None) – the optional required result quality

  • uses_all_fes_if_goal_not_reached (bool, default: True) – will the algorithm use all FEs unless it reaches the goal?

  • is_encoding_deterministic (bool, default: True) – is the encoding deterministic?

  • post (Optional[Callable[[Algorithm, int], Any]], default: None) – a check to run after each execution of the algorithm, receiving the algorithm and the number of consumed FEs as parameter

Raises:
Return type:

None

moptipy.tests.component module

Functions that can be used to test component implementations.

moptipy.tests.component.validate_component(component)[source]

Check whether an object is a valid moptipy component.

This test checks the conversion to string and the logging of parameters. This method must be called before the other validate_* methods provided in this package.

Parameters:

component (Component) – the component to test

Raises:
Return type:

None

moptipy.tests.encoding module

Functions that can be used to test encodings.

moptipy.tests.encoding.validate_encoding(encoding, search_space=None, solution_space=None, make_search_space_element_valid=<function <lambda>>, is_deterministic=True)[source]

Check whether an object is a proper moptipy encoding.

Parameters:
  • encoding (Encoding) – the encoding to test

  • search_space (Space | None, default: None) – the search space

  • make_search_space_element_valid (Optional[Callable[[Any], Any]], default: <function <lambda> at 0x7f667fecb920>) – a method that can turn a point from the space into a valid point

  • solution_space (Space | None, default: None) – the solution space

  • is_deterministic (bool, default: True) – is the mapping deterministic?

Raises:
Return type:

None

moptipy.tests.fitness module

Test fitness assignment processes.

moptipy.tests.fitness.validate_fitness(fitness, objective, space, op0)[source]

Validate a fitness assignment process on a given problem.

Parameters:
  • fitness (Fitness) – the fitness assignment process

  • objective (Objective) – the objective function

  • space (Space) – the space of solutions

  • op0 (Op0) – the nullary operator

Return type:

None

moptipy.tests.mo_algorithm module

Functions that can be used to test multi-objective algorithms.

moptipy.tests.mo_algorithm.validate_mo_algorithm(algorithm, solution_space, problem, search_space=None, encoding=None, max_fes=100, is_encoding_deterministic=True)[source]

Check whether a multi-objective algorithm follows the moptipy API.

Parameters:
  • algorithm (MOAlgorithm) – the algorithm to test

  • solution_space (Space) – the solution space

  • problem (MOProblem) – the problem to solve

  • search_space (Space | None, default: None) – the optional search space

  • encoding (Encoding | None, default: None) – the optional encoding

  • max_fes (int, default: 100) – the maximum number of FEs

  • is_encoding_deterministic (bool, default: True) – is the encoding deterministic?

Raises:
Return type:

None

moptipy.tests.mo_archive_pruner module

Functions for testing multi-objective archive pruners.

moptipy.tests.mo_archive_pruner.validate_mo_archive_pruner(pruner_factory, dimensions, dtypes=(dtype('int8'), dtype('uint8'), dtype('int16'), dtype('uint16'), dtype('int32'), dtype('uint32'), dtype('int64'), dtype('uint64'), dtype('float64')))[source]

Check whether an object is a moptipy multi-objective optimization pruner.

This method checks whether the class is correct and whether the pruning follows the general contract: Interesting records in the list to be pruned are moved to the front, the ones to discard are moved to the back. No record is lost and none is duplicated.

Parameters:
  • pruner_factory (Callable[[MOProblem], MOArchivePruner]) – the creator for the multi-objective archive pruner to test

  • dimensions (Iterable[int]) – the dimensions to simulate

  • dtypes (Iterable[dtype], default: (dtype('int8'), dtype('uint8'), dtype('int16'), dtype('uint16'), dtype('int32'), dtype('uint32'), dtype('int64'), dtype('uint64'), dtype('float64'))) – the dtypes to test on

Raises:
Return type:

None

moptipy.tests.mo_problem module

Functions for testing multi-objective optimization problems.

moptipy.tests.mo_problem.validate_mo_problem(mo_problem, solution_space=None, make_solution_space_element_valid=<function <lambda>>, is_deterministic=True, lower_bound_threshold=-inf, upper_bound_threshold=inf, must_be_equal_to=None)[source]

Check whether an object is a moptipy multi-objective optimization problem.

Parameters:
  • mo_problem (MOProblem) – the multi-objective optimization problem to test

  • solution_space (Space | None, default: None) – the solution space

  • make_solution_space_element_valid (Optional[Callable[[Generator, Any], Any]], default: <function <lambda> at 0x7f667f82ee80>) – a function that makes an element from the solution space valid

  • is_deterministic (bool) – is the objective function deterministic?

  • lower_bound_threshold (int | float, default: -inf) – the threshold for the lower bound

  • upper_bound_threshold (int | float, default: inf) – the threshold for the upper bound

  • must_be_equal_to (Optional[Callable[[Any], int | float]], default: None) – an optional function that should return the exactly same values as the objective function

Raises:
Return type:

None

moptipy.tests.objective module

Functions that can be used to test objective functions.

moptipy.tests.objective.validate_objective(objective, solution_space=None, make_solution_space_element_valid=<function <lambda>>, is_deterministic=True, lower_bound_threshold=-inf, upper_bound_threshold=inf, must_be_equal_to=None)[source]

Check whether an object is a moptipy objective function.

Parameters:
  • objective (Objective) – the objective function to test

  • solution_space (Space | None, default: None) – the solution space

  • make_solution_space_element_valid (Optional[Callable[[Generator, Any], Any]], default: <function <lambda> at 0x7f667fecaf20>) – a function that makes an element from the solution space valid

  • is_deterministic (bool) – is the objective function deterministic?

  • lower_bound_threshold (int | float, default: -inf) – the threshold for the lower bound

  • upper_bound_threshold (int | float, default: inf) – the threshold for the upper bound

  • must_be_equal_to (Optional[Callable[[Any], int | float]], default: None) – an optional function that should return the exactly same values as the objective function

Raises:
Return type:

None

moptipy.tests.on_bitstrings module

Test stuff on bit strings.

moptipy.tests.on_bitstrings.bitstrings_for_tests()[source]

Get a sequence of bit strings for tests.

Return type:

Iterable[BitStrings]

Returns:

the sequence of BitStrings

moptipy.tests.on_bitstrings.dimensions_for_tests()[source]

Get a sequence of dimensions for tests.

Return type:

Iterable[int]

Returns:

the sequence of integers

moptipy.tests.on_bitstrings.random_bit_string(random, x)[source]

Randomize a bit string.

Parameters:
  • random (Generator) – the random number generator

  • x (ndarray) – the bit string

Return type:

ndarray

Returns:

the array

moptipy.tests.on_bitstrings.validate_algorithm_on_bitstrings(objective, algorithm, dimension=5, max_fes=100, required_result=None, uses_all_fes_if_goal_not_reached=True, post=None)[source]

Check the validity of a black-box algorithm on a bit strings problem.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_algorithm_on_leadingones(algorithm, post=None)[source]

Check the validity of a black-box algorithm on LeadingOnes.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_algorithm_on_onemax(algorithm, post=None)[source]

Check the validity of a black-box algorithm on OneMax.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_fitness_on_bitstrings(fitness, class_needed=<class 'moptipy.algorithms.so.fitness.Fitness'>, prepare_objective=<function <lambda>>)[source]

Validate a fitness assignment process on bit strings.

Parameters:
  • fitness (Union[Fitness, Callable[[Objective], Fitness]]) – the fitness assignment process, or a callable creating it

  • class_needed (str | type, default: <class 'moptipy.algorithms.so.fitness.Fitness'>) – the required class

  • prepare_objective (Callable[[Objective], Objective], default: <function <lambda> at 0x7f667f96ccc0>) – prepare the objective function

Return type:

None

moptipy.tests.on_bitstrings.validate_mo_algorithm_on_2_bitstring_problems(algorithm)[source]

Check the validity of a black-box algorithm on OneMax and ZeroMax.

Parameters:

algorithm (Union[MOAlgorithm, Callable[[BitStrings, MOProblem], MOAlgorithm]]) – the algorithm or algorithm factory

Return type:

None

moptipy.tests.on_bitstrings.validate_mo_algorithm_on_3_bitstring_problems(algorithm)[source]

Check the validity of an algorithm on OneMax, ZeroMax, and Ising1d.

Parameters:

algorithm (Union[MOAlgorithm, Callable[[BitStrings, MOProblem], MOAlgorithm]]) – the algorithm or algorithm factory

Return type:

None

moptipy.tests.on_bitstrings.validate_mo_algorithm_on_bitstrings(problem, algorithm, dimension=5, max_fes=100)[source]

Check a black-box multi-objective algorithm on a bit strings problem.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op0_on_1_bitstrings(op0, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the unary operator on one bit strings instance.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op0_on_bitstrings(op0, number_of_samples=None, min_unique_samples=None)[source]

Validate the unary operator on several BitStrings instances.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op1_on_1_bitstrings(op1, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the unary operator on one BitStrings instance.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op1_on_bitstrings(op1, number_of_samples=None, min_unique_samples=None)[source]

Validate the unary operator on several BitStrings instances.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op1_with_step_size_on_1_bitstrings(op1, search_space, number_of_samples=None, min_unique_samples=None, step_sizes=(), get_step_size=None)[source]

Validate the step-sized unary operator on one BitStrings instance.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op1_with_step_size_on_bitstrings(op1, number_of_samples=None, min_unique_samples=None, step_sizes=(), get_step_size=None)[source]

Validate the unary operator on several BitStrings instances.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op2_on_1_bitstrings(op2, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the binary operator on one BitStrings instance.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.validate_op2_on_bitstrings(op2, number_of_samples=None, min_unique_samples=None)[source]

Validate the binary operator on several BitStrings instances.

Parameters:
Return type:

None

moptipy.tests.on_bitstrings.verify_algorithms_equivalent(algorithms, max_fes=None)[source]

Verify that a set of algorithms performs identical steps.

Parameters:
Return type:

None

moptipy.tests.on_jssp module

Perform tests on the Job Shop Scheduling Problem.

moptipy.tests.on_jssp.jssp_instances_for_tests()[source]

Get a sequence of JSSP instances to test on.

Return type:

Iterable[str]

Returns:

an iterable of JSSP instance names

moptipy.tests.on_jssp.make_gantt_valid(inst)[source]

Make a function that creates valid Gantt charts.

Parameters:

inst (Instance) – the JSSP instance

Return type:

Callable[[Generator, Gantt], Gantt]

Returns:

a function that can make gantt charts valid

moptipy.tests.on_jssp.validate_algorithm_on_1_jssp(algorithm, instance=None, max_fes=100, required_result=None, post=None)[source]

Check the validity of a black-box algorithm on the JSSP.

Parameters:
  • algorithm (Union[Algorithm, Callable[[Instance, Permutations, Objective], Algorithm]]) – the algorithm or algorithm factory

  • instance (str | None, default: None) – the instance name, or None to randomly pick one

  • max_fes (int, default: 100) – the maximum number of FEs

  • required_result (int | None, default: None) – the optional required result quality

  • post (Optional[Callable[[Algorithm, int], Any]], default: None) – a check to run after each execution of the algorithm, receiving the algorithm and the number of consumed FEs as parameter

Return type:

None

moptipy.tests.on_jssp.validate_algorithm_on_jssp(algorithm, max_fes=100, post=None)[source]

Validate an algorithm on a set of JSSP instances.

Parameters:
Return type:

None

moptipy.tests.on_jssp.validate_mo_algorithm_on_1_jssp(algorithm, instance=None, max_fes=100)[source]

Check the validity of a black-box multi-objective algorithm on the JSSP.

Parameters:
Return type:

None

moptipy.tests.on_jssp.validate_mo_algorithm_on_jssp(algorithm)[source]

Validate a multi-objective algorithm on a set of JSSP instances.

Parameters:

algorithm (Callable[[Instance, Permutations, MOProblem], MOAlgorithm]) – the algorithm factory

Return type:

None

moptipy.tests.on_jssp.validate_objective_on_1_jssp(objective, instance=None, is_deterministic=True)[source]

Validate an objective function on 1 JSSP instance.

Parameters:
  • objective (Union[Objective, Callable[[Instance], Objective]]) – the objective function or a factory creating it

  • instance (str | None, default: None) – the instance name

  • is_deterministic (bool, default: True) – is the objective function deterministic?

Return type:

None

moptipy.tests.on_jssp.validate_objective_on_jssp(objective, is_deterministic=True)[source]

Validate an objective function on JSSP instances.

Parameters:
Return type:

None

moptipy.tests.on_ordered_choices module

Test stuff on ordered choices-based spaces.

moptipy.tests.on_ordered_choices.choices_for_tests(choice_filter=None)[source]

Get a sequence of ordered choices for tests.

Parameters:

choice_filter (Optional[Callable[[OrderedChoices], bool]], default: None) – an optional filter to sort out ordered choices we cannot use for testing

Return type:

Iterable[OrderedChoices]

Returns:

the sequence of ordered choices

moptipy.tests.on_ordered_choices.make_choices_valid(choices)[source]

Create a function that can make ordered choices valid.

Parameters:

choices (OrderedChoices) – the ordered choices

Return type:

Callable[[Generator, ndarray], ndarray]

Returns:

the function

moptipy.tests.on_ordered_choices.validate_op0_on_1_choices(op0, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the nullary operator on one OrderedChoices instance.

Parameters:
Return type:

None

moptipy.tests.on_ordered_choices.validate_op0_on_choices(op0, number_of_samples=None, min_unique_samples=None, choice_filter=None)[source]

Validate the nullary operator on several OrderedChoices instances.

Parameters:
Return type:

None

moptipy.tests.on_permutations module

Test stuff on permutations with repetitions.

moptipy.tests.on_permutations.make_permutation_valid(pwr)[source]

Create a function that can make permutations with repetitions valid.

Parameters:

pwr (Permutations) – the permutations

Return type:

Callable[[Generator, ndarray], ndarray]

Returns:

the function

moptipy.tests.on_permutations.permutations_for_tests(perm_filter=None)[source]

Get a sequence of permutations for tests.

Parameters:

perm_filter (Optional[Callable[[Permutations], bool]], default: None) – an optional filter to sort out permutations we cannot use for testing

Return type:

Iterable[Permutations]

Returns:

the sequence of Permutations

moptipy.tests.on_permutations.validate_op0_on_1_permutations(op0, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the nullary operator on one Permutations instance.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op0_on_permutations(op0, number_of_samples=None, min_unique_samples=None, perm_filter=None)[source]

Validate the nullary operator on several Permutations instances.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op1_on_1_permutations(op1, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the unary operator on one Permutations instance.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op1_on_permutations(op1, number_of_samples=None, min_unique_samples=None, perm_filter=None)[source]

Validate the unary operator on several Permutations instances.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op1_with_step_size_on_1_permutations(op1, search_space, number_of_samples=None, min_unique_samples=None, step_sizes=(), get_step_size=None)[source]

Validate the step-sized unary operator on one Permutations instance.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op1_with_step_size_on_permutations(op1, number_of_samples=None, min_unique_samples=None, step_sizes=(), get_step_size=None, perm_filter=None)[source]

Validate the unary operator on several Permutations instances.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op2_on_1_permutations(op2, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the binary operator on one Permutations instance.

Parameters:
Return type:

None

moptipy.tests.on_permutations.validate_op2_on_permutations(op2, number_of_samples=None, min_unique_samples=None, perm_filter=None)[source]

Validate the binary operator on several Permutations instances.

Parameters:
Return type:

None

moptipy.tests.on_signed_permutations module

Test stuff on signed permutations with repetitions.

moptipy.tests.on_signed_permutations.make_signed_permutation_valid(pwr)[source]

Create a function that can make permutations with repetitions valid.

Parameters:

pwr (SignedPermutations) – the permutations

Return type:

Callable[[Generator, ndarray], ndarray]

Returns:

the function

moptipy.tests.on_signed_permutations.signed_permutations_for_tests(perm_filter=None)[source]

Get a sequence of permutations for tests.

Parameters:

perm_filter (Optional[Callable[[SignedPermutations], bool]], default: None) – an optional filter to sort out permutations we cannot use for testing

Return type:

Iterable[SignedPermutations]

Returns:

the sequence of SignedPermutations

moptipy.tests.on_signed_permutations.validate_op0_on_1_signed_permutations(op0, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the nullary operator on one SignedPermutations instance.

Parameters:
Return type:

None

moptipy.tests.on_signed_permutations.validate_op0_on_signed_permutations(op0, number_of_samples=None, min_unique_samples=None, perm_filter=None)[source]

Validate the nullary operator on several SignedPermutations instances.

Parameters:
Return type:

None

moptipy.tests.on_signed_permutations.validate_op1_on_1_signed_permutations(op1, search_space, number_of_samples=None, min_unique_samples=None)[source]

Validate the unary operator on one SignedPermutations instance.

Parameters:
Return type:

None

moptipy.tests.on_signed_permutations.validate_op1_on_signed_permutations(op1, number_of_samples=None, min_unique_samples=None, perm_filter=None)[source]

Validate the unary operator on several SignedPermutations instances.

Parameters:
Return type:

None

moptipy.tests.on_vectors module

Test stuff on real vectors.

moptipy.tests.on_vectors.DIMENSIONS_FOR_TESTS: Final[tuple[int, ...]] = (1, 2, 3, 4, 5, 10)

The dimensions for tests

moptipy.tests.on_vectors.make_vector_valid(space)[source]

Create a function that can make a vector space element valid.

Parameters:

space (VectorSpace) – the vector space

Return type:

Callable[[Generator, ndarray], ndarray]

Returns:

the function

moptipy.tests.on_vectors.validate_algorithm_on_ackley(algorithm, uses_all_fes_if_goal_not_reached=True, dims=(1, 2, 3, 4, 5, 10), post=None)[source]

Check the validity of a black-box algorithm on Ackley’s function.

Parameters:
  • algorithm (Union[Algorithm, Callable[[VectorSpace, Objective], Algorithm]]) – the algorithm or algorithm factory

  • uses_all_fes_if_goal_not_reached (bool, default: True) – will the algorithm use all FEs unless it reaches the goal?

  • dims (Iterable[int], default: (1, 2, 3, 4, 5, 10)) – the dimensions

  • post (Optional[Callable[[Algorithm, int], Any]], default: None) – a check to run after each execution of the algorithm, receiving the algorithm and the number of consumed FEs as parameter

Return type:

None

moptipy.tests.on_vectors.validate_algorithm_on_vectors(objective, algorithm, max_fes=100, uses_all_fes_if_goal_not_reached=True, dims=(1, 2, 3, 4, 5, 10), post=None)[source]

Check the validity of a black-box algorithm on vector problems.

Parameters:
Return type:

None

moptipy.tests.on_vectors.validate_op0_on_1_vectors(op0, search_space, number_of_samples=None, min_unique_samples=<function <lambda>>)[source]

Validate the nullary operator on one VectorSpace instance.

Parameters:
Return type:

None

moptipy.tests.on_vectors.validate_op0_on_vectors(op0, number_of_samples=None, min_unique_samples=<function <lambda>>)[source]

Validate the nullary operator on default VectorSpace instance.

Parameters:
Return type:

None

moptipy.tests.on_vectors.vectors_for_tests(dims=(1, 2, 3, 4, 5, 10))[source]

Get a sequence of vector spaces for tests.

Parameters:

dims (Iterable[int], default: (1, 2, 3, 4, 5, 10)) – the dimensions

Return type:

Iterable[VectorSpace]

Returns:

the sequence of vector spaces

moptipy.tests.op0 module

Functions that can be used to test nullary search operators.

moptipy.tests.op0.validate_op0(op0, search_space=None, make_search_space_element_valid=<function <lambda>>, number_of_samples=100, min_unique_samples=<function <lambda>>)[source]

Check whether an object is a valid moptipy nullary operator.

Parameters:
  • op0 (Op0) – the operator

  • search_space (Space | None, default: None) – the search space

  • make_search_space_element_valid (Optional[Callable[[Generator, Any], Any]], default: <function <lambda> at 0x7f667fd3c540>) – make a point in the search space valid

  • number_of_samples (int, default: 100) – the number of times to invoke the operator

  • min_unique_samples (Union[int, Callable[[int, Space], int]], default: <function <lambda> at 0x7f667fd3c400>) – a lambda for computing the number

Raises:
Return type:

None

moptipy.tests.op1 module

Functions that can be used to test unary search operators.

moptipy.tests.op1.default_min_unique_samples(samples, space)[source]

Compute the default number of minimum unique samples.

Parameters:
  • samples (int) – the number of samples

  • space (Space) – the space

Return type:

int

Returns:

the number of samples

moptipy.tests.op1.validate_op1(op1, search_space=None, make_search_space_element_valid=<function <lambda>>, number_of_samples=100, min_unique_samples=<function default_min_unique_samples>)[source]

Check whether an object is a valid moptipy unary operator.

Parameters:
  • op1 (Op1) – the operator

  • search_space (Space | None, default: None) – the search space

  • make_search_space_element_valid (Optional[Callable[[Generator, Any], Any]], default: <function <lambda> at 0x7f667fd3c720>) – make a point in the search space valid

  • number_of_samples (int, default: 100) – the number of times to invoke the operator

  • min_unique_samples (Union[int, Callable[[int, Space], int]], default: <function default_min_unique_samples at 0x7f667fd3c5e0>) – a lambda for computing the number

Raises:
Return type:

None

moptipy.tests.op1_with_step_size module

Functions for testing unary search operators with step size.

moptipy.tests.op1_with_step_size.validate_op1_with_step_size(op1, search_space=None, make_search_space_element_valid=<function <lambda>>, number_of_samples=100, min_unique_samples=<function default_min_unique_samples>, step_sizes=(), get_step_size=None)[source]

Check whether an object is a valid moptipy unary operator with step size.

Parameters:
  • op1 (Op1WithStepSize) – the operator

  • search_space (Space | None, default: None) – the search space

  • make_search_space_element_valid (Optional[Callable[[Generator, Any], Any]], default: <function <lambda> at 0x7f667fd3c900>) – make a point in the search space valid

  • number_of_samples (int, default: 100) – the number of times to invoke the operator

  • min_unique_samples (Union[int, Callable[[int, Space], int]], default: <function default_min_unique_samples at 0x7f667fd3c5e0>) – a lambda for computing the number

  • step_sizes (Iterable[float], default: ()) – the step sizes to test

  • get_step_size (Optional[Callable[[Space, Any, Any], float | None]], default: None) – try to get the step size difference from two space elements

Raises:
Return type:

None

moptipy.tests.op2 module

Functions that can be used to test binary search operators.

moptipy.tests.op2.validate_op2(op2, search_space=None, make_search_space_element_valid=<function <lambda>>, number_of_samples=100, min_unique_samples=<function <lambda>>)[source]

Check whether an object is valid a moptipy binary operator.

Parameters:
  • op2 (Op2) – the operator

  • search_space (Space | None, default: None) – the search space

  • make_search_space_element_valid (Optional[Callable[[Generator, Any], Any]], default: <function <lambda> at 0x7f667fd3ca40>) – make a point in the search space valid

  • number_of_samples (int, default: 100) – the number of times to invoke the operator

  • min_unique_samples (Union[int, Callable[[int, Space], int]], default: <function <lambda> at 0x7f667fd3e2a0>) – a lambda for computing the number

Raises:
Return type:

None

moptipy.tests.selection module

Validate selection algorithms.

moptipy.tests.selection.validate_selection(selection, without_replacement=False, lower_source_size_limit=0, upper_source_size_limit=999999)[source]

Validate a selection algorithm.

Parameters:
  • selection (Selection) – the selection algorithm

  • without_replacement (bool, default: False) – is this selection algorithm without replacement, i.e., can it select each element at most once?

  • lower_source_size_limit (int, default: 0) – the lower limit of the source size

  • upper_source_size_limit (int, default: 999999) – the upper limit for the source size

Return type:

None

moptipy.tests.space module

Functions that can be used to test spaces.

moptipy.tests.space.validate_space(space, make_element_valid=<function <lambda>>, make_element_invalid=None)[source]

Check whether an object is a moptipy space.

Parameters:
  • space (Space) – the space to test

  • make_element_valid (Optional[Callable[[Any], Any]], default: <function <lambda> at 0x7f667fec91c0>) – a method that can turn a point from the space into a valid point

  • make_element_invalid (Optional[Callable[[Any], Any]], default: None) – a method can a valid point from the space into an invalid one

Raises:
Return type:

None