Skip to content

Commit

Permalink
Corrections for using lume-base, cathode start status with distgen, e…
Browse files Browse the repository at this point in the history
…xamples.
  • Loading branch information
ChristopherMayes committed Jan 9, 2022
1 parent eea0106 commit 7f24159
Show file tree
Hide file tree
Showing 14 changed files with 635 additions and 631 deletions.
6 changes: 4 additions & 2 deletions astra/astra.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ class Astra(CommandWrapper):
COMMAND = "$ASTRA_BIN"
INPUT_PARSER = parsers.parse_astra_input_file

def __init__(self, *,
def __init__(self,
input_file=None,
*,
group=None,
**kwargs
):
super().__init__(**kwargs)
super().__init__(input_file=input_file, **kwargs)
# Save init
self.original_input_file = self._input_file

Expand Down
15 changes: 10 additions & 5 deletions astra/astra_distgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from distgen.writers import write_astra
from distgen.tools import update_nested_dict

from lume import tools as lumetools

from pmd_beamphysics import ParticleGroup

from h5py import File
Expand Down Expand Up @@ -65,7 +67,7 @@ def run_astra_with_distgen(settings=None,
return run_astra(settings=settings,
astra_input_file=astra_input_file,
workdir=workdir,
astra_bin=astra_bin,
command=astra_bin,
timeout=timeout,
verbose=verbose)

Expand All @@ -74,7 +76,7 @@ def run_astra_with_distgen(settings=None,
print('run_astra_with_generator')

# Distgen generator
G = Generator(input = distgen_input_file, verbose=verbose)
G = Generator(distgen_input_file, verbose=verbose)

# Make astra objects
if astra_input_file.endswith('.yaml'):
Expand All @@ -86,7 +88,7 @@ def run_astra_with_distgen(settings=None,
A.configure() # again to make sure things are set properly

else:
A = Astra(astra_bin=astra_bin, input_file=astra_input_file, workdir=workdir)
A = Astra(command=astra_bin, input_file=astra_input_file, workdir=workdir)



Expand Down Expand Up @@ -130,6 +132,9 @@ def run_astra_with_distgen(settings=None,
# Run distgen
G.run()
P = G.particles
# Special flag for cathode start
if G['start:type'] == 'cathode':
P.status[:] -1

# Attach to Astra object
A.initial_particles = P
Expand Down Expand Up @@ -192,7 +197,7 @@ def evaluate_astra_with_distgen(settings,
output['fingerprint'] = fingerprint

if archive_path:
path = tools.full_path(archive_path)
path = lumetools.full_path(archive_path)
assert os.path.exists(path), f'archive path does not exist: {path}'
archive_file = os.path.join(path, fingerprint+'.h5')
output['archive'] = archive_file
Expand All @@ -211,7 +216,7 @@ def fingerprint_astra_with_distgen(astra_object, distgen_object):
f1 = astra_object.fingerprint()
f2 = distgen_object.fingerprint()
d = {'f1':f1, 'f2':2}
return tools.fingerprint(d)
return lumetools.fingerprint(d)



Expand Down
4 changes: 2 additions & 2 deletions astra/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def evaluate_astra_with_generator(settings,
astra_input_file=astra_input_file,
generator_input_file=generator_input_file,
workdir=workdir,
astra_bin=astra_bin,
generator_bin=generator_bin,
command=astra_bin,
command_generator=generator_bin,
timeout=timeout,
auto_set_spacecharge_mesh=auto_set_spacecharge_mesh,
verbose=verbose)
Expand Down
10 changes: 6 additions & 4 deletions astra/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class AstraGenerator(CommandWrapper):
"""
COMMAND = "$GENERATOR_BIN"

def __init__(self, **kwargs):
super().__init__(**kwargs)
def __init__(self, input_file, **kwargs):
super().__init__(input_file=input_file, **kwargs)
# Save init
self.original_input_file = self.input_file

Expand All @@ -41,9 +41,11 @@ def load_input(self, input_filepath, absolute_paths=True, **kwargs):
super().load_input(input_filepath, **kwargs)
if absolute_paths:
parsers.fix_input_paths(self.input, root=self.original_path)

self.input = self.input['input']


def input_parser(self, path):
return parsers.parse_astra_input_file(path)['input']
return parsers.parse_astra_input_file(path)

def configure(self):
# Check that binary exists
Expand Down
1 change: 0 additions & 1 deletion astra/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ def fix_input_paths(input_dict, root='', prefixes=['file_', 'distribution', 'q_t
"""
for nl in input_dict:
#print(nl)
for key in input_dict[nl]:
if any([key.startswith(prefix) for prefix in prefixes]):
val = input_dict[nl][key]
Expand Down
101 changes: 46 additions & 55 deletions examples/basic_astra_examples.ipynb

Large diffs are not rendered by default.

89 changes: 51 additions & 38 deletions examples/elements/apex_gun.ipynb

Large diffs are not rendered by default.

66 changes: 29 additions & 37 deletions examples/elements/drift.ipynb

Large diffs are not rendered by default.

43 changes: 14 additions & 29 deletions examples/elements/tws.ipynb

Large diffs are not rendered by default.

107 changes: 49 additions & 58 deletions examples/functional_astra_run.ipynb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions examples/plot_examples.ipynb

Large diffs are not rendered by default.

708 changes: 351 additions & 357 deletions examples/scan_example.ipynb

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions examples/simple_distgen_example.ipynb

Large diffs are not rendered by default.

66 changes: 48 additions & 18 deletions examples/simple_generator_example.ipynb

Large diffs are not rendered by default.

0 comments on commit 7f24159

Please sign in to comment.