Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
4 changes: 2 additions & 2 deletions pycoupler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def run_model_bin(
detach: bool = False,
# pyright: ignore[reportExplicitAny]
subprocess_args: dict[str, Any] = {},
) -> CompletedProcess[str] | CompletedProcess[bytes] | Popen[str] | Popen[bytes]:
): # -> CompletedProcess[str] | CompletedProcess[bytes] | Popen[str] | Popen[bytes]:
"""Runs the LPJmL model binaries in the configured environment

Parameters
Expand Down Expand Up @@ -1362,7 +1362,7 @@ def parse_config(
"cc1: fatal error: .*: No such file or directory", json_str.stdout.decode()
):
raise FileNotFoundError(
f"Config file '{file_name}' does not exists{" in the container" if in_container else ""}."
f"Config file '{file_name}' does not exists{' in the container' if in_container else ''}."
)
else:
json_str.check_returncode()
Expand Down
24 changes: 13 additions & 11 deletions pycoupler/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,21 @@ def run_lpjml(config_file: str, std_to_file=False):
return operate_lpjml(config_file, std_to_file, False)


# TODO: Removed tpe hints for Python 3.9 support, should be changed back after upgrade of the base python version.
# Because Python 3.9 doesn’t support type unions: https://bugs.python.org/issue42233
def submit_lpjml(
config_file,
group: str | None = None,
sclass: str | None = None,
group=None, # str | None
sclass=None, # str | None
ntasks: int = 256,
wtime: str | None = None,
dependency: int | str | None = None,
blocking: str | None = None,
option: str | list[str] | None = None,
couple_to: str | Path | None = None,
venv_path: str | Path | None = None,
modules: str | None = None,
partition: str | None = None,
wtime=None, # str | None
dependency=None, # int | str | None
blocking=None, # str | None
option=None, # str | list[str] | None
couple_to=None, # str | Path | None
venv_path=None, # str | Path | None
modules=None, # str | None
partition=None, # str | None
):
"""Submit LPJmL run to Slurm using `lpjsubmit` and a generated
(class LpjmlConfig) config file.
Expand Down Expand Up @@ -252,7 +254,7 @@ def submit_lpjml(
)

job_control_file = job_control_file.rename(
job_control_file.with_stem(f"slurm_{getattr(config, "sim_name", "")}")
job_control_file.with_stem(f"slurm_{getattr(config, 'sim_name', '')}")
)

sbatch_cmd = ["sbatch"]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def test_command(
"-wtime",
self.wtime,
"-couple",
f"{f"{mock_venv}/bin/python" if mock_venv else sys.executable} {couple_script} {config_coupled_json}",
(f"{mock_venv}/bin/python" if mock_venv else sys.executable)
+ f" {couple_script} {config_coupled_json}",
str(self.ntasks),
config_coupled_json,
]
Expand Down
38 changes: 20 additions & 18 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
from typing import NotRequired, TypedDict
from typing import TypedDict # , NotRequired TODO: Was added in python 3.11
import struct


class ClmHeader(TypedDict):
name: NotRequired[str]
version: NotRequired[int]
order: NotRequired[int]
firstyear: NotRequired[int]
nyear: NotRequired[int]
firstcell: NotRequired[int]
ncell: NotRequired[int]
nbands: NotRequired[int]
cellsize_lon: NotRequired[float]
scalar: NotRequired[float]
cellsize_lat: NotRequired[float]
datatype: NotRequired[int]
nstep: NotRequired[int]
timestep: NotRequired[int]


def clm_file(header: ClmHeader, big_endian: bool = False, data: list[int | float] = []):
name: str # NotRequired[str]
version: int # NotRequired[int]
order: int # NotRequired[int]
firstyear: int # NotRequired[int]
nyear: int # NotRequired[int]
firstcell: int # NotRequired[int]
ncell: int # NotRequired[int]
nbands: int # NotRequired[int]
cellsize_lon: float # NotRequired[float]
scalar: float # NotRequired[float]
cellsize_lat: float # NotRequired[float]
datatype: int # NotRequired[int]
nstep: int # NotRequired[int]
timestep: int # NotRequired[int]


def clm_file(
header: ClmHeader, big_endian: bool = False, data=[]
): # data: list[int | float]
version = header.get("version", 4)
name = header.get("name", "LPJGRID")

Expand Down
Loading