Simulations Toolkits API¶
Toolkits for running and managing computational simulations.
OpenFOAM¶
OFToolkit¶
hera.simulations.openFoam.toolkit.OFToolkit
¶
Bases: hermesWorkflowToolkit
The goal of this toolkit is to provide the functions that are required to run workflows. and to mange the workflows in the DB.
This toolkit might relay on the hermes project in order to manipulate the nodes of the workflow. (TBD).
Source code in hera/simulations/openFoam/toolkit.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 404 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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | |
__init__(projectName, filesDirectory=None, connectionName=None)
¶
Initialize the OpenFOAM toolkit with solver extensions and object home.
Source code in hera/simulations/openFoam/toolkit.py
runOFSimulation(nameOrWorkflowFileOrJSONOrResource)
¶
Build the workflow and then runs the simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nameOrWorkflowFileOrJSONOrResource
|
|
required |
Source code in hera/simulations/openFoam/toolkit.py
prepareSlurmWorkflowExecution(baseConfiguration, jsonVariations, slurmExecutionFileName='submit_all.sh', caseListFileName='cases.txt', allocateProcessorsPerRun=None, memoryInGB=None, jobName='foam_cases', exclusive=False, addAllRun=True)
¶
Adds the different configurations to the workgroup,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baseConfiguration
|
dict
|
|
required |
jsonVariations
|
|
required | |
slurmExecutionFileName
|
|
'submit_all.sh'
|
|
caseListFileName
|
|
'cases.txt'
|
|
allocateProcessorsPerRun
|
int | None
|
|
None
|
memoryInGB
|
str | int | none
|
|
None
|
jobName
|
bool
|
|
'foam_cases'
|
exclusive
|
bool
|
|
False
|
addAllRun
|
|
True
|
Source code in hera/simulations/openFoam/toolkit.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
processorList(caseDirectory)
¶
Returns the list of processors directories in the case
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caseDirectory
|
str
|
Path to the directory. |
required |
Source code in hera/simulations/openFoam/toolkit.py
getHermesWorkflow_Flow(workflowfile)
¶
Returns the workflow of the requested JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowfile
|
|
required |
getMeshFromName(nameOrWorkflowFileOrJSONOrResource, readParallel=True, time=0)
¶
Returns the name from the workflow
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nameOrWorkflowFileOrJSONOrResource
|
string or dict
|
|
required |
The
|
|
required | |
readParallel
|
|
True
|
|
time
|
float
|
The time to read the mesh from. (relevant for mesh moving cases). |
0
|
Source code in hera/simulations/openFoam/toolkit.py
getMesh(caseDirectory, readParallel=True, time=0)
¶
Reads the mesh from the mesh directory.
Reads the decomposed case if it exists and parallel is true,
otherwise, reads just the single case.
Unfortunately, we have to use the OF postProcess utility in order to interpolate the
mesh points to their centers.
Returns:
| Type | Description |
|---|---|
pandas dataframe with the points in the columns x,y,z
|
the index column (don't mix up with the index of pandas) is the sequential number of the point. If the case is decomposed, return processorNumber and index columns. The index is the internal order in the processor. |
Source code in hera/simulations/openFoam/toolkit.py
getMeshExtentFromName(nameOrWorkflowFileOrJSONOrResource, readParallel=True, time=0)
¶
Returns the name from the workflow
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nameOrWorkflowFileOrJSONOrResource
|
string or dict
|
|
required |
The
|
|
required | |
readParallel
|
|
True
|
|
time
|
float
|
The time to read the mesh from. (relevant for mesh moving cases). |
0
|
Source code in hera/simulations/openFoam/toolkit.py
read_points_file(path)
¶
Parse an OpenFOAM points file and return coordinates as a numpy array.
Source code in hera/simulations/openFoam/toolkit.py
getMeshExtent(caseDirectory)
¶
Return the bounding box of the mesh from the points file.
Source code in hera/simulations/openFoam/toolkit.py
createEmptyCase(caseDirectory: str, fieldList: list, flowType: str, additionalFieldsDescription=dict())
¶
Creates an empty case directory for the simulation.
fields is a list of fields to create in the case directory.
The simulation type (copressible, incompressible, dispersion) is needed to get the dimensions and components
of the fields. If the fields are not in the standard list then their description can be supplied in the
additionalFieldsDescription parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caseDirectory
|
str
|
The case directory to create |
required |
fieldList
|
list
|
The list of field names to create |
required |
flowType
|
str
|
compressible, incompressible or dispersion. The dimension of the fields is determined by the type of simulation |
required |
additionalFieldsDescription
|
dict | str
|
Definition of additional fields: has the structure : { dimensions : {kg : .., m : ..}, componentNames : None|list ) the keys for the dimensions are kg,m,s,K,mol,A,cd Can also be a JSON file name. |
dict()
|
Source code in hera/simulations/openFoam/toolkit.py
writeEmptyField(fieldName, flowType, caseDirectory, timeOrLocation=0, readBoundaryFromCase=False, writeProcBoundary=False)
¶
Writes an empty field in the case.
If the readBoundaryField is True, then the field is written with the relevant boundaries (that are red from the case).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fieldName
|
str
|
The name of the field |
required |
flowType
|
str
|
The flow type (compressible/incompressible) |
required |
timeOrLocation
|
float[default:0]
|
The time to write the new field in |
0
|
caseDirectory
|
str
|
The name of te new case directory |
required |
readParallel
|
bool
|
If true, then attempt to write as parallel fields. |
required |
readBoundaryFromCase
|
bool
|
If True, tries to read the boundary names from the case. Otherwise write the general ".*" boundary field. |
False
|
writeProcBoundary
|
bool
|
If true writes the proc boundaries. If readBoundaryFromCase is True, then write the specific proc for each processor (when it is parallel) Otherwise, write the "proc.*" boundary field. |
False
|
Source code in hera/simulations/openFoam/toolkit.py
template_add(name, objFile, workflowObj=None)
¶
Adds a templates to the toolkit.
Templates can be
- Flow : Holds Hermes flow templates.
- Node : Holds a hermes node objects
- Field : Holds a field templates.
This can be
* xarray
* pandas/dask
* constant
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
required | |
objFile
|
|
required | |
workflowObj
|
|
None
|
Source code in hera/simulations/openFoam/toolkit.py
xarrayToSetFieldsDictDomain(xarrayData, xColumnName='x', yColumnName='y', zColumnName='z', time=None, timeColumn='time', **kwargs)
¶
Converts the xarray to the setFields dict of the internal domain.
Not debugged.
Use
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xarrayData
|
xarray dataset
|
|
required |
xColumnName
|
string
|
The coordinate name of the x-axis If None, ignore that coordinate (the mesh should be in the right dimension). |
'x'
|
yColumnName
|
The coordinate name of the y-axis If None, ignore that coordinate (the mesh should be in the right dimension). |
'y'
|
|
zColumnName
|
The coordinate name of the z-axis If None, ignore that coordinate (the mesh should be in the right dimension). |
'z'
|
|
time
|
string
|
The time is not None, select the closest (nearest neighbours). If None ignore the index. |
None
|
kwargs
|
dict
|
A mapping of OpenFoamField -> dataset Field If the dataset Field is a tuple, then write it as vector. Each component can be either a field, float (to keep fixed value). If you want to map a function, just create its value as a Field name. so U = ("u","v",0) will map the feld 'u' as Ux, 'v' as Uy and Uz=0 |
{}
|
Returns:
| Type | Description |
|---|---|
string (setField dict).
|
|
Source code in hera/simulations/openFoam/toolkit.py
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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
getVTKPipelineCacheDocuments(regularMesh=None, filterName=None, workflowName=None, groupName=None)
¶
Return the list of the cached documents in the case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regularMesh
|
|
None
|
|
filterName
|
|
None
|
Source code in hera/simulations/openFoam/toolkit.py
getVTKPipelineCacheTable(regularMesh=None, filterName=None, workflowName=None, groupName=None)
¶
Return the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regularMesh
|
|
None
|
|
filterName
|
|
None
|
|
workflowName
|
|
None
|
|
groupName
|
|
None
|
Source code in hera/simulations/openFoam/toolkit.py
clearVTKPipelineCache(regularMesh=None, filterName=None, workflowName=None, groupName=None)
¶
deletes the cache documents and the data from the disk.
Use with care!.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regularMesh
|
|
None
|
|
filterName
|
|
None
|
|
workflowName
|
|
None
|
|
groupName
|
|
None
|
Source code in hera/simulations/openFoam/toolkit.py
getTimeList(nameOrWorkflowFileOrJSONOrResourceorDirectory, singleProcessor=False, returnFirst=True)
¶
Extract the computed Time steps from the case.
Tries to load as parallel, and if fails falls to the single (unless singleProcessor is True
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nameOrWorkflowFileOrJSONOrResourceorDirectory
|
|
required | |
singleProcessor
|
|
False
|
Source code in hera/simulations/openFoam/toolkit.py
LSM¶
LSMToolkit¶
hera.simulations.LSM.toolkit.LSMToolkit
¶
Bases: abstractToolkit
The LSM.old toolkit
The datasources are the templates.
The LSM.old template JSON structure is :
<< TO DO >>
Source code in hera/simulations/LSM/toolkit.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 404 405 406 407 408 409 410 411 | |
__init__(projectName, filesDirectory=None, to_xarray=True, to_database=False, forceKeep=False, connectionName=None)
¶
Initializes the LSM.old toolkit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectName
|
The name of the project that contains the |
required | |
filesDirectory
|
The directory to save the simulations.old. |
None
|
|
to_xarray
|
Save the simulation results into xarray or not |
True
|
|
to_database
|
Save the simulation run in the database or not |
False
|
|
forceKeep
|
If to_xarray is true, determine wehter to keep the original files. if False, removes the Lagrnagian files. |
False
|
Source code in hera/simulations/LSM/toolkit.py
getTemplates(**query)
¶
Get a list of Template objects that fulfill the query
Returns:
| Type | Description |
|---|---|
List of LSMTemplates
|
|
Source code in hera/simulations/LSM/toolkit.py
getTemplateByName(templateName, templateVersion=None)
¶
Retrieve the template by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
templateName
|
|
required | |
templateVersion
|
|
None
|
Returns:
| Type | Description |
|---|---|
The template by the name
|
|
Source code in hera/simulations/LSM/toolkit.py
getTemplatesTable(**query)
¶
:list the template parameters that fulfil the query
:param query: :return:
Source code in hera/simulations/LSM/toolkit.py
loadData(fileNameOrData, saveMode=toolkit.TOOLKIT_SAVEMODE_FILEANDDB, **kwargs)
¶
Load a template object. Possibly saves to the DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fileNameOrData
|
|
required | |
saveMode
|
|
TOOLKIT_SAVEMODE_FILEANDDB
|
Returns:
| Type | Description |
|---|---|
template.LSMTemplate object
|
Return the template object. |
Source code in hera/simulations/LSM/toolkit.py
getSimulations(simulationName=None, unitsTemplateVersion='v4-general', **query)
¶
get a list of SingleSimulation objects that fulfill the query :param query: :return:
Source code in hera/simulations/LSM/toolkit.py
getSimulationsList(wideFormat=False, **query)
¶
List the Simulation parameters that fulfil the query
:param query: :return:
Source code in hera/simulations/LSM/toolkit.py
prepareSlurmLSMExecution(baseParameters, jsonVariations, templateName, filesDirectory=None, to_xarray=True, to_database=False, forceKeep=False, connectionName=None, stations=None, topography=None, depositionRates=None, canopy=None, saveMode=toolkit.TOOLKIT_SAVEMODE_FILEANDDB, slurmExecutionFileName='submit_all.sh', caseListFileName='cases.txt', allocateProcessorsPerRun=None, memoryInGB=None, jobName='lsm_cases', exclusive=False)
¶
Creates a slurm setup to run many LSM simulations against specific variation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baseParameters
|
dict
|
|
required |
jsonVariations
|
|
required | |
slurmExecutionFileName
|
|
'submit_all.sh'
|
|
caseListFileName
|
|
'cases.txt'
|
|
allocateProcessorsPerRun
|
int | None
|
|
None
|
memoryInGB
|
str | int | none
|
|
None
|
jobName
|
bool
|
|
'lsm_cases'
|
exclusive
|
bool
|
|
False
|
Source code in hera/simulations/LSM/toolkit.py
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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 404 405 406 407 408 409 410 411 | |
Wind Profile¶
WindProfileToolkit¶
hera.simulations.windProfile.toolkit.WindProfileToolkit
¶
Bases: abstractToolkit
Source code in hera/simulations/windProfile/toolkit.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
getWindProfile(xarray: xarray.DataArray, height: float, dz: float)
¶
Returns dataframe with u and v velocities in different specified heights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stations
|
Stations dataframe, with lon, lat, wind and direction columns. Direction should be in meteorological direction. |
required | |
xarray
|
DataArray
|
Xarray of stations region. |
required |
height
|
float
|
The maximum height to calculate velocities. |
required |
dz
|
float
|
Step size in meters. |
required |
Returns:
| Type | Description |
|---|---|
pd.DataFrame
|
|
Source code in hera/simulations/windProfile/toolkit.py
Gaussian Dispersion¶
gaussianToolkit¶
hera.simulations.gaussian.toolkit.gaussianToolkit
¶
Bases: abstractToolkit
Source code in hera/simulations/gaussian/toolkit.py
__init__(projectName: str, filesDirectory: str = None, connectionName=None)
¶
Initializes the toolkit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectName
|
str
|
|
required |
filesDirectory
|
str
|
|
None
|
Source code in hera/simulations/gaussian/toolkit.py
getSigmaType(sigmaName)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigmaName
|
|
required |
Source code in hera/simulations/gaussian/toolkit.py
listSigmaTypes()
¶
getGasCloud(sourceQ, sourceHeight, initialCloudSize, sigmaTypeName='briggsRural')
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sourceQ
|
(unum, method)
|
If unum: The unit determine the release time. [mass] - Instantaneous [mass/time] - Continuous else Continuous (not implementaed yet.) |
required |
sourceHeight
|
unum
|
|
required |
initialCloudSize
|
3-touple unum, the sigmas in each axis.
|
|
required |
sigmaTypeName
|
Name of the sigma type, for example from Briggs, rural/urban.
|
|
'briggsRural'
|
Returns:
| Type | Description |
|---|---|
An instance of the class gadCloud
|
|
Source code in hera/simulations/gaussian/toolkit.py
Workflow¶
hermesWorkflowToolkit¶
hera.simulations.hermesWorkflowToolkit.hermesWorkflowToolkit
¶
Bases: abstractToolkit
Manages the hermes worflows:
1. Checks if they are in the DB.
2. create a new name to them
3. allows simple deletion
4. allows simple comparison.
5. retrieve by initial name.
Source code in hera/simulations/hermesWorkflowToolkit.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 404 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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
__init__(projectName: str, filesDirectory: str = None, toolkitName: str = 'hermesWorkflowToolkit', connectionName=None)
¶
Initializes the workflow toolkit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectName
|
str
|
The project that the workflow will be used i. |
required |
filesDirectory
|
str
|
The directory to write all the Workflow and the outputs. default is current directory. |
None
|
Source code in hera/simulations/hermesWorkflowToolkit.py
listHermesSolverTemplates(solverName)
¶
Returns a list of all the templates that were loaded for that specific solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solverName
|
str
|
|
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
getHermesFlowTemplate(hermesFlowName)
¶
Get a hermes flow template
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solverName
|
|
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
listHermesNodesTemplates()
¶
Returns a list of all the templates that were loaded for that specific solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solverName
|
str
|
|
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
getHermesNodeTemplate(hermesNodeName)
¶
Get a hermes flow template
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solverName
|
|
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
getHemresWorkflowFromDocument(documentList, returnFirst=True)
¶
Return a hermes-workflow (or a list of hermes Workflow) to the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documentList
|
(list, document)
|
A hera.datalayer document or a list of documents. |
required |
returnFirst
|
bool
|
If true, return obj of only the first iterm in the list (if it is a list). |
True
|
Returns:
| Type | Description |
|---|---|
hermes workflow object (or one of its derivatives).
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
getHermesWorkflowFromJSON(workflow: Union[dict, str], name=None, resource=None)
¶
Creates a hermes workflow object from the JSON that is supplied.
The JSON can be either file name, JSON string or a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
Union[dict, str]
|
The |
required |
simulationType
|
str
|
The type of the workflow to create. |
required |
Returns:
| Type | Description |
|---|---|
hermesWorkflow object.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
updateDocumentWorkflow(document, workflow)
¶
Update a simulation document's workflow and parameters in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
MetadataFrame
|
The simulation document to update. |
required |
workflow
|
workflow
|
The workflow object whose JSON and parameters will be stored. |
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
getHermesWorkflowFromDB(nameOrWorkflowFileOrJSONOrResource: Union[dict, str, list, workflow], returnFirst=True, **query)
¶
Retrieve Workflow from the DB as hermes.workflow objects (or its derivatives).
If the workflow is string, use it as a name. If the workflow is dict,
use it as a filter on the paramters
If returnFirst is False, return a list with all the results of the query.
else, returns a single hermesworkflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
The filtering criteria. Either name, or the parameters of the flow. |
required | |
returnFirst
|
bool
|
If true, return only the first object (if found several results in the DB) |
True
|
query
|
Additional query criteria. |
{}
|
Returns:
| Type | Description |
|---|---|
list (returnFirst is False)
|
hermes workflow. |
Source code in hera/simulations/hermesWorkflowToolkit.py
getWorkflowDocumentByName(name, doctype=None, dockind='Simulations', **query)
¶
Retrieve the simulation using only the name.
For a more sophisticated retrieval (that tries to retrieve by group name and by the content of the workflow) use getWorkflowDocumentFromDB
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the workflow. |
required |
doctype
|
document type. |
None
|
|
dockind
|
Whether the document is cachaed or Simulation. |
'Simulations'
|
|
query
|
dict
|
Additional criteria. |
{}
|
Source code in hera/simulations/hermesWorkflowToolkit.py
getWorkflowDocumentFromDB(nameOrWorkflowFileOrJSONOrResource, doctype=None, dockind='Simulations', **query)
¶
Tries to find item as name, workflow directory , groupname or through the resource.
Additional queries are also applicable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nameOrWorkflowFileOrJSONOrResource
|
string or dict
|
|
required |
doctype
|
document type. |
None
|
|
dockind
|
Whether the document is cachaed or Simulation. |
'Simulations'
|
|
query
|
dict
|
Additional criteria. |
{}
|
Returns:
| Type | Description |
|---|---|
doc or empty list if not found.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
getWorkflowListDocumentFromDB(nameOrWorkflowFileOrJSONOrResource: Union[dict, str, list, workflow], **query)
¶
Returns the simulation document from the DB.
The nameOrWorkflowFileOrJSONOrResource can be either group name
Identify the simulation from :
- Resource (thedirectory name)
- Simulation name
- Its workflow
- workfolow dict.
Return the first item that was found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nameOrWorkflowFileOrJSONOrResource
|
Union[dict, str, list, workflow]
|
|
required |
Can
|
|
required | |
query
|
dict
|
Additional query cireteria to the DB. |
{}
|
Returns:
| Type | Description |
|---|---|
A document, or None if not found. .
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
getWorkflowListOfSolvers(solverName: str, **query)
¶
Returns all the documents of the requested solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solverName
|
str
|
The name of the solver |
required |
query
|
param - list
|
Additional query |
{}
|
Returns:
| Type | Description |
|---|---|
list of documnts.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
getWorkflowDocumentsInGroup(groupName: str, **kwargs)
¶
Return a list of all the simulations.old with the name as a prefic, and of the requested simuationType.
Returns the list of the documents.
If the simuationType is None use the default simuationType (WORKFLOW).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groupName
|
str
|
The prefix name of all the runs. |
required |
simulationType
|
str[optional]
|
The type of the workflow. if None, return all. |
required |
kwargs
|
|
{}
|
Returns:
| Type | Description |
|---|---|
list of mongo documents.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
findAvailableName(simulationGroup: str, **kwargs)
¶
Finds the next availabe name of that prefix. The available name is the maximal ID + 1.
we assume that the name of each run is:
<prefix name>_<id>.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulationGroup
|
str
|
The simulation group |
required |
simulationType
|
str
|
The type of the workflow. |
required |
**kwargs
|
dict
|
|
{}
|
Returns:
| Type | Description |
|---|---|
int,str
|
The new ID, The name. |
Source code in hera/simulations/hermesWorkflowToolkit.py
getworkFlowName(baseName, flowID)
staticmethod
¶
Returns the name of the flow field from the base and the
flow id.
The name is <base>_<id>
where <id> is padded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baseName
|
str
|
|
required |
flowID
|
|
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
splitWorkflowName(workflow_name: str)
staticmethod
¶
splits workflow name into base name and the flow id.
Returns:
| Type | Description |
|---|---|
base name and the flow id, both as strings
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
addWorkflowFileInGroup(workflowFilePath, write_file=False)
¶
adds the workflow to the database and assigning group based on the name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowFilePath
|
str
|
|
required |
write_file
|
bool
|
|
False
|
Source code in hera/simulations/hermesWorkflowToolkit.py
addWorkflowToGroup(workflowJSON: str, groupName: str, writeWorkflowToFile: bool = False, resource=None)
¶
Adds the workflow to the database, or updates an existing document.
If the fullName is true:
The groupOrFullName is the name of the simulation.
Hence, try to get the name from the DB. If the document exists update it with the
new data if the overwrite is True.
If the record is not in the DB, aadd it with that name.
If the fullName is False:
Check if the workflow is in the DB. If it is not,
generate a new name with the counter and add it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowJSON
|
str
|
The file name that contains the workflow. |
required |
groupName
|
str
|
The group to assign the workflow to. |
required |
fullName
|
`Treat the groupOrFullName as a full name if True. |
required | |
overwrite
|
bool
|
If true, then update the json workflow in the document if it exists. |
required |
writeWorkflowToFile
|
bool
|
If true, then write the JSON file to the disk. |
False
|
Returns:
| Type | Description |
|---|---|
The document of the new workflow.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
executeWorkflowFromDB(nameOrWorkflowFileOrJSONOrResource)
¶
Building and Executing the workflow.
Note that it is only executing the workflow.
For OpenFOAM simulations, use the runOFSimulation method that will build the case
and then run it.
Note the procedure removes the [name]_targetFiles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Can
|
|
required | |
build
|
bool [default = True]
|
If true, also builds the workflow. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
compareWorkflowObj(workflowList, longFormat: bool = False)
¶
Compares the parameters of the Workflow to each other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowList
|
list of hermes workflow objects
|
|
required |
Source code in hera/simulations/hermesWorkflowToolkit.py
compareWorkflows(Workflow: Union[list, str], longFormat: bool = False, transpose: bool = False) -> Union[dict, pandas.DataFrame]
¶
Compares two or more hermes Workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Workflow
|
(str, list)
|
|
required |
diffParams
|
|
required | |
JSON
|
|
required |
Returns:
| Type | Description |
|---|---|
pandas.DataFrame, json (depends on the input flags).
|
Return the differences between the parametrs of the requested Workflow. |
Source code in hera/simulations/hermesWorkflowToolkit.py
compareWorkflowInGroup(workflowGroup, longFormat=False, transpose=False)
¶
Compares all the Workflow in the group name
Each parameter that has different value across the workgroup is in the row, each simulation
is in the column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowGroup
|
str
|
The group name. |
required |
longFormat
|
bool
|
If True, return the results in long format rather than in a wide table. |
False
|
transpose
|
bool
|
If True return the simulation names as rows |
False
|
Returns:
| Type | Description |
|---|---|
Pandas with the difference in the parameter names.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
deleteWorkflowInGroup(workflowGroup, deepDelete=False, resetCounter=True, exclude=[])
¶
Deletes all the workflows in the group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowGroup
|
str
|
The name of the workgroup. |
required |
deepDelete
|
If true, delete the resources. |
False
|
|
resetCounter
|
bool [default = True]
|
Reset the counter of the group to 1. |
True
|
Source code in hera/simulations/hermesWorkflowToolkit.py
listWorkflows(workflowGroup: str, listNodes: bool = False, listParameters: bool = False) -> Union[pandas.DataFrame, dict]
¶
Lists all the simulations in the simulation group (of this project).
Allows additional filters using the simulationType.
If parameters is not None, return the list of parameters.
return the parameters of all the nodes if the paraleters is an empty List, or the requested parameters.
The default behaviour is to return only the parameters that are different from each other, unless allParams
is True.
The output is either pandas.DataFrame (if jsonFormat is False) or a JSON (if JSON is True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowGroup
|
str
|
The name of the group |
required |
parametersOfNodes
|
If None, just return the names of the simulations.old. Otherwise add the parameters from the requested nodes. |
required | |
allParams
|
If true, list all the parameters and not just the parameters that were different between the simulations.old. |
required | |
jsonFormat
|
If true, return JSON and not a normalized pandas.DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
pandas.DataFrame or dict
|
A list of the simulations.old and their values. |
Source code in hera/simulations/hermesWorkflowToolkit.py
listGroups(solver=None, workflowName=True)
¶
Lists all the simulation groups of the current project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
str
|
|
None
|
workflowName
|
bool
|
|
True
|
Source code in hera/simulations/hermesWorkflowToolkit.py
workflowTable(workflowGroup, longFormat=False, transpose=False)
¶
Compares all the Workflow in the group name
Each parameter that has different value across the workgroup is in the row, each simulation
is in the column.
Identical to the method compareWorkflowInGroup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflowGroup
|
str
|
The group name. |
required |
longFormat
|
bool
|
If True, return the results in long format rather than in a wide table. |
False
|
transpose
|
bool
|
If True return the simulation names as rows |
False
|
Returns:
| Type | Description |
|---|---|
Pandas with the difference in the parameter names.
|
|
Source code in hera/simulations/hermesWorkflowToolkit.py
Machine Learning¶
machineLearningDeepLearningToolkit¶
hera.simulations.machineLearningDeepLearning.toolkit.machineLearningDeepLearningToolkit
¶
Bases: abstractToolkit
The class handles machine/deep learning models.
It helps saving hyper parameters and it provide simple tools (like batch/train splitting).
Notes: * Torch models it requires pytorch installed. * SkiLearn requires scikitlearn installed.
Source code in hera/simulations/machineLearningDeepLearning/toolkit.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 | |
__init__(projectName: str, filesDirectory: str = None, connectionName=None)
¶
Initializes the machineLearning/deepLearning toolkit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectName
|
str
|
The project where the models are stored. |
required |
filesDirectory
|
str
|
The directory to write all the Workflow and the outputs. default is current directory. |
None
|
Source code in hera/simulations/machineLearningDeepLearning/toolkit.py
packTorchModelByID(modelIDorListID, packFileName)
¶
Pack one or more models, checkpoint and
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modelIDorListID
|
int/list of it
|
|
required |
packFileName
|
|
required |
Source code in hera/simulations/machineLearningDeepLearning/toolkit.py
packTorchModel(modelContainerOrListContainers, packFileName)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modelContainer
|
|
required |
Source code in hera/simulations/machineLearningDeepLearning/toolkit.py
loadPackedModel(archiveFile, overwrite=False)
¶
Loads the model to the database, and extracts the runtime data to the directory.
If the model is in the database, we will overwrite the data if the overwrite is True.
Otherwise, it will skip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archiveFile
|
|
required | |
overwrite
|
|
False
|
Source code in hera/simulations/machineLearningDeepLearning/toolkit.py
append_filesDirectory_to_pathToData(modelJSON)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modelJSON
|
|
required |
Source code in hera/simulations/machineLearningDeepLearning/toolkit.py
update_classes_filepath(modelJSON)
classmethod
¶
Recursively adds the correct files path to all the classpath of the machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modelJSON
|
dictionary to process
|
|
required |