jina.optimizers.parameters module

class jina.optimizers.parameters.OptimizationParameter(parameter_name='', executor_name=None, prefix='JINA', jaml_variable=None)[source]

Bases: jina.jaml.JAMLCompatible

Base class for all optimization parameters.

property search_space: Dict[str, List[Any]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Raises

NotImplementedErrorOptimizationParameter is just an interface. Please use any implemented subclass.

Return type

Dict[str, List[Any]]

update_trial_params(trial, trial_params)[source]

Update the trial parameters given the variables and the trials

Parameters
  • trial (Trial) – An instance of an Optuna Trial object

  • trial_params (Dict) – the parameters to update # noqa: DAR201

class jina.optimizers.parameters.IntegerParameter(low, high, step_size=1, log=False, *args, **kwargs)[source]

Bases: jina.optimizers.parameters.OptimizationParameter

Used for optimizing integer parameters with the FlowOptimizer. For detailed information about sampling and usage see https://optuna.readthedocs.io/en/stable/reference/generated/optuna.trial.Trial.html#optuna.trial.Trial.suggest_int

property search_space: Dict[str, List[int]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Return type

Dict[str, List[int]]

Return:

The parameter’s search space in dictionary form with the parameter name as key and a list of values as value

class jina.optimizers.parameters.UniformParameter(low, high, *args, **kwargs)[source]

Bases: jina.optimizers.parameters.OptimizationParameter

Used for optimizing float parameters with the FlowOptimizer with uniform sampling. For detailed information about sampling and usage see https://optuna.readthedocs.io/en/stable/reference/generated/optuna.trial.Trial.html#optuna.trial.Trial.suggest_discrete_uniform

property search_space: Dict[str, List[Any]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Raises

NotImplementedError – search space is not defined for parameter type UniformParameter.

Return type

Dict[str, List[Any]]

class jina.optimizers.parameters.LogUniformParameter(low, high, *args, **kwargs)[source]

Bases: jina.optimizers.parameters.OptimizationParameter

Used for optimizing float parameters with the FlowOptimizer with loguniform sampling. For detailed information about sampling and usage see https://optuna.readthedocs.io/en/stable/reference/generated/optuna.trial.Trial.html#optuna.trial.Trial.suggest_loguniform

property search_space: Dict[str, List[Any]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Raises

NotImplementedError – search space is not defined for parameter type LogUniformParameter.

Return type

Dict[str, List[Any]]

class jina.optimizers.parameters.CategoricalParameter(choices, *args, **kwargs)[source]

Bases: jina.optimizers.parameters.OptimizationParameter

Used for optimizing categorical parameters with the FlowOptimizer. For detailed information about sampling and usage see https://optuna.readthedocs.io/en/stable/reference/generated/optuna.trial.Trial.html#optuna.trial.Trial.suggest_categorical

property search_space: Dict[str, List[Optional[Union[bool, int, float, str]]]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Return type

Dict[str, List[Union[bool, int, float, str, None]]]

Return:

The parameter’s search space in dictionary form with the parameter name as key and a list of values as value

class jina.optimizers.parameters.DiscreteUniformParameter(low, high, q, *args, **kwargs)[source]

Bases: jina.optimizers.parameters.OptimizationParameter

Used for optimizing discrete parameters with the FlowOptimizer with uniform sampling. For detailed information about sampling and usage it is used by Jina with optuna see https://optuna.readthedocs.io/en/stable/reference/generated/optuna.trial.Trial.html#optuna.trial.Trial.suggest_discrete_uniform

property search_space: Dict[str, List[float]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Return type

Dict[str, List[float]]

Return:

The parameter’s search space in dictionary form with the parameter name as key and a list of values as value

class jina.optimizers.parameters.ExecutorAlternativeParameter(inner_parameters, *args, **kwargs)[source]

Bases: jina.optimizers.parameters.CategoricalParameter

Used for optimizing alternative executor parameters. It selects from choices the same way as :class::CategoricalParameter does. Plus adds some inner parameters that expose different OptimizationParameters for each of the specific options.

choices = ['executorA', 'executorB']
inner_parameters = {
        'executorA': [IntegerParameter(..., parameter_name='executorA_param1'),
            CategoricalParameter(..., parameter_name='executorA_param2')],
        'executorB': [IntegerParameter(..., parameter_name='executorB_param1'),
            CategoricalParameter(..., parameter_name='executorB_param2')]
        }

parameter = ExecutorAlternativeParameter(choices=choices, inner_parameters=inner_parameters)
property search_space: Dict[str, List[Any]]

Get the parameter’s search space, i.e. a dictionary mapping the parameter name to a list of possible values for the parameter.

Return type

Dict[str, List[Any]]

Return:

The parameter’s search space in dictionary form with the parameter name as key and a list of values as value

update_trial_params(trial, trial_params)[source]

Update the trial parameters given the variables and the trials

Parameters
  • trial (Trial) – An instance of an Optuna Trial object

  • trial_params (Dict) – the parameters to update # noqa: DAR201

jina.optimizers.parameters.load_optimization_parameters(filepath)[source]

Loads optimization parameters from a .yml file and parses it with the JAML parser. :type filepath: str :param filepath: Path to a file that contains optimization parameters. :return:: The loaded OptimizationParameter objects.