Genesis4¶
genesis.Genesis4 ¶
Genesis4(input=None, lattice='', *, workdir=None, output=None, alias=None, units=None, command=None, command_mpi=None, use_mpi=False, mpi_run='', use_temp_dir=True, verbose=tools.global_display_options.verbose >= 1, timeout=None, initial_particles=None, initial_field=None, **kwargs)
Bases: CommandWrapper
Genesis 4 command wrapper for Python-defined configurations and lattices.
Files will be written into a temporary directory within workdir. If workdir=None, a location will be determined by the system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
MainInput, Genesis4Input, str, or pathlib.Path
|
Input settings for the Genesis 4 run. This may be a full configuration
( |
None
|
lattice |
(Lattice, str or Path)
|
Lattice file source code or path to a lattice file.
Not required if |
''
|
command |
str
|
The command to run to execute Genesis 4. |
"genesis4"
|
command_mpi |
str
|
The Genesis 4 executable to run under MPI. |
"genesis4"
|
use_mpi |
bool
|
Enable parallel processing with MPI. |
False
|
mpi_run |
str
|
The template for invoking |
""
|
use_temp_dir |
bool
|
Whether or not to use a temporary directory to run the process. |
True
|
workdir |
path - like
|
The work directory to be used. |
None
|
verbose |
bool
|
Whether or not to produce verbose output.
Defaults to |
verbose >= 1
|
timeout |
float
|
The timeout in seconds to be used when running Genesis. |
None
|
initial_particles |
ParticleGroup or Genesis4ParticleData
|
Initial particles to use in the simulation, using the OpenPMD-beamphysics standard. |
None
|
initial_field |
FieldFile
|
Initial Genesis 4 format field file to use in the simulation. Use
|
None
|
Source code in genesis/version4/run.py
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 |
|
Attributes¶
genesis.Genesis4.initial_field
property
writable
¶
initial_field
Initial field, if defined. Property is alias for .input.main.initial_field
.
genesis.Genesis4.initial_particles
property
writable
¶
initial_particles
Initial particles, if defined. Property is alias for .input.main.initial_particles
.
genesis.Genesis4.input
property
writable
¶
input
The Genesis 4 input, including namelists and lattice information.
Functions¶
genesis.Genesis4.archive ¶
archive(dest)
Archive the latest run, input and output, to a single HDF5 file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dest |
filename or Group
|
|
required |
Source code in genesis/version4/run.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
|
genesis.Genesis4.configure ¶
configure()
Configure and set up for run.
Source code in genesis/version4/run.py
300 301 302 303 304 305 306 307 308 |
|
genesis.Genesis4.from_archive
classmethod
¶
from_archive(arch)
Create a new Genesis4 object from an archive file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch |
filename or Group
|
|
required |
Source code in genesis/version4/run.py
616 617 618 619 620 621 622 623 624 625 626 627 628 |
|
genesis.Genesis4.get_executable ¶
get_executable()
Gets the full path of the executable from .command, .command_mpi Will search environmental variables: Genesis4.command_env='GENESIS4_BIN' Genesis4.command_mpi_env='GENESIS4_BIN'
Source code in genesis/version4/run.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
|
genesis.Genesis4.get_run_prefix ¶
get_run_prefix()
Get the command prefix to run Genesis (e.g., 'mpirun' or 'genesis4').
Source code in genesis/version4/run.py
448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
genesis.Genesis4.get_run_script ¶
get_run_script(write_to_path=True)
Assembles the run script using self.mpi_run string of the form: 'mpirun -n {n} {command_mpi}' Optionally writes a file 'run' with this line to path.
mpi_exe could be a complicated string like: 'srun -N 1 --cpu_bind=cores {n} {command_mpi}' or 'mpirun -n {n} {command_mpi}'
Source code in genesis/version4/run.py
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 |
|
genesis.Genesis4.input_parser
staticmethod
¶
input_parser(path)
Invoke the specialized main input parser and returns the MainInput
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str or Path
|
Path to the main input file. |
required |
Returns:
Type | Description |
---|---|
MainInput
|
|
Source code in genesis/version4/run.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
|
genesis.Genesis4.lattice_parser
staticmethod
¶
lattice_parser(path)
Invoke the specialized lattice input parser and returns the Lattice
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str or Path
|
Path to the lattice input file. |
required |
Returns:
Type | Description |
---|---|
Lattice
|
|
Source code in genesis/version4/run.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
|
genesis.Genesis4.load_archive ¶
load_archive(arch)
Load an archive from a single HDF5 file into this Genesis4 object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch |
filename or Group
|
|
required |
Source code in genesis/version4/run.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
genesis.Genesis4.load_output ¶
load_output(load_fields=False, load_particles=False, smear=True)
Load the Genesis 4 output files from disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
load_fields |
bool
|
Load all field files. |
True
|
load_particles |
bool
|
Load all particle files. |
True
|
smear |
bool
|
If set, this will smear the particle phase over the sample (skipped) slices, preserving the modulus. |
True
|
Returns:
Type | Description |
---|---|
Genesis4Output
|
|
Source code in genesis/version4/run.py
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 |
|
genesis.Genesis4.load_raw_h5_output ¶
load_raw_h5_output()
Load the unprocessed Genesis 4 HDF5 file from the last run.
Returns:
Type | Description |
---|---|
File
|
|
Source code in genesis/version4/run.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
|
genesis.Genesis4.plot ¶
plot(y='field_energy', x='zplot', xlim=None, ylim=None, ylim2=None, yscale='linear', yscale2='linear', y2=[], nice=True, include_layout=True, include_legend=True, return_figure=False, tex=False, **kwargs)
Plots output multiple keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y |
list
|
List of keys to be displayed on the Y axis |
'field_energy'
|
x |
str
|
Key to be displayed as X axis |
'zplot'
|
xlim |
list
|
Limits for the X axis |
None
|
ylim |
list
|
Limits for the Y axis |
None
|
ylim2 |
list
|
Limits for the secondary Y axis |
None
|
yscale |
one of "linear", "log", "symlog", "logit", ... for the Y axis |
'linear'
|
|
yscale2 |
one of "linear", "log", "symlog", "logit", ... for the secondary Y axis |
'linear'
|
|
y2 |
list
|
List of keys to be displayed on the secondary Y axis |
[]
|
nice |
bool
|
Whether or not a nice SI prefix and scaling will be used to make the numbers reasonably sized. Default: True |
True
|
include_layout |
bool
|
Whether or not to include a layout plot at the bottom. Default: True Whether or not the plot should include the legend. Default: True |
True
|
return_figure |
bool
|
Whether or not to return the figure object for further manipulation. Default: True |
False
|
kwargs |
dict
|
Extra arguments can be passed to the specific plotting function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
The plot figure for further customizations or |
Source code in genesis/version4/run.py
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 |
|
genesis.Genesis4.run ¶
run(load_fields=False, load_particles=False, smear=True, raise_on_error=True)
Execute Genesis 4 with the configured input settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
load_fields |
bool
|
After execution, load all field files. |
False
|
load_particles |
bool
|
After execution, load all particle files. |
False
|
smear |
bool
|
If set, for particles, this will smear the phase over the sample (skipped) slices, preserving the modulus. |
True
|
raise_on_error |
bool
|
If Genesis 4 fails to run, raise an error. Depending on the error,
output information may still be accessible in the |
True
|
Returns:
Type | Description |
---|---|
Genesis4Output
|
The output data. This is also accessible as |
Source code in genesis/version4/run.py
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 |
|
genesis.Genesis4.stat ¶
stat(key)
Calculate a statistic of the beam or field along z.
Source code in genesis/version4/run.py
768 769 770 771 772 773 774 775 776 |
|
genesis.Genesis4.write_input ¶
write_input(path=None, write_run_script=True)
Write the input parameters into the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The directory to write the input parameters |
None
|
Source code in genesis/version4/run.py
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 |
|
genesis.Genesis4.write_run_script ¶
write_run_script(path=None)
Write the 'run' script which can be used in a terminal to launch Genesis.
This is also performed automatically in write_input
and
get_run_script
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path or str
|
Where to write the run script. Defaults to |
None
|
Returns:
Type | Description |
---|---|
Path
|
The run script location. |
Source code in genesis/version4/run.py
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 |
|
genesis.version4.Genesis4Input ¶
Genesis4Input(**data)
Bases: BaseModel
All Genesis 4-related command input.
Attributes:
Name | Type | Description |
---|---|---|
main |
MainInput
|
The main input. This contains all the namelists, starting with
|
lattice |
Lattice
|
The lattice definition. |
beamline |
(str, optional)
|
Optional override for |
lattice_name |
(str, optional)
|
Optional override for |
seed |
(str, optional)
|
Optional override for |
output_path |
Optional[AnyPath] = None
|
Optional override for |
source_path |
Optional[AnyPath] = None
|
When using Genesis 4-compatible input as strings, this is the directory where we expect to find other input HDF5 files. |
input_filename |
str = "genesis4.in"
|
The filename to use when writing the main input file. As a user, you should not need to worry about this as Genesis4Input will handle it for you. |
initial_particles |
(ParticleGroup, optional)
|
OpenPMD ParticleGroup to use as the initial Genesis 4 particle
distribution. If set, this acts as a shortcut for automatically adding
an |
initial_field |
(FieldFile, optional)
|
Initial Genesis 4 format field file to use in the simulation. Use
|
Source code in genesis/version4/input/core.py
1003 1004 1005 1006 1007 1008 |
|
Attributes¶
genesis.version4.Genesis4Input.arguments
property
¶
arguments
Get all of the command-line arguments for running Genesis 4.
Returns:
Type | Description |
---|---|
list of str
|
Individual arguments to pass to Genesis 4. |
genesis.version4.Genesis4Input.lattice_filename
property
¶
lattice_filename
The filename of the lattice, determined from the Setup namelist.
Defaults to "genesis.lat" if not previously set.
Functions¶
genesis.version4.Genesis4Input.archive ¶
archive(h5)
Dump input data into the given HDF5 group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h5 |
Group
|
The HDF5 file in which to write the information. |
required |
Source code in genesis/version4/input/core.py
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 |
|
genesis.version4.Genesis4Input.from_archive
classmethod
¶
from_archive(h5)
Loads input from archived h5 file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h5 |
str or File
|
The filename or handle on h5py.File from which to load data. |
required |
Source code in genesis/version4/input/core.py
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 |
|
genesis.version4.Genesis4Input.from_main_input
classmethod
¶
from_main_input(main, lattice='', *, source_path=None)
Work with a lume-genesis MainInput and potentially an external lattice file or instance.
If the input refers to files that already exist on disk, ensures
that source_path
is set correctly.
Source code in genesis/version4/input/core.py
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 |
|
genesis.version4.Genesis4Input.from_strings
classmethod
¶
from_strings(main, lattice='', *, source_path=pathlib.Path('.'), input_filename=None, lattice_filename=None)
Work directly with Genesis 4-compatible inputs.
If unspecified, lattice
will be determined from the main
input
settings.
If the input refers to files that already exist on disk, ensures
that source_path
is set correctly.
Source code in genesis/version4/input/core.py
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 |
|
genesis.version4.Genesis4Input.write ¶
write(workdir=pathlib.Path('.'), rename=True)
Write all input files for executing Genesis 4.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workdir |
AnyPath
|
The working directory for Genesis 4. This will be where all input and output files are written. |
Path('.')
|
rename |
bool
|
Adjust temporary filenames of HDF5 files, replacing random characters with sensible namelist-prefixed names. |
True
|
Returns:
Type | Description |
---|---|
List[Path]
|
Paths written. |
Source code in genesis/version4/input/core.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 |
|
genesis.version4.Genesis4Input.write_context ¶
write_context(workdir)
Write all input files for executing Genesis 4.
This is a context manager. When the context manager exits, all input files will be cleaned up (i.e., deleted from disk).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workdir |
AnyPath
|
The working directory for Genesis 4. This will be where all input and output files are written. |
required |
Yields:
Type | Description |
---|---|
List[Path]
|
Paths written. |
Source code in genesis/version4/input/core.py
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 |
|
genesis.version4.Genesis4Input.write_initial_field ¶
write_initial_field(workdir)
Write the initial field file.
Source code in genesis/version4/input/core.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
|
genesis.version4.Genesis4Input.write_initial_particles ¶
write_initial_particles(workdir)
Write the initial particles file.
Source code in genesis/version4/input/core.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 |
|
genesis.version4.types.BaseModel ¶
Bases: BaseModel
LUME-Genesis customized pydantic BaseModel.
Alters dir()
handling and other things for user convenience.