Skip to content

Commit e754bd1

Browse files
Merge pull request #178 from rosswhitfield/cleanup_runspaceInit
Fix runspaceInitComponent when using multiple configurations
2 parents e40dccf + 3348597 commit e754bd1

File tree

3 files changed

+22
-85
lines changed

3 files changed

+22
-85
lines changed

ipsframework/configurationManager.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,6 @@ def _initialize_sim(self, sim_data):
443443
if 'IPS_ROOT' not in comp_conf:
444444
if 'IPS_ROOT' in sim_conf:
445445
comp_conf['IPS_ROOT'] = sim_conf['IPS_ROOT']
446-
if 'DATA_TREE_ROOT' not in comp_conf:
447-
if 'DATA_TREE_ROOT' in sim_conf:
448-
comp_conf['DATA_TREE_ROOT'] = sim_conf['DATA_TREE_ROOT']
449-
else:
450-
comp_conf['DATA_TREE_ROOT'] = sim_data.conf_file_dir
451446
if 'BIN_DIR' not in comp_conf:
452447
if 'BIN_DIR' in sim_conf:
453448
comp_conf['BIN_DIR'] = sim_conf['BIN_DIR']
@@ -552,6 +547,10 @@ def get_all_simulation_components_map(self):
552547
del sim_comps[self.fwk_sim_name]
553548
return sim_comps
554549

550+
def get_all_simulation_sim_root(self):
551+
sim_roots = {name: sim_map.sim_root for name, sim_map in self.sim_map.items()}
552+
return sim_roots
553+
555554
def get_framework_components(self):
556555
"""
557556
Return list of framework components.

ipsframework/runspaceInitComponent.py

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
from ipsframework import ipsutil
77

88

9-
def catch_and_go(func_to_decorate):
10-
def new_func(*original_args, **original_kwargs):
11-
# Do whatever else you want here
12-
obj = original_args[0]
13-
try:
14-
func_to_decorate(*original_args, **original_kwargs)
15-
except Exception as e:
16-
obj.services.exception("Exception in call to %s:%s" % (obj.__class__.__name__, func_to_decorate.__name__))
17-
print(e)
18-
return new_func
19-
20-
219
class runspaceInitComponent(Component):
2210
"""
2311
Framework component to manage runspace initialization, container file
@@ -34,33 +22,16 @@ def __init__(self, services, config):
3422
self.simRootDir = services.get_config_param('SIM_ROOT')
3523
self.cwd = self.config['OS_CWD']
3624

37-
@catch_and_go
3825
def init(self, timestamp=0.0, **keywords):
3926
"""
4027
Creates base directory, copies IPS and FacetsComposer input files.
4128
"""
4229

43-
services = self.services
44-
45-
try:
46-
os.chdir(self.cwd)
47-
except OSError:
48-
self.services.debug('Working directory %s does not exist - this is impossibile',
49-
self.cwd)
50-
raise
51-
5230
if not self.simRootDir.startswith("/"):
5331
self.simRootDir = os.path.join(self.cwd, self.simRootDir)
5432

55-
# try making the simulation root directory
56-
try:
57-
os.makedirs(self.simRootDir, exist_ok=True)
58-
except OSError as oserr:
59-
self.services.exception('Error creating directory %s : %s',
60-
self.simRootDir, oserr.strerror)
61-
62-
config_files = services.fwk.config_file_list
63-
platform_file = services.fwk.platform_file_name
33+
config_files = self.services.fwk.config_file_list
34+
platform_file = self.services.fwk.platform_file_name
6435

6536
# Determine where the file is...if there's not an absolute path specified,
6637
# assume that it was in the directory that the IPS was launched from.
@@ -79,29 +50,19 @@ def init(self, timestamp=0.0, **keywords):
7950
ipsutil.copyFiles(conf_file_loc, config_files, self.simRootDir)
8051
ipsutil.copyFiles(plat_file_loc, platform_file, self.simRootDir)
8152

82-
@catch_and_go
8353
def step(self, timestamp=0.0, **keywords):
8454
"""
8555
Copies individual subcomponent input files into working subdirectories.
8656
"""
8757

88-
services = self.services
89-
90-
# sim_comps = services.fwk.config_manager.get_component_map()
91-
sim_comps = services.fwk.config_manager.get_all_simulation_components_map()
92-
registry = services.fwk.comp_registry
58+
sim_comps = self.services.fwk.config_manager.get_all_simulation_components_map()
59+
sim_roots = self.services.fwk.config_manager.get_all_simulation_sim_root()
60+
registry = self.services.fwk.comp_registry
9361

9462
simulation_setup = os.path.join(self.simRootDir, 'simulation_setup')
9563

96-
# make the simulation_setup directory for scripts
97-
try:
98-
os.makedirs(simulation_setup, exist_ok=True)
99-
except OSError as oserr:
100-
self.services.exception('Error creating directory %s : %s',
101-
simulation_setup, oserr.strerror)
102-
10364
# for each simulation component
104-
for comp_list in sim_comps.values():
65+
for name, comp_list in sim_comps.items():
10566
# for each component_id in the list of components
10667
for comp_id in comp_list:
10768
# build the work directory name
@@ -111,7 +72,7 @@ def step(self, timestamp=0.0, **keywords):
11172
str(comp_id.get_seq_num())])
11273

11374
# compose the workdir name
114-
workdir = os.path.join(self.simRootDir, 'work', full_comp_id)
75+
workdir = os.path.join(sim_roots[name], 'work', full_comp_id)
11576

11677
# make the working directory
11778
try:
@@ -130,21 +91,6 @@ def step(self, timestamp=0.0, **keywords):
13091
print('Error copying input files for initialization')
13192
raise
13293

133-
# This is a bit tricky because we want to look either in the same
134-
# place as the input files or the data_tree root
135-
if 'DATA_FILES' in comp_conf:
136-
filesCopied = False
137-
if 'DATA_TREE_ROOT' in comp_conf:
138-
dtrdir = os.path.abspath(comp_conf['DATA_TREE_ROOT'])
139-
if os.path.exists(os.path.join(dtrdir, comp_conf['DATA_FILES'][0])):
140-
ipsutil.copyFiles(dtrdir, os.path.basename(comp_conf['DATA_FILES']),
141-
workdir)
142-
filesCopied = True
143-
if not filesCopied:
144-
ipsutil.copyFiles(os.path.abspath(comp_conf['INPUT_DIR']),
145-
os.path.basename(comp_conf['DATA_FILES']),
146-
workdir)
147-
14894
# copy the component's script to the simulation_setup directory
14995
if comp_conf['SCRIPT']:
15096
if os.path.isabs(comp_conf['SCRIPT']):
@@ -155,14 +101,3 @@ def step(self, timestamp=0.0, **keywords):
155101
ipsutil.copyFiles(comp_conf['BIN_DIR'],
156102
[os.path.basename(comp_conf['SCRIPT'])],
157103
simulation_setup)
158-
159-
# get the working directory from the runspaceInitComponent
160-
workdir = services.get_working_dir()
161-
162-
# create the working directory for this component
163-
try:
164-
os.makedirs(workdir, exist_ok=True)
165-
except OSError as oserr:
166-
self.services.exception('Error creating directory %s : %s',
167-
workdir, oserr.strerror)
168-
raise

tests/multirun/test_basic_serial.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,25 @@ def test_basic_serial_multi(tmpdir, capfd):
139139

140140
# check files copied and created
141141
for no in ["1", "2"]:
142-
# This should also work for 2
143-
if no == "2":
144-
continue
145142

146-
driver_files = [os.path.basename(f) for f in glob.glob(str(tmpdir.join(f"test_basic_serial{no}_0/work/drivers_testing_basic_serial1_*/*")))]
143+
driver_files = [os.path.basename(f) for f in glob.glob(str(tmpdir.join(f"test_basic_serial{no}_0/work/drivers_testing_basic_serial*_*/*")))]
147144
for infile in ["file1", "ofile1", "ofile2", "sfile1", "sfile2"]:
148145
assert infile in driver_files
149146

150147
small_worker_files = [os.path.basename(f) for f in glob.glob(str(tmpdir.join(f"test_basic_serial{no}_0/work/workers_testing_small_worker_*/*")))]
151148
medium_worker_files = [os.path.basename(f) for f in glob.glob(str(tmpdir.join(f"test_basic_serial{no}_0/work/workers_testing_medium_worker_*/*")))]
152149
large_worker_files = [os.path.basename(f) for f in glob.glob(str(tmpdir.join(f"test_basic_serial{no}_0/work/workers_testing_large_worker_*/*")))]
153150

154-
for outfile in ["my_out3.50", "my_out3.60", "my_out3.70"]:
155-
assert outfile in small_worker_files
156-
assert outfile in medium_worker_files
157-
assert outfile in large_worker_files
151+
if no == "1":
152+
for outfile in ["my_out3.50", "my_out3.60", "my_out3.70"]:
153+
assert outfile in small_worker_files
154+
assert outfile in medium_worker_files
155+
assert outfile in large_worker_files
156+
else:
157+
for outfile in ["my_out3.40", "my_out3.50", "my_out3.60"]:
158+
assert outfile in small_worker_files
159+
assert outfile in medium_worker_files
160+
assert outfile in large_worker_files
158161

159162
# check contents of my_out files
160163
for outfile in ["my_out3.50", "my_out3.60", "my_out3.70"]:

0 commit comments

Comments
 (0)