Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
exclude: ^.*\.DAT$|.*\.dat$|.*\.tex$|.*\.PPF$|.*\.FLD$|.*\.ps$|ref_dicts.json$|.*\.md$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.15.10
hooks:
- id: ruff
args: [--fix]
Expand All @@ -22,14 +22,14 @@ repos:
args: [--mapping, '2', --sequence, '4', --offset, '2']

- repo: https://github.com/biomejs/pre-commit
rev: v2.3.8
rev: v2.4.11
hooks:
- id: biome-format
types: [json]
args: [--indent-style=space, --indent-width=2, --line-width=89]

- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
rev: 0.9.1
hooks:
- id: nbstripout
args: [--extra-keys=metadata.language_info.version]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

temp_c0max = 90.0 # Critical temperature (K) at zero field and strain
b_c20max = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

# Create a grid of temperature and field values
temp_conductor = np.linspace(1, 11.0, 50) # Temperature range (K)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

# Create a grid of temperature and field values
temp_conductor = np.linspace(1, 8.0, 50) # Temperature range (K)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

# Create a grid of temperature and field values
temp_conductor = np.linspace(4.2, 30.0, 50) # Temperature range (K)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

temp_c0max = 16.06 # Critical temperature (K) at zero field and strain
b_c20max = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

# Create a grid of temperature and field values
temp_conductor = np.linspace(4.2, 40.0, 50) # Temperature range (K)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

# Create a grid of temperature and field values
temp_conductor = np.linspace(1, 10.0, 50) # Temperature range (K)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go

import process.models.superconductors as superconductors
from process.models import superconductors

temp_c0max = 16.34 # Critical temperature (K) at zero field and strain
b_c20max = (
Expand Down
4 changes: 2 additions & 2 deletions process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# setup the package "root" logger, every other logger in PROCESS
# will inherit from this (implicitly, based on the namespace)
root_logger = logging.getLogger(__name__)
root_logger.setLevel(logging.DEBUG)
root_logger = logging.getLogger(__name__) # noqa: RUF067
root_logger.setLevel(logging.DEBUG) # noqa: RUF067

__version__ = version("process")
10 changes: 7 additions & 3 deletions process/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def get_git_summary() -> tuple[str, str]:
directory = Path(process.__file__).parent

git_branch = (
subprocess.run(
subprocess
.run(
"git rev-parse --abbrev-ref HEAD",
shell=True,
capture_output=True,
Expand All @@ -120,7 +121,8 @@ def get_git_summary() -> tuple[str, str]:
)

git_tag = (
subprocess.run(
subprocess
.run(
"git describe --tags",
shell=True,
capture_output=True,
Expand Down Expand Up @@ -409,7 +411,7 @@ def check_process(inputs): # noqa: ARG001
data_structure.buildings_variables.triv = 0.0
data_structure.heat_transport_variables.p_tritium_plant_electric_mw = 0.0

if data_structure.impurity_radiation_module.f_nd_impurity_electrons[1] != 0.1:
if data_structure.impurity_radiation_module.f_nd_impurity_electrons[1] != 0.1: # noqa: RUF069
raise ProcessValidationError(
"The thermal alpha/electron density ratio should be controlled using f_nd_alpha_electron (itv 109) and not f_nd_impurity_electrons(2)."
"f_nd_impurity_electrons(2) should be removed from the input file, or set to the default value 0.1D0."
Expand Down Expand Up @@ -741,11 +743,13 @@ def check_process(inputs): # noqa: ARG001
)

# Check if a single null divertor is used in double null machine
# ruff: disable[RUF069]
if data_structure.physics_variables.i_single_null == 0 and (
data_structure.physics_variables.f_p_div_lower == 1.0
or data_structure.physics_variables.f_p_div_lower == 0.0
):
warn("Operating with a single null in a double null machine", stacklevel=2)
# ruff: enable[RUF069]

# Set the TF coil shape to picture frame (if default value)
if data_structure.tfcoil_variables.i_tf_shape == TFCoilShapeModel.DEFAULT:
Expand Down
2 changes: 1 addition & 1 deletion process/core/io/cli_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _lazy_load(self, cmd_name):
cmd_object = getattr(mod, cmd_object_name)
# check the result to make debugging easier
if not isinstance(cmd_object, click.Command):
raise ValueError(
raise ValueError( # noqa: TRY004
f"Lazy loading of {import_path} failed by returning a non-command object"
)
return cmd_object
Expand Down
4 changes: 2 additions & 2 deletions process/core/io/data_structure_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def slice_file(file, re1, re2):
lines:List of lines from file between re1 and re2 inclusive
"""

with open(file, encoding="utf-8") as file:
filetext = file.readlines()
with open(file, encoding="utf-8") as fh:
filetext = fh.readlines()
start = None
for i in range(len(filetext)):
# look for first match
Expand Down
20 changes: 10 additions & 10 deletions process/core/io/in_dat/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
generation script imports, and inspects, process.
"""

import sys
from re import sub
from sys import stderr

from process.core.exceptions import ProcessValidationError
from process.core.io.data_structure_dicts import get_dicts
Expand Down Expand Up @@ -679,7 +679,7 @@ def add_parameter(data, parameter_name, parameter_value):
print(
f"Warning: Description for {parameter_name}",
"specified in IN.DAT not in dictionary.",
file=stderr,
file=sys.stderr,
)
comment = ""

Expand Down Expand Up @@ -938,7 +938,7 @@ def variable_constraint_type_check(item_number, var_type):
except ValueError:
print(
f"Value {item_number} for {var_type} not valid. Check value!",
file=stderr,
file=sys.stderr,
)

# Check if item is in float format
Expand All @@ -959,7 +959,7 @@ def variable_constraint_type_check(item_number, var_type):

# Value not recognised
else:
raise ValueError(
raise ValueError( # noqa: TRY004
f"Value {item_number} for {var_type} not a recognised format. Check value!"
)

Expand Down Expand Up @@ -1063,7 +1063,7 @@ def __repr__(self):

@property
def get_value(self):
""" """
"""Get value of variables"""
if self.v_type != "Bound":
return parameter_type(self.name, self.value)
return self.value
Expand Down Expand Up @@ -1132,7 +1132,7 @@ def read_in_dat(self):
print(
"Warning: Line below is causing a problem. Check "
f"that line in IN.DAT is valid. Line skipped!\n{line}",
file=stderr,
file=sys.stderr,
)

# Store the first part of the unrecognised line (probably a
Expand Down Expand Up @@ -1246,9 +1246,9 @@ def process_parameter(self, line):
no_comment_line,
"\n Please note, that our Python Library cannot cope with",
" variable definitions on multiple lines.",
file=stderr,
file=sys.stderr,
)
exit()
sys.exit()
else:
try:
value = no_comment_line[1].strip().replace(",", "")
Expand All @@ -1258,9 +1258,9 @@ def process_parameter(self, line):
no_comment_line,
"\n Please note, that our Python Library cannot cope with",
" variable definitions on multiple lines.",
file=stderr,
file=sys.stderr,
)
exit()
sys.exit()

# Find group of variables the parameter belongs to
parameter_group = find_parameter_group(name)
Expand Down
3 changes: 1 addition & 2 deletions process/core/io/mfile/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def set_scan(self, scan_number, scan_value):
value of parameter for scan
"""
self[f"scan{scan_number:02}"] = scan_value
if scan_number > self.latest_scan:
self.latest_scan = scan_number
self.latest_scan = max(self.latest_scan, scan_number)

def get_scan(self, scan_number):
"""Returns the value of a specific scan. For scan = -1 or None the last
Expand Down
5 changes: 2 additions & 3 deletions process/core/io/plot/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,10 @@ def power_balance_sankey(m_file: Path):
#
# Neutrons to CP shield, should only show if CP shield is present
m_file.get("p_cp_shield_nuclear_heat_mw", scan=-1), # 51
#
m_file.get("p_plasma_separatrix_mw", scan=-1), # 52
m_file.get("p_div_secondary_heat_mw", scan=-1), # 53
m_file.get("p_shld_secondary_heat_mw", scan=-1), # 54
m_file.get("p_fw_hcd_nuclear_heat_mw", scan=-1), #
m_file.get("p_fw_hcd_nuclear_heat_mw", scan=-1),
m_file.get("p_fw_hcd_rad_total_mw", scan=-1), # 56
m_file.get("p_plant_secondary_heat_mw", scan=-1), # 57
m_file.get("p_hcd_secondary_heat_mw", scan=-1), # 58
Expand Down Expand Up @@ -399,7 +398,7 @@ def add(
rotation: float = 0,
**kwargs,
):
__doc__ = super().__doc__ # noqa: F841, A001
__doc__ = super().__doc__ # noqa: F841
# Here we first check if the "add" method has received arguments that
# the Sankey class can't handle.
if future is None:
Expand Down
13 changes: 7 additions & 6 deletions process/core/io/plot/scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""

import math
import sys
from collections.abc import Iterable, Sequence
from pathlib import Path

Expand Down Expand Up @@ -179,7 +180,7 @@ def plot_scan(
f"ERROR : nsweep = {nsweep_ref} not supported by the utility\n"
"ERROR : Please update the 'nsweep_dict' dict"
)
exit()
sys.exit()

# Check if the scan variable is present in the
if scan_var_name not in m_file.data:
Expand All @@ -188,7 +189,7 @@ def plot_scan(
"ERROR : The scan variable is probably an upper/lower boundary\n"
"ERROR : Please modify 'nsweep_dict' dict with the constrained var"
)
exit()
sys.exit()

# Check if the second scan variable is present in the
if is_2D_scan and (scan_2_var_name not in m_file.data):
Expand All @@ -197,12 +198,12 @@ def plot_scan(
"ERROR : The scan variable is probably an upper/lower boundary\n"
"ERROR : Please modify 'nsweep_dict' dict with the constrained var"
)
exit()
sys.exit()

# Only one imput must be used for a 2D scan
if is_2D_scan and len(input_files) > 1:
print("ERROR : Only one input file can be used for 2D scans\nERROR : Exiting")
exit()
sys.exit()
# ------

# Plot settings
Expand Down Expand Up @@ -264,12 +265,12 @@ def _format_lists(inp, output_names):
"ERROR : You must use inputs files with the same scan variables\n"
"ERROR : Exiting"
)
exit()
sys.exit()

# No D scans
if "nsweep_2" in m_file.data:
print("ERROR : You cannot mix 1D with 2D scans\nERROR : Exiting")
exit()
sys.exit()
# ---

# Only selecting the scans that has converged
Expand Down
Loading
Loading