Lightweight, versatile, and platform agnostic architecture

Optuna is entirely written in Python and has few dependencies. This means that we can quickly move to the real example once you get interested in Optuna.

Quadratic Function Example

Usually, Optuna is used to optimize hyperparameters, but as an example, let’s optimize a simple quadratic function: \((x - 2)^2\).

First of all, import optuna.

import optuna

In optuna, conventionally functions to be optimized are named objective.

def objective(trial):
    x = trial.suggest_float("x", -10, 10)
    return (x - 2) ** 2

This function returns the value of \((x - 2)^2\). Our goal is to find the value of x that minimizes the output of the objective function. This is the “optimization.” During the optimization, Optuna repeatedly calls and evaluates the objective function with different values of x.

A Trial object corresponds to a single execution of the objective function and is internally instantiated upon each invocation of the function.

The suggest APIs (for example, suggest_float()) are called inside the objective function to obtain parameters for a trial. suggest_float() selects parameters uniformly within the range provided. In our example, from \(-10\) to \(10\).

To start the optimization, we create a study object and pass the objective function to method optimize() as follows.

study = optuna.create_study()
study.optimize(objective, n_trials=100)

You can get the best parameter as follows.

best_params = study.best_params
found_x = best_params["x"]
print("Found x: {}, (x - 2)^2: {}".format(found_x, (found_x - 2) ** 2))

Out:

Found x: 2.004421833357796, (x - 2)^2: 1.9552610244116478e-05

We can see that the x value found by Optuna is close to the optimal value of 2.

Note

When used to search for hyperparameters in machine learning, usually the objective function would return the loss or accuracy of the model.

Study Object

Let us clarify the terminology in Optuna as follows:

  • Trial: A single call of the objective function

  • Study: An optimization session, which is a set of trials

  • Parameter: A variable whose value is to be optimized, such as x in the above example

In Optuna, we use the study object to manage optimization. Method create_study() returns a study object. A study object has useful properties for analyzing the optimization outcome.

To get the dictionary of parameter name and parameter values:

Out:

{'x': 2.004421833357796}

To get the best observed value of the objective function:

study.best_value

Out:

1.9552610244116478e-05

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=79, values=[1.9552610244116478e-05], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 4182), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 7168), params={'x': 2.004421833357796}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=79, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[3.783628290242227], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 764757), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 765110), params={'x': 3.9451550812832963}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=0, state=TrialState.COMPLETE, value=None), FrozenTrial(number=1, values=[39.263251483263375], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 765525), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 765798), params={'x': 8.266039537320474}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=1, state=TrialState.COMPLETE, value=None), FrozenTrial(number=2, values=[26.39105033310013], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 766161), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 766395), params={'x': -3.1372220443640675}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=2, state=TrialState.COMPLETE, value=None), FrozenTrial(number=3, values=[27.471430538388496], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 766758), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 766993), params={'x': 7.241319541717381}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=3, state=TrialState.COMPLETE, value=None), FrozenTrial(number=4, values=[7.161721040904625], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 767352), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 767587), params={'x': 4.676139204321148}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=4, state=TrialState.COMPLETE, value=None), FrozenTrial(number=5, values=[7.363501324954363], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 767959), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 768196), params={'x': 4.713577219272443}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=5, state=TrialState.COMPLETE, value=None), FrozenTrial(number=6, values=[58.250447925296506], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 768552), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 768794), params={'x': -5.63219810574231}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=6, state=TrialState.COMPLETE, value=None), FrozenTrial(number=7, values=[35.54177325035468], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 769150), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 769390), params={'x': -3.961692146559958}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=7, state=TrialState.COMPLETE, value=None), FrozenTrial(number=8, values=[20.196704329604486], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 769746), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 769989), params={'x': 6.494074357373773}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=8, state=TrialState.COMPLETE, value=None), FrozenTrial(number=9, values=[36.03664460948479], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 770340), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 770585), params={'x': 8.003052940753129}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=9, state=TrialState.COMPLETE, value=None), FrozenTrial(number=10, values=[124.62375410604551], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 770939), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 774781), params={'x': -9.16350097890646}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=10, state=TrialState.COMPLETE, value=None), FrozenTrial(number=11, values=[0.12326308099179087], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 775197), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 778106), params={'x': 2.351088423323514}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=11, state=TrialState.COMPLETE, value=None), FrozenTrial(number=12, values=[0.7611167973172344], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 778524), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 781349), params={'x': 1.1275799192377365}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=12, state=TrialState.COMPLETE, value=None), FrozenTrial(number=13, values=[1.8065616425954716], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 781769), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 784585), params={'x': 0.6559160582034054}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=13, state=TrialState.COMPLETE, value=None), FrozenTrial(number=14, values=[1.8946091359771258], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 785004), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 787818), params={'x': 0.6235519857338869}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=14, state=TrialState.COMPLETE, value=None), FrozenTrial(number=15, values=[0.007464319421631842], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 788232), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 791011), params={'x': 2.086396292869728}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=15, state=TrialState.COMPLETE, value=None), FrozenTrial(number=16, values=[11.901238521646349], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 791432), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 794291), params={'x': -1.4498171722058473}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=16, state=TrialState.COMPLETE, value=None), FrozenTrial(number=17, values=[0.4397630597341917], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 794711), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 797500), params={'x': 2.663146333575171}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=17, state=TrialState.COMPLETE, value=None), FrozenTrial(number=18, values=[12.242813122312203], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 797920), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 800730), params={'x': -1.4989731525566472}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=18, state=TrialState.COMPLETE, value=None), FrozenTrial(number=19, values=[62.994342253819624], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 801151), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 803966), params={'x': 9.936897520682727}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=19, state=TrialState.COMPLETE, value=None), FrozenTrial(number=20, values=[0.5426819079518638], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 804384), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 807177), params={'x': 2.7366694699469116}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=20, state=TrialState.COMPLETE, value=None), FrozenTrial(number=21, values=[0.17666725605230793], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 807600), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 810381), params={'x': 2.4203180415498577}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=21, state=TrialState.COMPLETE, value=None), FrozenTrial(number=22, values=[0.0020658652551558267], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 810799), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 813600), params={'x': 1.9545482095495037}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=22, state=TrialState.COMPLETE, value=None), FrozenTrial(number=23, values=[11.527933541763424], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 814024), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 816817), params={'x': -1.3952810696264049}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=23, state=TrialState.COMPLETE, value=None), FrozenTrial(number=24, values=[17.63469300528812], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 817235), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 820023), params={'x': 6.199368167389961}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=24, state=TrialState.COMPLETE, value=None), FrozenTrial(number=25, values=[0.09847262736306306], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 820448), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 823227), params={'x': 1.6861965147372275}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=25, state=TrialState.COMPLETE, value=None), FrozenTrial(number=26, values=[6.428674510503048], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 823663), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 826453), params={'x': -0.5354830921351157}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=26, state=TrialState.COMPLETE, value=None), FrozenTrial(number=27, values=[27.153157933321193], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 826872), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 829707), params={'x': -3.2108692109206878}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=27, state=TrialState.COMPLETE, value=None), FrozenTrial(number=28, values=[5.531213218629766], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 830130), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 832998), params={'x': 4.35185314563426}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=28, state=TrialState.COMPLETE, value=None), FrozenTrial(number=29, values=[69.39443210037453], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 833418), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 836281), params={'x': -6.330332052227842}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=29, state=TrialState.COMPLETE, value=None), FrozenTrial(number=30, values=[0.05894140006061574], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 836702), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 839746), params={'x': 1.7572215000033657}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=30, state=TrialState.COMPLETE, value=None), FrozenTrial(number=31, values=[0.11674720809453266], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 840170), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 843058), params={'x': 1.6583170942313141}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=31, state=TrialState.COMPLETE, value=None), FrozenTrial(number=32, values=[2.1954409245542017], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 843482), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 846363), params={'x': 3.4817020363602804}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=32, state=TrialState.COMPLETE, value=None), FrozenTrial(number=33, values=[4.904184231252135], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 846785), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 849670), params={'x': -0.2145392819392784}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=33, state=TrialState.COMPLETE, value=None), FrozenTrial(number=34, values=[13.623679629096182], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 850092), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 852993), params={'x': 5.691026907121673}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=34, state=TrialState.COMPLETE, value=None), FrozenTrial(number=35, values=[3.8666576906866257], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 853411), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 856293), params={'x': 3.9663818781423474}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=35, state=TrialState.COMPLETE, value=None), FrozenTrial(number=36, values=[0.17497118819763657], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 856894), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 860149), params={'x': 1.5817044248409546}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=36, state=TrialState.COMPLETE, value=None), FrozenTrial(number=37, values=[10.111176647220264], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 860575), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 863460), params={'x': 5.1798076431162094}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=37, state=TrialState.COMPLETE, value=None), FrozenTrial(number=38, values=[2.715450617112694], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 863899), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 866778), params={'x': 3.647862438771117}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=38, state=TrialState.COMPLETE, value=None), FrozenTrial(number=39, values=[5.087546997667964], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 867197), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 870260), params={'x': -0.2555591319377917}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=39, state=TrialState.COMPLETE, value=None), FrozenTrial(number=40, values=[21.30839504970103], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 870682), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 873635), params={'x': -2.616101715701359}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=40, state=TrialState.COMPLETE, value=None), FrozenTrial(number=41, values=[0.013869355921399588], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 874055), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 876973), params={'x': 1.8822317703223845}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=41, state=TrialState.COMPLETE, value=None), FrozenTrial(number=42, values=[0.13626196559162845], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 877394), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 880560), params={'x': 1.630863215607509}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=42, state=TrialState.COMPLETE, value=None), FrozenTrial(number=43, values=[1.2601882902567754], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 880983), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 884079), params={'x': 3.1225810840455024}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=43, state=TrialState.COMPLETE, value=None), FrozenTrial(number=44, values=[0.015574182127333773], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 884503), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 887415), params={'x': 1.8752034370371773}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=44, state=TrialState.COMPLETE, value=None), FrozenTrial(number=45, values=[2.495162496285486], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 887856), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 890791), params={'x': 0.4203916636439633}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=45, state=TrialState.COMPLETE, value=None), FrozenTrial(number=46, values=[9.658449596038077], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 891228), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 894151), params={'x': 5.107804626426519}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=46, state=TrialState.COMPLETE, value=None), FrozenTrial(number=47, values=[27.36801675550561], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 894579), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 897624), params={'x': 7.2314449968919305}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=47, state=TrialState.COMPLETE, value=None), FrozenTrial(number=48, values=[8.189362927021497], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 898054), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 900985), params={'x': -0.8617062964290199}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=48, state=TrialState.COMPLETE, value=None), FrozenTrial(number=49, values=[17.97476943430163], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 901415), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 904358), params={'x': -2.239666193735261}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=49, state=TrialState.COMPLETE, value=None), FrozenTrial(number=50, values=[0.9520062417927486], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 904787), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 907732), params={'x': 1.0242919279862708}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=50, state=TrialState.COMPLETE, value=None), FrozenTrial(number=51, values=[0.01243435010867604], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 908205), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 911096), params={'x': 2.1115094171300166}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=51, state=TrialState.COMPLETE, value=None), FrozenTrial(number=52, values=[0.07600796821315059], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 911524), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 914474), params={'x': 2.2756954265365144}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=52, state=TrialState.COMPLETE, value=None), FrozenTrial(number=53, values=[2.555729826581767], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 914906), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 917847), params={'x': 0.4013349861269351}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=53, state=TrialState.COMPLETE, value=None), FrozenTrial(number=54, values=[1.1848037515317698], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 918276), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 921204), params={'x': 3.0884869092146996}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=54, state=TrialState.COMPLETE, value=None), FrozenTrial(number=55, values=[0.17758269295195594], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 921631), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 924618), params={'x': 2.4214056157100377}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=55, state=TrialState.COMPLETE, value=None), FrozenTrial(number=56, values=[5.993476960200942], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 925047), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 927979), params={'x': 4.448157870767517}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=56, state=TrialState.COMPLETE, value=None), FrozenTrial(number=57, values=[0.6229283989086767], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 928412), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 931342), params={'x': 1.2107418680123234}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=57, state=TrialState.COMPLETE, value=None), FrozenTrial(number=58, values=[0.00017273466180060823], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 931855), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 934756), params={'x': 1.9868571440774614}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=58, state=TrialState.COMPLETE, value=None), FrozenTrial(number=59, values=[2.9947501582698646], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 935187), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 938384), params={'x': 3.730534645209354}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=59, state=TrialState.COMPLETE, value=None), FrozenTrial(number=60, values=[2.175277254405778], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 938816), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 941756), params={'x': 0.5251178845732185}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=60, state=TrialState.COMPLETE, value=None), FrozenTrial(number=61, values=[0.043151101446675506], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 942190), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 945327), params={'x': 2.207728431965091}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=61, state=TrialState.COMPLETE, value=None), FrozenTrial(number=62, values=[0.23878041630847566], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 945760), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 948726), params={'x': 2.488651630825556}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=62, state=TrialState.COMPLETE, value=None), FrozenTrial(number=63, values=[0.8585123553294631], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 949162), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 952137), params={'x': 1.0734405818678097}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=63, state=TrialState.COMPLETE, value=None), FrozenTrial(number=64, values=[8.585361336009754], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 952593), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 955555), params={'x': -0.9300787252239067}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=64, state=TrialState.COMPLETE, value=None), FrozenTrial(number=65, values=[1.1006303662610455], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 956008), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 958954), params={'x': 3.0491093204528523}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=65, state=TrialState.COMPLETE, value=None), FrozenTrial(number=66, values=[0.0015839575140126816], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 959389), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 962393), params={'x': 2.0397989637303873}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=66, state=TrialState.COMPLETE, value=None), FrozenTrial(number=67, values=[115.7802257174499], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 962830), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 965813), params={'x': -8.76012201220088}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=67, state=TrialState.COMPLETE, value=None), FrozenTrial(number=68, values=[4.010732528596642], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 966249), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 969236), params={'x': -0.0026813347601364335}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=68, state=TrialState.COMPLETE, value=None), FrozenTrial(number=69, values=[7.756650148942116], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 969678), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 972689), params={'x': 4.785076327309921}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=69, state=TrialState.COMPLETE, value=None), FrozenTrial(number=70, values=[3.984238901981982], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 973127), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 976112), params={'x': 3.9960558363888476}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=70, state=TrialState.COMPLETE, value=None), FrozenTrial(number=71, values=[0.10908794126009268], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 976550), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 979508), params={'x': 1.66971536326966}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=71, state=TrialState.COMPLETE, value=None), FrozenTrial(number=72, values=[0.27583631095185346], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 979965), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 982954), params={'x': 2.525201209968002}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=72, state=TrialState.COMPLETE, value=None), FrozenTrial(number=73, values=[0.013868003041943747], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 983391), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 986370), params={'x': 1.882237514284286}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=73, state=TrialState.COMPLETE, value=None), FrozenTrial(number=74, values=[1.0370639083539313], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 986808), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 989809), params={'x': 0.9816366520961533}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=74, state=TrialState.COMPLETE, value=None), FrozenTrial(number=75, values=[1.0299337908979154], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 990246), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 993308), params={'x': 3.0148565371016316}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=75, state=TrialState.COMPLETE, value=None), FrozenTrial(number=76, values=[0.0005070780426068138], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 993749), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 10, 996778), params={'x': 1.9774816065713645}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=76, state=TrialState.COMPLETE, value=None), FrozenTrial(number=77, values=[2.4118730397017547], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 10, 997217), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 233), params={'x': 3.553020617925517}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=77, state=TrialState.COMPLETE, value=None), FrozenTrial(number=78, values=[3.5403810717825555], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 742), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 3743), params={'x': 0.11840996181884633}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=78, state=TrialState.COMPLETE, value=None), FrozenTrial(number=79, values=[1.9552610244116478e-05], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 4182), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 7168), params={'x': 2.004421833357796}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=79, state=TrialState.COMPLETE, value=None), FrozenTrial(number=80, values=[0.6919890810873542], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 7611), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 10633), params={'x': 1.168141189210961}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=80, state=TrialState.COMPLETE, value=None), FrozenTrial(number=81, values=[0.0015787447264529908], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 11076), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 14154), params={'x': 1.9602665792253802}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=81, state=TrialState.COMPLETE, value=None), FrozenTrial(number=82, values=[0.016859851348682234], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 14598), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 17622), params={'x': 2.1298454902901223}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=82, state=TrialState.COMPLETE, value=None), FrozenTrial(number=83, values=[0.6770041897475488], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 18065), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 21100), params={'x': 2.8228026432550815}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=83, state=TrialState.COMPLETE, value=None), FrozenTrial(number=84, values=[1.6087174641396997], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 21546), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 24650), params={'x': 0.7316477365732736}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=84, state=TrialState.COMPLETE, value=None), FrozenTrial(number=85, values=[0.38560417710572176], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 25113), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 28183), params={'x': 1.3790296487707954}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=85, state=TrialState.COMPLETE, value=None), FrozenTrial(number=86, values=[6.565347350475073], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 28642), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 31708), params={'x': -0.5622933771282075}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=86, state=TrialState.COMPLETE, value=None), FrozenTrial(number=87, values=[1.9824673177808394], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 32160), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 35214), params={'x': 3.4080011781887256}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=87, state=TrialState.COMPLETE, value=None), FrozenTrial(number=88, values=[3.9325795871024947], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 35680), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 38701), params={'x': 3.9830732682133796}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=88, state=TrialState.COMPLETE, value=None), FrozenTrial(number=89, values=[0.003932568245749478], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 39149), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 42182), params={'x': 1.937289807481164}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=89, state=TrialState.COMPLETE, value=None), FrozenTrial(number=90, values=[0.7071673691084783], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 42647), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 45710), params={'x': 2.8409324402759584}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=90, state=TrialState.COMPLETE, value=None), FrozenTrial(number=91, values=[0.0029427895666521153], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 46155), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 49198), params={'x': 1.9457525155730506}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=91, state=TrialState.COMPLETE, value=None), FrozenTrial(number=92, values=[1.6454747673031924], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 49647), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 52729), params={'x': 0.7172393959498162}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=92, state=TrialState.COMPLETE, value=None), FrozenTrial(number=93, values=[0.006211954030873771], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 53177), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 56431), params={'x': 2.0788159503582477}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=93, state=TrialState.COMPLETE, value=None), FrozenTrial(number=94, values=[0.31425803489598786], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 56877), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 59943), params={'x': 1.4394127767278424}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=94, state=TrialState.COMPLETE, value=None), FrozenTrial(number=95, values=[3.089397559279363], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 60391), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 63466), params={'x': 0.24233178350424645}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=95, state=TrialState.COMPLETE, value=None), FrozenTrial(number=96, values=[0.4201629942112357], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 63932), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 66973), params={'x': 2.6481998104066644}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=96, state=TrialState.COMPLETE, value=None), FrozenTrial(number=97, values=[5.2527688993024855], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 67420), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 70481), params={'x': 4.291891991194717}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=97, state=TrialState.COMPLETE, value=None), FrozenTrial(number=98, values=[1.4291287964110402], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 70928), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 74026), params={'x': 3.195461750291928}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=98, state=TrialState.COMPLETE, value=None), FrozenTrial(number=99, values=[12.751761311981149], datetime_start=datetime.datetime(2021, 10, 4, 6, 39, 11, 74475), datetime_complete=datetime.datetime(2021, 10, 4, 6, 39, 11, 77562), params={'x': 5.570960838763308}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=99, state=TrialState.COMPLETE, value=None)]

To get the number of trials:

len(study.trials)

Out:

100

By executing optimize() again, we can continue the optimization.

study.optimize(objective, n_trials=100)

To get the updated number of trials:

len(study.trials)

Out:

200

As the objective function is so easy that the last 100 trials don’t improve the result. However, we can check the result again:

best_params = study.best_params
found_x = best_params["x"]
print("Found x: {}, (x - 2)^2: {}".format(found_x, (found_x - 2) ** 2))

Out:

Found x: 2.004421833357796, (x - 2)^2: 1.9552610244116478e-05

Total running time of the script: ( 0 minutes 0.713 seconds)

Gallery generated by Sphinx-Gallery