feijoa.jobs package#

Submodules#

feijoa.jobs.job module#

Job class module.

class feijoa.jobs.job.Job(name, storage, search_space, job_id, loaded=False, **kwargs)#

Bases: object

Facade of framework, contains main logic of optimization process.

Example

from feijoa.jobs import Job
from feijoa.storages.rdb.storage import RDBStorage
from feijoa.search.space import SearchSpace
from feijoa.search.bandit import ThompsonSampler

job = Job(
    name="foo_job",
    storage=RDBStorage("sqlite:///:memory:"),
    search_space=SearchSpace(),
    job_id=1,
)
Parameters
  • name (str) – Name of job.

  • storage (Storage) – Storage instance, which will be used to save the results

  • search_space (SearchSpace) – Search space of optimization problem.

  • optimizer (MetaOracle) – Optimizer, which will be used to oracles manipulation.

  • job_id (int) –

Raises

AnyError – If anything bad happens.

add_algorithm(oracle)#

Add oracle to job’s optimizer

Parameters

oracle (Oracle) – search oracle instance.

Returns

None

Raises

AnyError – If anything bad happens.

add_seed(seed)#

Add seed configuration to current job.

Parameters

seed (dict) – Seed configuration, which must be measured immediately.

Returns

None

Raises

AnyError – If anything bad happens.

ask(n)#

Ask for a new experiment.

Parameters

n (int) – Preferred count of experiments:

Return type

Optional[List[feijoa.models.experiment.Experiment]]

Note

n may not affect on experiments count.

Returns

None

Raises

AnyError – If anything bad happens.

Parameters

n (int) –

Return type

Optional[List[feijoa.models.experiment.Experiment]]

property best_experiment: Optional[feijoa.models.experiment.Experiment]#

Get the best experiment from job.

Returns

Best experiment of optimization session.

Raises

AnyError – If anything bad happens.

property best_parameters: Optional[dict]#

Get the best parameters in job. Load configurations with result and take params from best.

Returns

The best parameters’ dict.

Raises

AnyError – If anything bad happens.

property best_value: Optional[Any]#

Get the best result value by objective.

Returns

Float best objective function value.

Raises

AnyError – If anything bad happens.

property dataframe#

Get dataframe property.

do(objective, n_trials=100, n_jobs=1, n_points_iter=1, optimizer='', progress_bar=True, use_numba_jit=False, seed=None)#

Do optimization for current job.

Example

from feijoa import create_job
from feijoa import Experiment
from feijoa import Real
from feijoa import SearchSpace


def objective(experiment: Experiment):
    x = experiment.params.get("x")
    y = experiment.params.get("y")
    return (
        (1.5 - x + x * y) ** 2
        + (2.25 - x + x * y**2) ** 2
        + (2.625 - x + x * y**3) ** 2
    )


space = SearchSpace()

space.insert(Real("x", low=0.0, high=5.0))
space.insert(Real("y", low=0.0, high=2.0))

job = create_job(search_space=space)
job.do(objective, n_trials=50)
Parameters
  • objective (Callable) – Objective function.

  • n_trials (int) – Number of total runs.

  • n_jobs (int) – Job’s count parallelization with joblib backend. if -1 passed => used max of CPU’s.

  • optimizer (str) – Optimizer according to feijoa’s optimizer’s spec.

  • n_points_iter (int) – The preferred number of configurations in one epoch. May have no effect for some oracles.

  • progress_bar (bool) – Show progress bar (rich) or not.

  • use_numba_jit (bool) – Use numba for objective evaluation speedup.

  • seed (int | None) – Random seed

Returns

None

Raises

AnyError – If anything bad happens.

property experiments: List[feijoa.models.experiment.Experiment]#

Get all experiments.

Returns

List of experiments.

Raises

AnyError – If anything bad happens.

property experiments_count: int#

Get job experiments count.

Returns

Experiments count.

Raises

AnyError – If anything bad happens.

get_dataframe(brief=False, desc=False, only_good=False)#

Make dataframe for current job.

Parameters
  • brief (bool) – Make brief report without additional information.

  • desc (bool) – Fetch only descending by objective function values experiments.

  • only_good (bool) – Fetch only correct (state=’OK’) experiments.

Returns

Pandas dataframe, contains all information about optimization session.

Raises

AnyError – If anything bad happens.

property rewards#

Obtaining the results of a strictly monotonically decreasing sequence for objective function values.

Returns

Length of monotonically decreasing sequence for objective function values

Raises

AnyError – If anything bad happens.

static setup_default_algo()#

Setup default optimization oracle (bayesian).

Raises

AnyError – If anything bad happens.

tell(experiment, result, force=False)#

Finish concrete experiment and results to oracles.

Parameters
  • experiment (Experiment) – Specified experiment.

  • result (Union[float, Result]) – Result for current experiment.

  • force (bool) – Force result (suppress tell exceptions to optimizer)

Returns

None

Raises

AnyError – If anything bad happens.

top_experiments(n)#

Get top-n experiments by objective.

Parameters

n (int) – Max count of top experiments.

Returns

List of top-experiments sorted by objective value.

Raises

AnyError – If anything bad happens.

feijoa.jobs.job.create_job(*, search_space, name=None, storage=None, **kwargs)#

Create job instance with specified parameters.

Example

from feijoa import create_job
from feijoa import SearchSpace

space = SearchSpace()

job = create_job(search_space=space)
Parameters
Returns

Job instance.

Raises

AnyError – If anything bad happens.

feijoa.jobs.job.load_job(*, name, storage=None, **kwargs)#

Load existed job instance with specified parameters.

Example

from feijoa import load_job
from feijoa import SearchSpace

# job must be in storage

job = load_job(name="foo", storage="sqlite:///:memory:")
Parameters
Returns

Job instance.

Raises

AnyError – If anything bad happens.

Module contents#