Xopt
xopt.Xopt ¶
Xopt(*args, **kwargs)
Bases: XoptBaseModel
Object to handle a single optimization problem.
Xopt is designed for managing a single optimization problem by unifying the definition, configuration, and execution of optimization tasks. It combines the Variables, Objective, Constraints, Statics (VOCS) definition with a generator for candidate generation and an evaluator for objective function evaluations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vocs
|
VOCS
|
VOCS object for defining the problem's variables, objectives, constraints, and statics. |
required |
generator
|
SerializeAsAny[Generator]
|
An object responsible for generating candidates for optimization. |
required |
evaluator
|
SerializeAsAny[Evaluator]
|
An object used for evaluating candidates generated by the generator. |
required |
strict
|
bool
|
A flag indicating whether exceptions raised during evaluation should stop the optimization process. |
required |
dump_file
|
str
|
An optional file path for dumping attributes of the xopt object and the results of evaluations. |
required |
max_evaluations
|
int
|
An optional maximum number of evaluations to perform. If set, the optimization process will stop after reaching this limit. |
required |
data
|
DataFrame
|
An optional DataFrame object for storing internal data related to the optimization process. |
required |
serialize_torch
|
bool
|
A flag indicating whether Torch (PyTorch) models should be serialized when saving them. |
required |
serialize_inline
|
bool
|
A flag indicating whether Torch models should be stored via binary string directly inside the main configuration file. |
required |
Methods:
Name | Description |
---|---|
step |
Executes one optimization cycle, generating candidates, submitting them for evaluation, waiting for evaluation results, and updating data storage. |
run |
Runs the optimization process until the specified stopping criteria are met, such as reaching the maximum number of evaluations. |
evaluate |
Evaluates a candidate without storing data. |
evaluate_data |
Evaluates a set of candidates, adding the results to the internal DataFrame. |
add_data |
Adds new data to the internal DataFrame and the generator's data. |
reset_data |
Resets the internal data by clearing the DataFrame. |
random_evaluate |
Generates random inputs using the VOCS and evaluates them, adding the data to Xopt. |
yaml |
Serializes the Xopt configuration to a YAML string. |
dump |
Dumps the Xopt configuration to a specified file. |
dict |
Provides a custom dictionary representation of the Xopt configuration. |
json |
Serializes the Xopt configuration to a JSON string. |
Initialize Xopt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
tuple
|
Positional arguments; a single YAML string can be passed as the only argument to initialize Xopt. |
()
|
kwargs
|
dict
|
Keyword arguments for initializing Xopt. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If both a YAML string and keyword arguments are specified during initialization. If more than one positional argument is provided. |
Notes
- If a single YAML string is provided in the
args
argument, it is deserialized into keyword arguments usingyaml.safe_load
. - When using the YAML string for initialization, no additional keyword arguments are allowed.
Source code in xopt/base.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
Functions¶
xopt.Xopt.add_data ¶
add_data(new_data)
Concatenate new data to the internal DataFrame and add it to the generator's data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_data
|
DataFrame
|
New data to be added to the internal DataFrame. |
required |
Source code in xopt/base.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
xopt.Xopt.dict ¶
dict(**kwargs)
Handle custom dictionary generation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments for customizing the dictionary generation. |
{}
|
Returns:
Type | Description |
---|---|
Dict
|
A dictionary representation of the Xopt configuration. |
Source code in xopt/base.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
xopt.Xopt.dump ¶
dump(file=None, **kwargs)
Dump data to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
str
|
The path to the file where the Xopt configuration will be dumped. |
None
|
**kwargs
|
Additional keyword arguments for customizing the dump. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If no dump file is specified via argument or in the |
Source code in xopt/base.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
xopt.Xopt.evaluate ¶
evaluate(input_dict)
Evaluate a candidate without storing data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict
|
Dict
|
A dictionary representing the input data for candidate evaluation. |
required |
Returns:
Type | Description |
---|---|
Any
|
The result of the evaluation. |
Source code in xopt/base.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
xopt.Xopt.evaluate_data ¶
evaluate_data(input_data)
Evaluate data using the evaluator and wait for results.
This method evaluates a set of candidates and adds the results to the internal DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
Union[pd.DataFrame, List[Dict[str, float], Dict[str, List[float],
|
The input data for evaluation, which can be provided as a DataFrame, a list of dictionaries, or a single dictionary. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
The results of the evaluations added to the internal DataFrame. |
Source code in xopt/base.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
xopt.Xopt.json ¶
json(**kwargs)
Handle custom serialization of generators and DataFrames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments for customizing serialization. |
{}
|
Returns:
Type | Description |
---|---|
str
|
The Xopt configuration serialized as a JSON string. |
Source code in xopt/base.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
|
xopt.Xopt.random_evaluate ¶
random_evaluate(n_samples=None, seed=None, custom_bounds=None)
Convenience method to generate random inputs using VOCs and evaluate them.
This method generates random inputs using the Variables, Objectives, Constraints, and Statics (VOCS) and evaluates them, adding the data to the Xopt object and generator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples
|
int
|
The number of random samples to generate. |
None
|
seed
|
int
|
The random seed for reproducibility. |
None
|
custom_bounds
|
dict
|
Dictionary of vocs-like ranges for random sampling |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
The results of the evaluations added to the internal DataFrame. |
Source code in xopt/base.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
xopt.Xopt.remove_data ¶
remove_data(indices, inplace=True)
Removes data from the X.data
data storage attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices
|
list[int]
|
List of indices specifying the rows (steps) to remove from data. |
required |
inplace
|
bool
|
Whether to update data inplace. If False, returns a copy. |
True
|
Returns:
Type | Description |
---|---|
DataFrame or None
|
A copy of the internal DataFrame with the specified rows removed or None if inplace is True. |
Source code in xopt/base.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
xopt.Xopt.reset_data ¶
reset_data()
Reset the internal data by clearing the DataFrame.
Source code in xopt/base.py
368 369 370 371 372 373 374 |
|
xopt.Xopt.run ¶
run()
Run until the maximum number of evaluations is reached or the generator is done.
Source code in xopt/base.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
xopt.Xopt.step ¶
step()
Run one optimization cycle.
This method performs the following steps: - Determines the number of candidates to request from the generator. - Passes the candidate request to the generator. - Submits candidates to the evaluator. - Waits until all evaluations are finished - Updates data storage and generator data storage (if applicable).
Source code in xopt/base.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
xopt.Xopt.yaml ¶
yaml(**kwargs)
Serialize the Xopt configuration to a YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments for customizing serialization. |
{}
|
Returns:
Type | Description |
---|---|
str
|
The Xopt configuration serialized as a YAML string. |
Source code in xopt/base.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|