diff --git a/process/core/io/vary_run/config.py b/process/core/io/vary_run/config.py index c267881d6a..a289cc13b3 100644 --- a/process/core/io/vary_run/config.py +++ b/process/core/io/vary_run/config.py @@ -280,7 +280,8 @@ def setup(self): ) data_structure.global_variables.fileprefix = str(self.wdir / self.infile) - def run_process(self, input_path: Path, solver: str = "vmcon"): + @staticmethod + def run_process(input_path: Path, solver: str = "vmcon"): """Perform a single run of PROCESS, catching any errors. Parameters diff --git a/process/core/scan.py b/process/core/scan.py index 7a33222c49..30c157676b 100644 --- a/process/core/scan.py +++ b/process/core/scan.py @@ -664,7 +664,8 @@ def post_optimise(self, ifail: int): ), ) - def verror(self, ifail: int): + @staticmethod + def verror(ifail: int): """Routine to print out relevant messages in the case of an unfeasible result from a VMCON (optimisation) run @@ -952,7 +953,8 @@ def scan_2d(self): ) print(f"\nConvergence Percentage: {converged_percentage:.2f}%") - def scan_2d_init(self): + @staticmethod + def scan_2d_init(): process_output.ovarin( constants.MFILE, "Number of first variable scan points", @@ -1051,7 +1053,8 @@ def scan_2d_write_point_header(self, iscan, iscan_1, iscan_2): return iscan_r - def scan_1d_write_plot(self): + @staticmethod + def scan_1d_write_plot(): if scan_variables.first_call_1d: process_output.ovarin( constants.MFILE, diff --git a/process/main.py b/process/main.py index d6835f92c9..ab68dabac9 100644 --- a/process/main.py +++ b/process/main.py @@ -96,7 +96,10 @@ PlasmaBeta, PlasmaInductance, ) -from process.models.physics.plasma_current import PlasmaCurrent, PlasmaDiamagneticCurrent +from process.models.physics.plasma_current import ( + PlasmaCurrent, + PlasmaDiamagneticCurrent, +) from process.models.physics.plasma_fields import PlasmaFields from process.models.physics.plasma_geometry import PlasmaGeom from process.models.physics.plasma_profiles import PlasmaProfile @@ -444,11 +447,13 @@ def run_scan(self): ) self.scan = Scan(self.models, self.solver, self.data) - def show_errors(self): + @staticmethod + def show_errors(): """Report all informational/error messages encountered.""" show_errors(constants.NOUT) - def finish(self): + @staticmethod + def finish(): """Run the finish subroutine to close files open in the Fortran. Files being handled by Fortran must be closed before attempting to diff --git a/process/models/availability.py b/process/models/availability.py index 9040871468..aca0568a3f 100644 --- a/process/models/availability.py +++ b/process/models/availability.py @@ -783,11 +783,9 @@ def calc_u_unplanned_divertor(self, output: bool) -> float: # Integrating the instantaneous availability gives the mean # availability over the planned cycle life N if self.data.costs.div_nu <= self.data.costs.div_nref: - logger.error( - """div_nu <= div_nref + logger.error("""div_nu <= div_nref The cycle when the divertor fails with 100% probability <= & Reference value for cycle life of divertor - """ - ) + """) po.ocmmnt( self.outfile, "ERROR: The cycle when the divertor fails with 100% probability & <= Reference value for cycle cycle life of divertor", @@ -895,11 +893,9 @@ def calc_u_unplanned_fwbs(self, output: bool) -> float: ) if self.data.costs.fwbs_nu <= self.data.costs.fwbs_nref: - logger.error( - """fwbs_nu <= fwbs_nref + logger.error("""fwbs_nu <= fwbs_nref The cycle when the blanket fails with 100% probability <= &Reference value for cycle life of blanket - """ - ) + """) po.ocmmnt( self.outfile, "EROROR: The cycle when the blanket fails with 100% probability& <= Reference value for cycle life of blanket", @@ -1029,7 +1025,8 @@ def calc_u_unplanned_bop(self, output: bool) -> float: return u_unplanned_bop - def calc_u_unplanned_hcd(self) -> float: + @staticmethod + def calc_u_unplanned_hcd() -> float: """Calculates the unplanned unavailability of the heating and current drive system diff --git a/process/models/blankets/blanket_library.py b/process/models/blankets/blanket_library.py index 8975142f9e..f0ec7d9680 100644 --- a/process/models/blankets/blanket_library.py +++ b/process/models/blankets/blanket_library.py @@ -3239,8 +3239,8 @@ def pipe_hydraulic_diameter(self, i_channel_shape): f"i_channel_shape ={i_channel_shape} is an invalid option." ) + @staticmethod def elbow_coeff( - self, radius_pipe_elbow: float, deg_pipe_elbow: float, darcy_friction: float, @@ -3490,8 +3490,9 @@ def calculate_basic_geometry(self): b_bz_liq=self.data.fwbs.b_bz_liq, ) + @staticmethod def blkt_outboard_poloidal_plasma_angle( - self, n_divertors: int, deg_div_poloidal_plasma: float + n_divertors: int, deg_div_poloidal_plasma: float ) -> float: """Calculate the poloidal angle subtended by the outboard blanket at the plasma mid-plane. @@ -3571,8 +3572,8 @@ def calculate_blkt_outboard_poloidal_plasma_angle( ) ) + @staticmethod def calculate_blanket_outboard_module_geometry( - self, n_blkt_outboard_modules_toroidal: int, rmajor: float, rminor: float, @@ -3647,8 +3648,8 @@ def calculate_blkt_inboard_poloidal_plasma_angle( 2.0 * np.arctan(dz_blkt_half / (rminor + dr_fw_plasma_gap_inboard)) ) + @staticmethod def calculate_blanket_inboard_module_geometry( - self, n_blkt_inboard_modules_toroidal: int, rmajor: float, rminor: float, diff --git a/process/models/blankets/hcpb.py b/process/models/blankets/hcpb.py index 774cb18a4d..b62ecc5d6f 100644 --- a/process/models/blankets/hcpb.py +++ b/process/models/blankets/hcpb.py @@ -598,8 +598,8 @@ def nuclear_heating_magnets(self, output: bool): self.data.tfcoil.m_tf_coils_total, ) + @staticmethod def nuclear_heating_fw( - self, m_fw_total: float, fw_armour_u_nuc_heating: float, p_fusion_total_mw: float, @@ -640,8 +640,9 @@ def nuclear_heating_fw( ) return p_fw_nuclear_heat_total_mw + @staticmethod def nuclear_heating_blanket( - self, m_blkt_total: float, p_fusion_total_mw: float + m_blkt_total: float, p_fusion_total_mw: float ) -> tuple[float, float]: """Calculates the nuclear heating in the blanket for the CCFE HCPB model. @@ -685,8 +686,8 @@ def nuclear_heating_blanket( return p_blkt_nuclear_heat_total_mw, exp_blanket + @staticmethod def nuclear_heating_shield( - self, itart: int, dr_shld_outboard: float, dr_shld_inboard: float, @@ -988,7 +989,8 @@ def powerflow_calc(self, output: bool): self.data.fwbs.radius_blkt_channel_180_bend, ) - def st_cp_angle_fraction(self, z_cp_top, r_cp_mid, r_cp_top, rmajor): + @staticmethod + def st_cp_angle_fraction(z_cp_top, r_cp_mid, r_cp_top, rmajor): """ Estimates the CP angular solid angle coverage fration Equation (1-3) from diff --git a/process/models/build.py b/process/models/build.py index 0c7daea60f..f9bf46a6c9 100644 --- a/process/models/build.py +++ b/process/models/build.py @@ -55,8 +55,8 @@ def run(self): dx_beam_shield=self.data.current_drive.dx_beam_shield, ) + @staticmethod def calculate_beam_port_size( - self, f_radius_beam_tangency_rmajor: float, rmajor: float, n_tf_coils: int, @@ -1458,8 +1458,8 @@ def divgeom(self, output: bool): ) return divht + @staticmethod def plasma_outboard_edge_toroidal_ripple( - self, ripple_b_tf_plasma_edge_max: float, r_tf_outboard_mid: float, n_tf_coils: int, diff --git a/process/models/costs/costs_2015.py b/process/models/costs/costs_2015.py index 69158a8143..579270d23d 100644 --- a/process/models/costs/costs_2015.py +++ b/process/models/costs/costs_2015.py @@ -1236,7 +1236,8 @@ def calc_remaining_subsystems(self): for j in range(35, 60): self.data.costs_2015.s_cost[60] += self.data.costs_2015.s_cost[j] - def value_function(self, x): + @staticmethod + def value_function(x): """Value function Function for separative work unit calculation for enrichment cost PROCESS Costs Paper (M. Kovari, J. Morris) @@ -1244,7 +1245,8 @@ def value_function(self, x): """ return (1.0e0 - 2.0e0 * x) * np.log((1.0e0 - x) / x) - def ocost(self, file, descr, vname, value): + @staticmethod + def ocost(file, descr, vname, value): """Routine to print out the code, description and value of a cost item from array s in costs_2015 diff --git a/process/models/divertor.py b/process/models/divertor.py index 77690a8e0f..4b20d8726c 100644 --- a/process/models/divertor.py +++ b/process/models/divertor.py @@ -372,8 +372,8 @@ def divwade( ) return self.data.divertor.pflux_div_heat_load_mw + @staticmethod def incident_radiation_power( - self, p_plasma_rad_mw: float, f_ster_div_single: float, n_divertors: int, @@ -396,8 +396,8 @@ def incident_radiation_power( """ return p_plasma_rad_mw * f_ster_div_single * n_divertors + @staticmethod def incident_neutron_power( - self, p_plasma_neutron_mw: float, f_ster_div_single: float, n_divertors: int, diff --git a/process/models/ife.py b/process/models/ife.py index a66c7cf3a5..8e46671f5e 100644 --- a/process/models/ife.py +++ b/process/models/ife.py @@ -1460,7 +1460,8 @@ def ifephy(self, output: bool = False): self.data.physics.pflux_fw_neutron_mw, ) - def driver(self, edrive, gainve, etave): + @staticmethod + def driver(edrive, gainve, etave): """Routine to calculate parameters of a generic driver suitable for inertial fusion energy @@ -1512,7 +1513,8 @@ def driver(self, edrive, gainve, etave): return gain, etadrv - def lasdrv(self, edrive): + @staticmethod + def lasdrv(edrive): """Routine to calculate parameters of a laser driver suitable for inertial fusion energy @@ -1569,7 +1571,8 @@ def lasdrv(self, edrive): return gain, etadrv - def iondrv(self, edrive): + @staticmethod + def iondrv(edrive): """Routine to calculate parameters of a heavy ion driver suitable for inertial fusion energy diff --git a/process/models/pfcoil.py b/process/models/pfcoil.py index 396976e8cf..220feac0c7 100644 --- a/process/models/pfcoil.py +++ b/process/models/pfcoil.py @@ -1531,7 +1531,8 @@ def tf_pf_collision_detector(self): "One or more collision between TF and PF coils. Check PF placement." ) - def solv(self, n_pf_groups_max, n_pf_coil_groups, nrws, gmat, bvec): + @staticmethod + def solv(n_pf_groups_max, n_pf_coil_groups, nrws, gmat, bvec): """Solve a matrix using singular value decomposition. This routine solves the matrix equation for calculating the @@ -2876,7 +2877,8 @@ def outvolt(self): * self.data.pf_coil.n_pf_coil_turns[k], ) - def selfinductance(self, a, b, c, n): + @staticmethod + def selfinductance(a, b, c, n): """Calculates the selfinductance using Bunet's formula. @@ -2993,8 +2995,8 @@ def output(self): def run(self): """This model doesn't need to be run""" + @staticmethod def calculate_cs_geometry( - self, z_tf_inside_half: float, f_z_cs_tf_internal: float, dr_cs: float, @@ -3067,8 +3069,8 @@ def calculate_cs_geometry( dr_cs_full, ) + @staticmethod def calculate_cs_turn_geometry_eu_demo( - self, a_cs_turn: float, f_dr_dz_cs_turn: float, radius_cs_turn_corners: float, @@ -3145,8 +3147,8 @@ def calculate_cs_turn_geometry_eu_demo( dz_cs_turn_conduit, ) + @staticmethod def place_cs_filaments( - self, n_cs_current_filaments: int, r_cs_middle: float, z_cs_inside_half: float, @@ -3606,8 +3608,8 @@ def ohcalc(self): ) self.calculate_cs_self_midplane_axial_stress_time_profile() + @staticmethod def calculate_cs_self_peak_magnetic_field( - self, j_cs: float, r_cs_inner: float, r_cs_outer: float, @@ -3746,8 +3748,8 @@ def output_cs_structure(self): "OP ", ) + @staticmethod def calculate_cs_self_peak_midplane_axial_stress( - self, r_cs_outer: float, r_cs_inner: float, dz_cs_half: float, diff --git a/pyproject.toml b/pyproject.toml index 1c82d46137..db9ff194e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,7 +116,7 @@ dependencies = ["pre-commit", "ruff", "ty"] [tool.hatch.envs.lint.scripts] fmt = ["pre-commit run --all-files --hook-stage manual {args:}"] -fmt_extra = ["ruff check --select=E501,PLR6301,C901,PLR0904,PLR0911,PLR0912,PLR0913,PLR0914,PLR0915,PLR0916,PLR0917,PLR1702,D100,D101,D102,D103,DOC501,D404,DOC102,D104,D105,PLC1901,S307 {args:.}"] +fmt_extra = ["ruff check --select=E501,C901,PLR0904,PLR0911,PLR0912,PLR0913,PLR0914,PLR0915,PLR0916,PLR0917,PLR1702,D100,D101,D102,D103,DOC501,D404,DOC102,D104,D105,PLC1901,S307 {args:.}"] [tool.coverage.report] exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] @@ -165,7 +165,6 @@ max-locals = 17 "tests/**" = [ "ARG", "PLR2004", - "PLR6301", "PLR0904", "PLC1901", "S101", @@ -237,7 +236,6 @@ ignore = [ # urgent removal remainder "E501", - "PLR6301", # complexity "C901", "PLR0904", diff --git a/tests/integration/test_vmcon.py b/tests/integration/test_vmcon.py index 1630840081..1b179dc338 100644 --- a/tests/integration/test_vmcon.py +++ b/tests/integration/test_vmcon.py @@ -115,7 +115,8 @@ class Evaluator1(CustomFunctionEvaluator): :type CustomFunctionEvaluator: CustomFunctionEvaluator """ - def fcnvmc1(self, n, m, x, ifail): + @staticmethod + def fcnvmc1(n, m, x, ifail): """Function evaluator. @@ -141,7 +142,8 @@ def fcnvmc1(self, n, m, x, ifail): return objf, conf - def fcnvmc2(self, n, m, x, lcnorm): + @staticmethod + def fcnvmc2(n, m, x, lcnorm): """Gradient function evaluator. Calculates the gradients of the objective and constraint functions at @@ -178,7 +180,8 @@ class Evaluator2(CustomFunctionEvaluator): :type CustomFunctionEvaluator: CustomFunctionEvaluator """ - def fcnvmc1(self, n, m, x, ifail): + @staticmethod + def fcnvmc1(n, m, x, ifail): """Function evaluator. @@ -204,7 +207,8 @@ def fcnvmc1(self, n, m, x, ifail): return objf, conf - def fcnvmc2(self, n, m, x, lcnorm): + @staticmethod + def fcnvmc2(n, m, x, lcnorm): """Gradient function evaluator. Calculates the gradients of the objective and constraint functions at @@ -242,7 +246,8 @@ class Evaluator3(CustomFunctionEvaluator): :type CustomFunctionEvaluator: CustomFunctionEvaluator """ - def fcnvmc1(self, n, m, x, ifail): + @staticmethod + def fcnvmc1(n, m, x, ifail): """Function evaluator. @@ -265,7 +270,8 @@ def fcnvmc1(self, n, m, x, ifail): return objf, conf - def fcnvmc2(self, n, m, x, lcnorm): + @staticmethod + def fcnvmc2(n, m, x, lcnorm): """Gradient function evaluator. Calculates the gradients of the objective and constraint functions at @@ -303,7 +309,8 @@ class Evaluator4(CustomFunctionEvaluator): :type CustomFunctionEvaluator: CustomFunctionEvaluator """ - def fcnvmc1(self, n, m, x, ifail): + @staticmethod + def fcnvmc1(n, m, x, ifail): """Function evaluator. Calculates the objective and constraint functions at the @@ -325,7 +332,8 @@ def fcnvmc1(self, n, m, x, ifail): return objf, conf - def fcnvmc2(self, n, m, x, lcnorm): + @staticmethod + def fcnvmc2(n, m, x, lcnorm): """Gradient function evaluator. Calculates the gradients of the objective and constraint functions at @@ -358,7 +366,8 @@ class Evaluator5(CustomFunctionEvaluator): :type CustomFunctionEvaluator: CustomFunctionEvaluator """ - def fcnvmc1(self, n, m, x, ifail): + @staticmethod + def fcnvmc1(n, m, x, ifail): """Function evaluator. Calculates the objective and constraint functions at the @@ -380,7 +389,8 @@ def fcnvmc1(self, n, m, x, ifail): return objf, conf - def fcnvmc2(self, n, m, x, lcnorm): + @staticmethod + def fcnvmc2(n, m, x, lcnorm): """Gradient function evaluator. Calculates the gradients of the objective and constraint functions at diff --git a/tests/regression/regression_test_assets.py b/tests/regression/regression_test_assets.py index 3f63eb0128..ee0431c63d 100644 --- a/tests/regression/regression_test_assets.py +++ b/tests/regression/regression_test_assets.py @@ -82,7 +82,8 @@ def get_reference_mfile(self, scenario_name: str, target_hash: str | None = None return None - def _git_commit_hashes(self): + @classmethod + def _git_commit_hashes(cls): """Returns the list of commit hashes. :returns: a list of commit hashes from 'git log' @@ -125,7 +126,8 @@ def _get_tracked_mfiles(self): key=lambda m: self._hashes.index(m.hash), ) - def _get_tracked_mfile(self, file: Path): + @staticmethod + def _get_tracked_mfile(file: Path): """Converts JSON data of a file tracked on GitHub into a `TrackedMFile`, if appropriate diff --git a/tests/regression/test_process_input_files.py b/tests/regression/test_process_input_files.py index 0b62666dd7..207a4b70e2 100644 --- a/tests/regression/test_process_input_files.py +++ b/tests/regression/test_process_input_files.py @@ -38,7 +38,8 @@ class ProcessModelFilter(logging.Filter): - def filter(self, record): + @staticmethod + def filter(record): return 0 if record.levelno < logging.CRITICAL else 1 diff --git a/tests/unit/models/test_divertor.py b/tests/unit/models/test_divertor.py index 6184c6a864..61aef5e3f9 100644 --- a/tests/unit/models/test_divertor.py +++ b/tests/unit/models/test_divertor.py @@ -14,7 +14,8 @@ def divertor(process_models): class TestDivertor: - def test_divtart(self, monkeypatch, divertor): + @staticmethod + def test_divtart(monkeypatch, divertor): """Test the divtart subroutine. Uses test data from the second call of this subroutine by FNSF regression test. @@ -54,7 +55,8 @@ def test_divtart(self, monkeypatch, divertor): assert pflux_div_heat_load_mw == pytest.approx(expected_pflux_div_heat_load_mw) - def test_divwade(self, monkeypatch, divertor): + @staticmethod + def test_divwade(monkeypatch, divertor): """Test the divwade subroutine. Uses test data from the second call of this subroutine by FNSF regression test. diff --git a/tests/unit/models/test_structure.py b/tests/unit/models/test_structure.py index 9b79c3898d..816ee4a626 100644 --- a/tests/unit/models/test_structure.py +++ b/tests/unit/models/test_structure.py @@ -16,7 +16,8 @@ def structure(): class TestStructure: - def test_structure(self, structure): + @staticmethod + def test_structure(structure): """Tests the structure subroutine""" expected_fncmass = 310716.52923547616 diff --git a/tests/unit/models/test_vacuum.py b/tests/unit/models/test_vacuum.py index f976f0ef5a..7c869820e2 100644 --- a/tests/unit/models/test_vacuum.py +++ b/tests/unit/models/test_vacuum.py @@ -24,7 +24,8 @@ def vacuum_vessel(process_models): class TestVacuum: - def test_simple_model(self, monkeypatch, vacuum): + @staticmethod + def test_simple_model(monkeypatch, vacuum): """Tests `vacuum_simple` subroutine. Values taken from first calling of the model in i_vacuum_pumping regression test. @@ -57,7 +58,8 @@ def test_simple_model(self, monkeypatch, vacuum): assert n_iter_vacuum_pumps == pytest.approx(14.082585474801862) - def test_old_model(self, monkeypatch, vacuum): + @staticmethod + def test_old_model(monkeypatch, vacuum): """Test `vacuum` subroutine. Values taken from first calling of the model in G-L_Nb-Ti regression test.