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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0
rev: v0.15.4
hooks:
# Run the linter.
- id: ruff-check
Expand All @@ -40,7 +40,7 @@ repos:
- id: ruff-format
types_or: [ python, pyi ]
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
rev: v4.4.0
hooks:
- id: conventional-pre-commit
# stages: [commit-msg]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# -- Project information -----------------------------------------------------

project = "ReLeSO"
copyright = "2023, Clemens Fricke" # noqa: A001
copyright = "2023, Clemens Fricke"
author = "Clemens Fricke"

# The full version, including alpha/beta/rc tags
Expand Down
10 changes: 4 additions & 6 deletions releso/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,10 @@ def __init__(
["stdout", "csv"],
)
self._logger.info(
(
"The StepLogCallback should only be used for debugging purposes"
" and only for use-cases with a smallish observation space."
" Otherwise it will create a lot of data and slow down the"
" training process. Use with caution!"
)
"The StepLogCallback should only be used for debugging purposes"
" and only for use-cases with a smallish observation space."
" Otherwise it will create a lot of data and slow down the"
" training process. Use with caution!"
)
self._reset_internal_storage()

Expand Down
2 changes: 1 addition & 1 deletion releso/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _parse_string_to_int(string: str) -> int:
seed = _parse_string_to_int(str(seed)) if seed is not None else seed
self.get_logger().debug(
f"A random action is applied during reset with the following "
f"seed {str(seed)}"
f"seed {seed!s}"
)
rng_gen = np.random.default_rng(seed)
if self.discrete_actions:
Expand Down
2 changes: 1 addition & 1 deletion releso/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def validate_mxyz_mien_path(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"Mesh files are defined by mxyz_path and mien_path."
)
return values
elif "path" in values.keys() and values["path"]:
elif values.get("path"):
get_parser_logger().debug(
"Trying to find mxyz_path and mien_path from path variable."
)
Expand Down
10 changes: 5 additions & 5 deletions releso/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def validate_knot_vector(
float: value of the validated value.
"""
if (
"number_of_points" in values.keys()
and "degree" in values.keys()
and "name" in values.keys()
"number_of_points" in values
and "degree" in values
and "name" in values
):
n_knots = values["number_of_points"] + values["degree"] + 1
else:
Expand Down Expand Up @@ -165,12 +165,12 @@ def make_default_control_point_grid(
List[List[VariableLocation]]: Definition of the control_points
"""
if not values.get("control_points"):
if "space_dimensions" not in values.keys():
if "space_dimensions" not in values:
raise ParserException(
"SplineDefinition",
"control_point_variables",
"During validation the prerequisite variable "
f"space_dimensions was not present. {str(values)}",
f"space_dimensions was not present. {values!s}",
)
spline_dimensions = values["space_dimensions"]
n_points_in_dim = [
Expand Down
13 changes: 5 additions & 8 deletions releso/spor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def validate_additional_observations(
# TODO: change name to something more meaningful for example
# using the function name values["name"]
v = {
"name": f"unnamed_{str(uuid4())}",
"name": f"unnamed_{uuid4()!s}",
"value_min": -1,
"value_max": 1,
"observation_shape": [int(v)],
Expand Down Expand Up @@ -423,10 +423,7 @@ def validate_add_step_information_only_true_if_also_spor_com_is_true(
str: value
"""
if v:
if (
"use_communication_interface" in values
and values["use_communication_interface"]
):
if values.get("use_communication_interface"):
pass
else:
raise ParserException(
Expand Down Expand Up @@ -1016,7 +1013,7 @@ def run(
self.save_location / self.python_file_path.name,
)
self.get_logger().debug(
f"Successfully copied the python file {str(ret_path)}"
f"Successfully copied the python file {ret_path!s}"
)

# trying to internalize the function
Expand All @@ -1026,15 +1023,15 @@ def run(
except ModuleNotFoundError as err:
raise RuntimeError(
f"Could not load the python file at "
f"{str(self.python_file_path)}"
f"{self.python_file_path!s}"
) from err
else:
try:
self._run_func = func.main
except AttributeError as err:
raise RuntimeError(
f"Could not get main function from python file"
f" {str(self.python_file_path)}."
f" {self.python_file_path!s}."
) from err
else:
self._run_logger = set_up_logger(
Expand Down
4 changes: 2 additions & 2 deletions releso/util/util_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def default(self, o: Any) -> Any:
try:
return json.JSONEncoder.default(self, o)
except TypeError:
print(type(o), o) # noqa: T201
print(type(o), o)
return json.JSONEncoder.default(self, "")


Expand Down Expand Up @@ -91,7 +91,7 @@ def call_commandline(command, folder, logger=None):
output = subprocess.check_output(
command,
shell=True,
cwd=folder, # noqa: S602
cwd=folder,
)
exitcode = 0
except subprocess.CalledProcessError as exc:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_base_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any, Dict, List, Union
import pathlib
from typing import Any, Dict, List, Union

import pytest

Expand All @@ -17,9 +17,7 @@ def recursive_remove_save_location(
if "save_location" in dict_to_clean:
del dict_to_clean["save_location"]
for value in dict_to_clean.values():
if isinstance(value, dict):
recursive_remove_save_location(value)
elif isinstance(value, list):
if isinstance(value, dict) or isinstance(value, list):
recursive_remove_save_location(value)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_mixd_mesh_export_and_get(
):
mesh_exporter = MeshExporter(
format="mixd",
export_path=f"{str(dir_save_location)}/export/" + "{}/test.xns",
export_path=f"{dir_save_location!s}/export/" + "{}/test.xns",
save_location=dir_save_location,
)
mesh = MeshIOMesh(
Expand All @@ -333,7 +333,7 @@ def test_mixd_mesh_export_and_get(
)
mesh.adapt_export_path("123")
mesh.export.export_mesh(mesh.get_mesh())
exported_file = pathlib.Path(f"{str(dir_save_location)}/export")
exported_file = pathlib.Path(f"{dir_save_location!s}/export")
mesh_exporter.mesh_format = "other"
with pytest.raises(RuntimeError) as err:
mesh_exporter.export_mesh(None)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def test_parser_environment_non_geometry_observations(
"reward_on_error": -1,
"working_directory": str(dir_save_location),
"python_file_path": (
f"{str(file_path)}/samples"
f"{file_path!s}/samples"
"/spor_python_scripts_tests/file_exists_has_main.py"
),
"use_communication_interface": True,
Expand Down Expand Up @@ -643,7 +643,7 @@ def test_parser_environment_validation(
"reward_on_error": -1,
"working_directory": str(dir_save_location),
"python_file_path": (
f"{str(file_path)}/samples"
f"{file_path!s}/samples"
"/spor_python_scripts_tests/file_exists_has_main.py"
),
"use_communication_interface": True,
Expand Down
12 changes: 4 additions & 8 deletions tests/test_reward_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ def test_parse_communication_interface_json(
):
args = []
args.extend([
f"-r{str(uuid.uuid4())}",
f"-e{str(uuid.uuid4())}",
f"-l{str(dir_save_location)}",
f"-r{uuid.uuid4()!s}",
f"-e{uuid.uuid4()!s}",
f"-l{dir_save_location!s}",
])
if j:
args.extend(["-j", j])
Expand All @@ -285,11 +285,7 @@ def test_parse_communication_interface_json(
assert error_j in err
return
argparse_ret = spor_com_parse_arguments(args)
if json_object:
assert argparse_ret.json_object == {"test": 12, "other": "test"}
elif additional_values:
assert argparse_ret.json_object == {"test": 12, "other": "test"}
elif j:
if json_object or additional_values or j:
assert argparse_ret.json_object == {"test": 12, "other": "test"}
else:
assert argparse_ret.json_object is None
51 changes: 25 additions & 26 deletions tests/test_shape_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ def test_variable_location_min_max_location(
def test_variable_location_is_action(
current_position, min_value, max_value, is_action, dir_save_location
):
variable_location = VariableLocation(**{
"current_position": current_position,
"min_value": min_value,
"max_value": max_value,
"save_location": dir_save_location,
})
variable_location = VariableLocation(
current_position=current_position,
min_value=min_value,
max_value=max_value,
save_location=dir_save_location,
)
assert variable_location.is_action() is is_action


Expand Down Expand Up @@ -294,14 +294,14 @@ def test_variable_location_discrete_action(
expect_position,
dir_save_location,
):
variable_location = VariableLocation(**{
"current_position": current_position,
"min_value": min_value,
"max_value": max_value,
"n_steps": n_steps,
"step": step,
"save_location": dir_save_location,
})
variable_location = VariableLocation(
current_position=current_position,
min_value=min_value,
max_value=max_value,
n_steps=n_steps,
step=step,
save_location=dir_save_location,
)
last_current_position = current_position
for iteration in iterations:
last_current_position = variable_location.apply_discrete_action(
Expand Down Expand Up @@ -363,14 +363,14 @@ def test_variable_location_continuous_action(
expect_position,
dir_save_location,
):
variable_location = VariableLocation(**{
"current_position": current_position,
"min_value": min_value,
"max_value": max_value,
"n_steps": n_steps,
"step": step,
"save_location": dir_save_location,
})
variable_location = VariableLocation(
current_position=current_position,
min_value=min_value,
max_value=max_value,
n_steps=n_steps,
step=step,
save_location=dir_save_location,
)
last_current_position = current_position
for iteration in iterations:
last_current_position = variable_location.apply_continuous_action(
Expand Down Expand Up @@ -580,10 +580,9 @@ def test_shape_definition_get_actions(
point["save_location"] = dir_save_location
new_cps.append(VariableLocation(**point))
new_control_points.append(new_cps)
shape = ShapeDefinition(**{
"control_points": new_control_points,
"save_location": dir_save_location,
})
shape = ShapeDefinition(
control_points=new_control_points, save_location=dir_save_location
)
actions = shape.get_actions()
assert len(actions) == n_actions

Expand Down
2 changes: 1 addition & 1 deletion tests/test_spor.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def test_spor_object_executor_spor_com_interface(
else:
assert "--reset" not in interface_string
if validation_id is not None:
assert f"--validation_value {str(validation_id)}" in interface_string
assert f"--validation_value {validation_id!s}" in interface_string
else:
assert "--validation_value" not in interface_string
if add_step_info:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_verbosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ def test_verbosity_default(
with caplog.at_level(VerbosityLevel.DEBUG):
verbosity = Verbosity(**calling_dict)
assert (
f"Parser logger has logging level: {str(wanted_parser.value)}"
f"Parser logger has logging level: {wanted_parser.value!s}"
in caplog.text
)
assert (
f"Environment logger has logging level: "
f"{str(wanted_environment.value)}"
f"{wanted_environment.value!s}"
) in caplog.text
else:
verbosity = Verbosity(**calling_dict)
Expand Down