Skip to content

Commit ab5a274

Browse files
committed
adjusting copy of experiment that didn't copy the experiment with the HPC send through command
1 parent 776920a commit ab5a274

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

autosubmit/autosubmit.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,8 +1367,8 @@ def replace_parameter_inside_section(content, parameter, new_value, section):
13671367
return content
13681368

13691369
@staticmethod
1370-
def as_conf_default_values(exp_id, hpc, minimal_configuration=False, git_repo="", git_branch="main",
1371-
git_as_conf=""):
1370+
def as_conf_default_values(exp_id:str, hpc:str = "local", minimal_configuration:bool = False, git_repo:str = "",
1371+
git_branch:str = "main", git_as_conf:str = "") -> None:
13721372
"""
13731373
Replace default values in as_conf files
13741374
:param exp_id: experiment id
@@ -1380,7 +1380,6 @@ def as_conf_default_values(exp_id, hpc, minimal_configuration=False, git_repo=""
13801380
:return: None
13811381
"""
13821382
# the var hpc was hardcoded in the header of the function
1383-
hpc_default = "local"
13841383

13851384
# open and replace values
13861385
for as_conf_file in Path(BasicConfig.LOCAL_ROOT_DIR, f"{exp_id}/conf").iterdir():
@@ -1404,12 +1403,13 @@ def as_conf_default_values(exp_id, hpc, minimal_configuration=False, git_repo=""
14041403
x = search.group(0).split(":")
14051404
# clean blank space, quotes and double quote
14061405
aux = x[1].strip(' "\'')
1407-
# hpc in config is empty && -H is empty-> hpc_default will be introduced
1408-
if len(aux) == 0 and not hpc:
1409-
content = content.replace(search.group(0), f"HPCARCH: \"{hpc_default}\"")
14101406
# hpc in config is empty && -H has a value-> write down hpc value
1411-
elif len(aux) == 0:
1407+
if hpc != "":
14121408
content = content.replace(search.group(0), f"HPCARCH: \"{hpc}\"")
1409+
elif len(aux) > 0:
1410+
content = content.replace(search.group(0), f"HPCARCH: \"{aux}\"")
1411+
else:
1412+
content = content.replace(search.group(0), "HPCARCH: \"local\"")
14131413
# the other case is aux!=0 that we dont care about val(hpc) because its a copyExpId
14141414
if minimal_configuration:
14151415
search = re.search('CUSTOM_CONFIG: .*', content, re.MULTILINE)

test/integration/test_expid.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,36 @@ def test_create_expid_flag_hpc(fake_hpc: str, expected_hpc: str, autosubmit: Aut
199199
assert hpc_result_experiment == expected_hpc
200200

201201

202+
@pytest.mark.parametrize("experiment_hpc,expected_hpc", [
203+
("local","mn5"),
204+
("mn5","marenostrum"), ])
205+
def test_copy_expid_with_flag_hpc(tmp_path: Path, autosubmit: Autosubmit, experiment_hpc, expected_hpc):
206+
"""Create expid using the flag -H. Defining a value for the flag and not defining any value for that flag.
207+
208+
code-block:: console
209+
210+
autosubmit expid -H ithaca -d "experiment"
211+
autosubmit expid -H "" -d "experiment"
212+
213+
:param fake_hpc: The value for the -H flag (hpc value).
214+
:param expected_hpc: The value it is expected for the variable hpc.
215+
:param autosubmit: Autosubmit interface that instantiate with no experiment.
216+
"""
217+
autosubmit.install()
218+
219+
exp_id = autosubmit.expid('experiment', hpc=experiment_hpc, minimal_configuration=True)
220+
copy_exp = autosubmit.expid('copy', hpc=expected_hpc , copy_id=exp_id, minimal_configuration=True)
221+
222+
describe = autosubmit.describe(exp_id)
223+
hpc_experiment = describe[4].lower()
224+
225+
describe_copy = autosubmit.describe(copy_exp)
226+
hpc_experiment_copy = describe_copy[4].lower()
227+
228+
assert hpc_experiment != hpc_experiment_copy
229+
assert hpc_experiment_copy == expected_hpc
230+
231+
202232
@pytest.mark.parametrize("fake_hpc,expected_hpc", [
203233
("mn5", "mn5"),
204234
("", "local"),
@@ -253,7 +283,7 @@ def test_copy_expid_no(autosubmit: Autosubmit):
253283
describe = autosubmit.describe(copy_experiment_id)
254284
hpc_result = describe[4].lower()
255285

256-
assert hpc_result != new_hpc
286+
assert hpc_result == new_hpc
257287

258288

259289
def _get_experiment_data(tmp_path):

0 commit comments

Comments
 (0)