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.0186556150388997, (x - 2)^2: 0.00034803197247961973

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.0186556150388997}

To get the best observed value of the objective function:

study.best_value

Out:

0.00034803197247961973

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=15, values=[0.00034803197247961973], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 990467), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 993007), params={'x': 2.0186556150388997}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=15, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[12.913796067613912], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 969348), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 969709), params={'x': -1.593577057419795}, 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=[9.498541106193843], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 970002), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 970255), params={'x': 5.081970328571293}, 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=[17.965542783596916], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 970492), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 970728), params={'x': -2.2385779199628875}, 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=[93.730753158728], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 970957), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 971178), params={'x': -7.681464411891829}, 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=[22.367871061743802], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 971403), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 971623), params={'x': 6.729468369885119}, 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=[0.7536371616033332], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 971848), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 972069), params={'x': 2.868122780258261}, 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=[42.704087036998516], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 972294), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 972517), params={'x': -4.534836420064279}, 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=[19.602191593224575], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 972743), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 972965), params={'x': -2.427436232541873}, 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=[105.774684201909], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 973192), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 973417), params={'x': -8.28468201753992}, 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=[3.791621943281064], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 973639), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 973866), params={'x': 3.9472087569855123}, 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=[63.88629053720457], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 974090), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 978883), params={'x': 9.992889999068208}, 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.2788550154999778], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 979135), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 981735), params={'x': 2.52806724524437}, 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.13014292242449607], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 981989), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 984629), params={'x': 1.6392467291562056}, 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=[0.7104425170964553], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 984872), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 987441), params={'x': 1.1571224779978675}, 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=[31.027839583856224], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 987691), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 990227), params={'x': 7.570263870218019}, 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.00034803197247961973], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 990467), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 993007), params={'x': 2.0186556150388997}, 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=[2.6297014482142043], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 993248), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 995857), params={'x': 0.37836457604854834}, 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=[52.042168400057946], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 996097), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 14, 998650), params={'x': -5.214025810881047}, 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=[55.75786332460411], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 14, 998890), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 1443), params={'x': 9.467118810130458}, 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=[15.780222287947115], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 1682), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 4261), params={'x': 5.972432792124634}, 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=[6.26820891037494], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 4503), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 7100), params={'x': -0.5036391334165833}, 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.0013867657445081056], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 7342), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 9892), params={'x': 1.962760696240288}, 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.0298855847016705], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 10133), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 12708), params={'x': 1.8271255232786792}, 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=[4.000755265655946], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 12949), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 15542), params={'x': 4.000188807501918}, 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=[5.596185506762104], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 15785), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 18336), params={'x': -0.3656258171490485}, 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=[3.7437942554839934], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 18579), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 21134), params={'x': 3.9348886933061533}, 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=[35.034776185365075], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 21376), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 23953), params={'x': -3.9190181774822315}, 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=[0.06452709714877848], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 24216), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 26816), params={'x': 2.2540218438417816}, 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=[1.2877723673470105], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 27060), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 29659), params={'x': 0.8651994151627298}, 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=[9.898248039975572], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 29908), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 32550), params={'x': -1.1461481274688214}, 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=[12.139247084232172], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 32794), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 35451), params={'x': 5.484142230769601}, 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.26702371963995547], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 35694), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 38653), params={'x': 2.5167433789028704}, 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=[0.0887327503875014], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 38930), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 42299), params={'x': 1.702119570318053}, 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.681825861967681], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 42566), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 45235), params={'x': 4.1637527266228185}, 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=[35.58372722735538], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 45552), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 48284), params={'x': 7.965209738756499}, 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=[19.067893898525075], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 48529), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 51186), params={'x': -2.366679962915198}, 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.763368954415577], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 51433), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 54351), params={'x': 2.873709880003412}, 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.341516391528511], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 54598), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 57256), params={'x': -1.2158228171851309}, 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.636443115491996], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 57504), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 60180), params={'x': 0.37628724353967224}, 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=[6.540373255595325], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 60425), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 63475), params={'x': 4.5574153467114655}, 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=[0.8179580807538674], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 63725), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 66622), params={'x': 2.9044103497604765}, 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.03136536090010365], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 66885), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 69522), params={'x': 1.8228973153786097}, 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.004752417071297488], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 69771), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 72472), params={'x': 1.9310622231915078}, 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=[2.051770106790588], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 72721), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 75411), params={'x': 3.4324001210522805}, 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.8741823068620304], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 75659), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 78311), params={'x': 1.0650228308338057}, 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=[4.501343907218167], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 78558), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 81248), params={'x': -0.12163708188232958}, 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=[0.0009504148240497287], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 81496), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 84191), params={'x': 1.9691712013849108}, 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=[26.676942656289114], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 84439), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 87127), params={'x': -3.164972667525852}, 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=[9.767097449566554], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 87379), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 90042), params={'x': 5.125235583050749}, 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.19403436999289], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 90296), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 92978), params={'x': 6.146568987728637}, 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=[13.49094697030119], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 93231), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 95966), params={'x': -1.6730024462694262}, 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.009236802746447661], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 96219), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 98912), params={'x': 1.903891713435065}, 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.36337936310411884], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 99164), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 101834), params={'x': 1.3971904420929286}, 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=[1.8420906789119829], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 102087), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 104769), params={'x': 3.35723641231437}, 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.8596385340658175], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 105024), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 107709), params={'x': 0.6363143565814673}, 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.011708155535304566], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 107963), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 110641), params={'x': 2.1082042306719315}, 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=[1.9279308920175404], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 110896), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 113554), params={'x': 3.3884995109893055}, 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.06215984142972487], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 113806), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 116542), params={'x': 2.249318754669048}, 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=[6.814791594624332], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 116799), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 119487), params={'x': -0.6105155802301451}, 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=[7.692880149000149], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 119740), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 122407), params={'x': 4.7736041803040585}, 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=[0.8701571316445714], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 122676), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 125361), params={'x': 1.067177867091174}, 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.007698966533124891], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 125616), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 128306), params={'x': 2.087743754952275}, 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.08597069408770702], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 128561), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 131272), params={'x': 2.2932075955491382}, 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=[2.7252685503227485], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 131528), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 134225), params={'x': 0.34916125853469615}, 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=[1.2002625049419924], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 134480), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 137186), params={'x': 3.095564925023612}, 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=[0.14396895562295656], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 137441), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 140157), params={'x': 1.6205675875429768}, 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=[4.802623135079231], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 140414), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 143140), params={'x': 4.19148879419431}, 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=[3.8547695544768064], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 143394), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 146106), params={'x': 0.03664329413200962}, 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=[0.15805383492000855], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 146362), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 149091), params={'x': 2.3975598507394937}, 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=[0.0008851361801172029], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 149347), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 152114), params={'x': 2.0297512382955265}, 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=[6.8207788043896835], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 152370), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 155117), params={'x': -0.6116620769903758}, 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.023384881820669834], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 155374), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 158096), params={'x': 1.8470788378913179}, 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=[3.042440676226276], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 158354), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 161095), params={'x': 3.744259348900351}, 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.9738425044354], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 161354), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 164101), params={'x': 1.0131654118164484}, 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=[0.5308545758595583], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 164368), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 167187), params={'x': 2.728597677638049}, 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=[0.002203831143494557], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 167446), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 170174), params={'x': 2.04694497996053}, 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.26342023131004794], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 170432), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 173170), params={'x': 1.4867551935868732}, 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.138985052081914], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 173428), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 176192), params={'x': 0.5374730593654304}, 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=[138.007567134363], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 176454), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 179213), params={'x': -9.747662198682894}, 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=[0.8529594096039393], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 179472), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 182212), params={'x': 2.9235580163714348}, 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=[2.653572529224873], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 182472), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 185246), params={'x': 3.628978983665803}, 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.000943325597878924], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 185506), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 188262), params={'x': 2.030713606070908}, 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.2979487737532296], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 188523), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 191298), params={'x': 1.4541531590700285}, 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.5282690351889361], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 191561), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 194321), params={'x': 2.7268211851541864}, 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=[5.920257587830746], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 194583), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 197621), params={'x': 4.433157945516638}, 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.006502675635893903], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 197884), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 200658), params={'x': 2.080639169365104}, 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=[3.623727015294911], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 200921), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 203707), params={'x': 0.09639105504966938}, 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.09565271065736], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 203969), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 206767), params={'x': 0.9532656924236409}, 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=[11.212892811362348], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 207029), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 209797), params={'x': 5.348565784236939}, 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=[1.4425913924714888], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 210059), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 212839), params={'x': 3.2010792615275183}, 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=[8.985164306361556], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 213101), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 215906), params={'x': -0.997526364581562}, 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.004494341179943616], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 216169), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 218955), params={'x': 1.9329601522977296}, 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=[0.06658511850804283], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 219219), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 222000), params={'x': 2.2580409240954675}, 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.35089848059782486], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 222263), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 225068), params={'x': 1.4076331536979598}, 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=[1.572838608025046], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 225332), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 228124), params={'x': 0.7458713750077124}, 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=[0.3145801580438124], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 228388), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 231202), params={'x': 2.560874458362843}, 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.00036136148972181544], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 231466), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 234261), params={'x': 1.9809904894928403}, 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=[3.1413667251184982], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 234526), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 237320), params={'x': 3.772390116514561}, 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=[0.02528724050271385], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 237585), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 240395), params={'x': 1.840980376988518}, 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=[0.5099319981056549], datetime_start=datetime.datetime(2021, 5, 7, 8, 31, 15, 240659), datetime_complete=datetime.datetime(2021, 5, 7, 8, 31, 15, 243475), params={'x': 1.2859047695820571}, 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: 1.9878747626338054, (x - 2)^2: 0.00014702138118656276

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

Gallery generated by Sphinx-Gallery