diff --git a/examples/1_Simple/just_a_quadratic.py b/examples/1_Simple/just_a_quadratic.py index 78a3c630a..f91e7b8d7 100755 --- a/examples/1_Simple/just_a_quadratic.py +++ b/examples/1_Simple/just_a_quadratic.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import logging from simsopt.objectives.functions import Identity from simsopt.objectives import LeastSquaresProblem from simsopt.solve import least_squares_serial_solve diff --git a/examples/1_Simple/permanent_magnet_simple.py b/examples/1_Simple/permanent_magnet_simple.py index 3276cadb7..f4b87dbfa 100755 --- a/examples/1_Simple/permanent_magnet_simple.py +++ b/examples/1_Simple/permanent_magnet_simple.py @@ -26,7 +26,6 @@ from matplotlib import pyplot as plt from simsopt.field import DipoleField, ToroidalField from simsopt.geo import PermanentMagnetGrid, SurfaceRZFourier -from simsopt.objectives import SquaredFlux from simsopt.solve import GPMO from simsopt.util.permanent_magnet_helper_functions import * diff --git a/examples/1_Simple/stage_two_optimization_minimal.py b/examples/1_Simple/stage_two_optimization_minimal.py index f9a7e287f..3b065e4f9 100755 --- a/examples/1_Simple/stage_two_optimization_minimal.py +++ b/examples/1_Simple/stage_two_optimization_minimal.py @@ -135,7 +135,7 @@ def fun(dofs): """) res = minimize(fun, dofs, jac=True, method='L-BFGS-B', options={'maxiter': MAXITER, 'maxcor': 300, 'iprint': 5}, tol=1e-15) -curves_to_vtk(curves, OUT_DIR + f"curves_opt", close=True) +curves_to_vtk(curves, OUT_DIR + "curves_opt", close=True) pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]} s.to_vtk(OUT_DIR + "surf_opt", extra_data=pointData) diff --git a/examples/1_Simple/tracing_fieldlines_QA.py b/examples/1_Simple/tracing_fieldlines_QA.py index b9b2572e9..a3357dd31 100755 --- a/examples/1_Simple/tracing_fieldlines_QA.py +++ b/examples/1_Simple/tracing_fieldlines_QA.py @@ -17,7 +17,6 @@ import time import os import logging -import sys from pathlib import Path import numpy as np diff --git a/examples/2_Intermediate/QSC.py b/examples/2_Intermediate/QSC.py index 195466b49..205c89fb5 100755 --- a/examples/2_Intermediate/QSC.py +++ b/examples/2_Intermediate/QSC.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -import logging -import numpy as np from qsc import Qsc from simsopt._core import Optimizable diff --git a/examples/2_Intermediate/boozerQA.py b/examples/2_Intermediate/boozerQA.py index 23eb398e0..ef7e36505 100755 --- a/examples/2_Intermediate/boozerQA.py +++ b/examples/2_Intermediate/boozerQA.py @@ -7,7 +7,7 @@ from simsopt.configs import get_ncsx_data from simsopt.field import BiotSavart, coils_via_symmetries from simsopt.geo import SurfaceXYZTensorFourier, BoozerSurface, curves_to_vtk, boozer_surface_residual, \ - ToroidalFlux, Volume, MajorRadius, CurveLength, CurveCurveDistance, NonQuasiSymmetricRatio, Iotas + Volume, MajorRadius, CurveLength, NonQuasiSymmetricRatio, Iotas from simsopt.objectives import QuadraticPenalty from simsopt.util import in_github_actions @@ -83,7 +83,7 @@ # sum the objectives together JF = J_nonQSRatio + J_iotas + J_major_radius + Jls -curves_to_vtk(curves, OUT_DIR + f"curves_init") +curves_to_vtk(curves, OUT_DIR + "curves_init") boozer_surface.surface.to_vtk(OUT_DIR + "surf_init") # let's fix the coil current @@ -144,7 +144,7 @@ def fun(dofs): MAXITER = 50 if in_github_actions else 1e3 res = minimize(fun, dofs, jac=True, method='BFGS', options={'maxiter': MAXITER}, tol=1e-15) -curves_to_vtk(curves, OUT_DIR + f"curves_opt") +curves_to_vtk(curves, OUT_DIR + "curves_opt") boozer_surface.surface.to_vtk(OUT_DIR + "surf_opt") print("End of 2_Intermediate/boozerQA.py") diff --git a/examples/2_Intermediate/permanent_magnet_MUSE.py b/examples/2_Intermediate/permanent_magnet_MUSE.py index 9f9a9b1d4..534d50331 100755 --- a/examples/2_Intermediate/permanent_magnet_MUSE.py +++ b/examples/2_Intermediate/permanent_magnet_MUSE.py @@ -21,8 +21,6 @@ https://github.com/akaptano/simsopt_permanent_magnet_advanced_scripts.git """ -import os -import pickle import time from pathlib import Path @@ -257,7 +255,6 @@ # surface is at least 64 x 64 resolution. vmec_flag = False if vmec_flag: - from mpi4py import MPI from simsopt.mhd.vmec import Vmec from simsopt.util.mpi import MpiPartition mpi = MpiPartition(ngroups=1) diff --git a/examples/2_Intermediate/permanent_magnet_PM4Stell.py b/examples/2_Intermediate/permanent_magnet_PM4Stell.py index 6febd3aa8..a9a1b0694 100755 --- a/examples/2_Intermediate/permanent_magnet_PM4Stell.py +++ b/examples/2_Intermediate/permanent_magnet_PM4Stell.py @@ -15,7 +15,6 @@ Ken Hammond and the PM4Stell + MAGPIE teams. ''' -import os from pathlib import Path import time diff --git a/examples/2_Intermediate/permanent_magnet_QA.py b/examples/2_Intermediate/permanent_magnet_QA.py index 16fb2f9a4..f263fc2ea 100755 --- a/examples/2_Intermediate/permanent_magnet_QA.py +++ b/examples/2_Intermediate/permanent_magnet_QA.py @@ -31,12 +31,10 @@ are available to OpenMP, e.g. through setting OMP_NUM_THREADS). """ -import os import time from pathlib import Path import numpy as np -from matplotlib import pyplot as plt from simsopt.field import BiotSavart, DipoleField from simsopt.geo import PermanentMagnetGrid, SurfaceRZFourier @@ -242,7 +240,6 @@ # surface is at least 64 x 64 resolution. vmec_flag = False if vmec_flag: - from mpi4py import MPI from simsopt.mhd.vmec import Vmec from simsopt.util.mpi import MpiPartition mpi = MpiPartition(ngroups=1) diff --git a/examples/2_Intermediate/stage_two_optimization.py b/examples/2_Intermediate/stage_two_optimization.py index 3dd147fcf..e71becd7f 100755 --- a/examples/2_Intermediate/stage_two_optimization.py +++ b/examples/2_Intermediate/stage_two_optimization.py @@ -166,7 +166,7 @@ def fun(dofs): ################################################################################ """) res = minimize(fun, dofs, jac=True, method='L-BFGS-B', options={'maxiter': MAXITER, 'maxcor': 300}, tol=1e-15) -curves_to_vtk(curves, OUT_DIR + f"curves_opt_short") +curves_to_vtk(curves, OUT_DIR + "curves_opt_short") pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]} s.to_vtk(OUT_DIR + "surf_opt_short", extra_data=pointData) @@ -177,7 +177,7 @@ def fun(dofs): dofs = res.x LENGTH_WEIGHT *= 0.1 res = minimize(fun, dofs, jac=True, method='L-BFGS-B', options={'maxiter': MAXITER, 'maxcor': 300}, tol=1e-15) -curves_to_vtk(curves, OUT_DIR + f"curves_opt_long") +curves_to_vtk(curves, OUT_DIR + "curves_opt_long") pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]} s.to_vtk(OUT_DIR + "surf_opt_long", extra_data=pointData) diff --git a/examples/3_Advanced/single_stage_optimization.py b/examples/3_Advanced/single_stage_optimization.py index 5f4dea3e1..546dda7e3 100755 --- a/examples/3_Advanced/single_stage_optimization.py +++ b/examples/3_Advanced/single_stage_optimization.py @@ -8,7 +8,6 @@ """ import os import numpy as np -from mpi4py import MPI from pathlib import Path from scipy.optimize import minimize from simsopt.util import MpiPartition, proc0_print, comm_world @@ -57,7 +56,7 @@ ARCLENGTH_WEIGHT = 1e-9 # Weight for the arclength variation penalty in the objective function ########################################################################################## ########################################################################################## -directory = f'optimization_QH' +directory = 'optimization_QH' vmec_verbose = False # Create output directories this_path = os.path.join(parent_path, directory) @@ -109,7 +108,7 @@ J_LENGTH_PENALTY = LENGTH_CON_WEIGHT * sum([QuadraticPenalty(Jls[i], LENGTH_THRESHOLD) for i in range(len(base_curves))]) JF = Jf + J_CC + J_LENGTH + J_LENGTH_PENALTY + J_CURVATURE + J_MSC ########################################################################################## -proc0_print(f' Starting optimization') +proc0_print(' Starting optimization') ########################################################################################## # Initial stage 2 optimization ########################################################################################## @@ -229,7 +228,7 @@ def fun(dofs, prob_jacobian=None, info={'Nfeval': 0}): pointData = {"B_N": BdotN_surf[:, :, None]} surf.to_vtk(os.path.join(coils_results_path, "surf_opt"), extra_data=pointData) bs.save(os.path.join(coils_results_path, "biot_savart_opt.json")) -vmec.write_input(os.path.join(this_path, f'input.final')) +vmec.write_input(os.path.join(this_path, 'input.final')) proc0_print(f"Aspect ratio after optimization: {vmec.aspect()}") proc0_print(f"Mean iota after optimization: {vmec.mean_iota()}") proc0_print(f"Quasisymmetry objective after optimization: {qs.total()}") diff --git a/examples/3_Advanced/single_stage_optimization_finite_beta.py b/examples/3_Advanced/single_stage_optimization_finite_beta.py index 88b4336d8..1c2696226 100755 --- a/examples/3_Advanced/single_stage_optimization_finite_beta.py +++ b/examples/3_Advanced/single_stage_optimization_finite_beta.py @@ -10,7 +10,6 @@ """ import os import numpy as np -from mpi4py import MPI from math import isnan from pathlib import Path from scipy.optimize import minimize @@ -62,7 +61,7 @@ ARCLENGTH_WEIGHT = 1e-9 # Weight for the arclength variation penalty in the objective function ########################################################################################## ########################################################################################## -directory = f'optimization_QH_finitebeta' +directory = 'optimization_QH_finitebeta' vmec_verbose = False # Create output directories this_path = os.path.join(parent_path, directory) @@ -122,7 +121,7 @@ JF = Jf + J_CC + J_LENGTH + J_LENGTH_PENALTY + J_CURVATURE + J_MSC ########################################################################################## -proc0_print(f' Starting optimization') +proc0_print(' Starting optimization') ########################################################################################## # Initial stage 2 optimization ########################################################################################## @@ -169,7 +168,7 @@ def fun_J(prob, coils_prob): try: vc = VirtualCasing.from_vmec(vmec, src_nphi=vc_src_nphi, trgt_nphi=nphi_VMEC, trgt_ntheta=ntheta_VMEC, filename=None) Jf.target = vc.B_external_normal - except ObjectiveFailure as e: + except ObjectiveFailure: pass bs.set_points(surf.gamma().reshape((-1, 3))) @@ -265,7 +264,7 @@ def fun(dofss, prob_jacobian, info={'Nfeval': 0}): pointData = {"B_N": BdotN_surf[:, :, None]} surf.to_vtk(os.path.join(coils_results_path, "surf_opt"), extra_data=pointData) bs.save(os.path.join(coils_results_path, "biot_savart_opt.json")) -vmec.write_input(os.path.join(this_path, f'input.final')) +vmec.write_input(os.path.join(this_path, 'input.final')) proc0_print(f"Aspect ratio after optimization: {vmec.aspect()}") proc0_print(f"Mean iota after optimization: {vmec.mean_iota()}") proc0_print(f"Quasisymmetry objective after optimization: {qs.total()}") diff --git a/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py b/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py index fe66f1558..cc348d432 100755 --- a/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py +++ b/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import os -from mpi4py import MPI import numpy as np from simsopt.mhd import Vmec diff --git a/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py b/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py index 457a1aa77..90d990436 100755 --- a/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py +++ b/examples/stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import numpy as np -from mpi4py import MPI from simsopt.objectives import LeastSquaresProblem from simsopt.mhd import Vmec diff --git a/pyproject.toml b/pyproject.toml index 65e1c03dd..4e3a99f8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,8 +7,10 @@ build-backend = "setuptools.build_meta" [tool.ruff] src = ["src/simsopt"] ignore = ["E226","E265","E266","E4","E501","E701","E702","E712","E722","E731","E741","F403","F405","F406","W5"] +extend-exclude = ["thirdparty"] [tool.ruff.per-file-ignores] "__init__.py" = ["E402","F401"] +"src/simsopt/field/magneticfieldclasses.py" = ["E743"] "tests/verify_MPI_not_initialized.py" = ["F401"] "tests/geo/test_plot.py" = ["F401"] "tests/geo/test_curve.py" = ["F401"] diff --git a/src/simsopt/field/coil.py b/src/simsopt/field/coil.py index 86dc2b522..e2ab7dd0b 100644 --- a/src/simsopt/field/coil.py +++ b/src/simsopt/field/coil.py @@ -4,7 +4,7 @@ from simsopt._core.optimizable import Optimizable from simsopt._core.derivative import Derivative from simsopt.geo.curvexyzfourier import CurveXYZFourier -from simsopt.geo.curve import RotatedCurve, Curve +from simsopt.geo.curve import RotatedCurve import simsoptpp as sopp diff --git a/src/simsopt/field/mgrid.py b/src/simsopt/field/mgrid.py index 21c83b91b..e7873ee03 100644 --- a/src/simsopt/field/mgrid.py +++ b/src/simsopt/field/mgrid.py @@ -1,4 +1,3 @@ -import sys import numpy as np from scipy.io import netcdf_file diff --git a/src/simsopt/geo/curveperturbed.py b/src/simsopt/geo/curveperturbed.py index 2b2255803..14ce54e16 100644 --- a/src/simsopt/geo/curveperturbed.py +++ b/src/simsopt/geo/curveperturbed.py @@ -3,7 +3,7 @@ import numpy as np from sympy import Symbol, lambdify, exp -from .._core.json import GSONable, GSONDecoder +from .._core.json import GSONable from .._core.util import RealArray import simsoptpp as sopp diff --git a/src/simsopt/geo/curverzfourier.py b/src/simsopt/geo/curverzfourier.py index c92d55a60..fc8eb219c 100644 --- a/src/simsopt/geo/curverzfourier.py +++ b/src/simsopt/geo/curverzfourier.py @@ -1,7 +1,6 @@ import numpy as np import simsoptpp as sopp -from .._core.json import GSONDecoder from .curve import Curve __all__ = ['CurveRZFourier'] diff --git a/src/simsopt/geo/permanent_magnet_grid.py b/src/simsopt/geo/permanent_magnet_grid.py index 7ffbb40bc..88ee65b6a 100644 --- a/src/simsopt/geo/permanent_magnet_grid.py +++ b/src/simsopt/geo/permanent_magnet_grid.py @@ -5,7 +5,7 @@ from pyevtk.hl import pointsToVTK from .._core.descriptor import OneofStrings -from . import Surface, SurfaceRZFourier +from . import Surface import simsoptpp as sopp __all__ = ['PermanentMagnetGrid'] diff --git a/src/simsopt/geo/surface.py b/src/simsopt/geo/surface.py index 8221d0e4a..cd055ac8f 100644 --- a/src/simsopt/geo/surface.py +++ b/src/simsopt/geo/surface.py @@ -11,7 +11,7 @@ from .._core.optimizable import Optimizable from .._core.dev import SimsoptRequires from .plotting import fix_matplotlib_3d -from .._core.json import GSONable, GSONDecoder +from .._core.json import GSONable __all__ = ['Surface', 'signed_distance_from_surface', 'SurfaceClassifier', 'SurfaceScaled', 'best_nphi_over_ntheta'] diff --git a/src/simsopt/geo/surfacegarabedian.py b/src/simsopt/geo/surfacegarabedian.py index 36de86a1f..7fcb66c7e 100644 --- a/src/simsopt/geo/surfacegarabedian.py +++ b/src/simsopt/geo/surfacegarabedian.py @@ -3,7 +3,7 @@ import numpy as np import simsoptpp as sopp -from .._core.descriptor import Integer, Float, PositiveInteger, OneofIntegers, OneofStrings +from .._core.descriptor import Integer from .surface import Surface from .surfacerzfourier import SurfaceRZFourier diff --git a/src/simsopt/mhd/profiles.py b/src/simsopt/mhd/profiles.py index f9c3b7ae6..ac4d7528c 100644 --- a/src/simsopt/mhd/profiles.py +++ b/src/simsopt/mhd/profiles.py @@ -16,7 +16,6 @@ from .._core.optimizable import Optimizable from .._core.descriptor import PositiveInteger -from .._core.types import RealArray __all__ = ['Profile', 'ProfilePolynomial', 'ProfileScaled', 'ProfileSpline', 'ProfilePressure', 'ProfileSpec'] diff --git a/src/simsopt/mhd/spec.py b/src/simsopt/mhd/spec.py index c4347275a..f708e57a6 100644 --- a/src/simsopt/mhd/spec.py +++ b/src/simsopt/mhd/spec.py @@ -798,7 +798,7 @@ def run(self, update_guess: bool = True): si.zac[0:mn] = self.axis['zac'] # Set initial guess - if not self.initial_guess is None: + if self.initial_guess is not None: # Set all modes to zero spec.allglobal.mmrzrz[:] = 0 spec.allglobal.nnrzrz[:] = 0 @@ -939,7 +939,7 @@ def run(self, update_guess: bool = True): spec.allglobal.broadcast_inputs() logger.debug('About to call preset') spec.preset() - logger.debug(f'About to call init_outfile') + logger.debug('About to call init_outfile') spec.sphdf5.init_outfile() logger.debug('About to call mirror_input_to_outfile') spec.sphdf5.mirror_input_to_outfile() @@ -948,7 +948,7 @@ def run(self, update_guess: bool = True): spec.allglobal.wrtend() logger.debug('About to call init_convergence_output') spec.sphdf5.init_convergence_output() - logger.debug(f'About to call spec') + logger.debug('About to call spec') spec.spec() logger.debug('About to call diagnostics') spec.final_diagnostics() diff --git a/src/simsopt/objectives/least_squares.py b/src/simsopt/objectives/least_squares.py index 16e146f0f..029ca806e 100644 --- a/src/simsopt/objectives/least_squares.py +++ b/src/simsopt/objectives/least_squares.py @@ -18,7 +18,7 @@ from .._core.optimizable import Optimizable from .._core.util import ObjectiveFailure -from .._core.types import RealArray, IntArray, BoolArray +from .._core.types import RealArray __all__ = ['LeastSquaresProblem'] diff --git a/src/simsopt/solve/mpi.py b/src/simsopt/solve/mpi.py index 8b5f8ae44..9c92009ea 100644 --- a/src/simsopt/solve/mpi.py +++ b/src/simsopt/solve/mpi.py @@ -19,7 +19,7 @@ try: from mpi4py import MPI -except ImportError as err: +except ImportError: MPI = None from .._core.optimizable import Optimizable @@ -494,7 +494,6 @@ def nlc_jac(x): if prob.has_nlc: constraint_file.close() - datalog_started = False logger.info("Completed solve.") # Finally, make sure all procs get the optimal state vector. diff --git a/tests/core/test_dev.py b/tests/core/test_dev.py index 95072266f..0a02ab75e 100644 --- a/tests/core/test_dev.py +++ b/tests/core/test_dev.py @@ -5,7 +5,7 @@ except ImportError: np = None -from simsopt._core.dev import SimsoptRequires, deprecated +from simsopt._core.dev import SimsoptRequires from simsopt._core.optimizable import Optimizable diff --git a/tests/core/test_integrated.py b/tests/core/test_integrated.py index fe7b1d702..d1ad153d4 100755 --- a/tests/core/test_integrated.py +++ b/tests/core/test_integrated.py @@ -1,5 +1,4 @@ import unittest -import logging import numpy as np from monty.tempfile import ScratchDir diff --git a/tests/core/test_util.py b/tests/core/test_util.py index f9e702d79..4f29ab370 100755 --- a/tests/core/test_util.py +++ b/tests/core/test_util.py @@ -3,7 +3,7 @@ import numpy as np from simsopt._core.util import isnumber, isbool, unique, \ - ObjectiveFailure, finite_difference_steps, nested_lists_to_array + finite_difference_steps, nested_lists_to_array class IsboolTests(unittest.TestCase): diff --git a/tests/field/test_coil.py b/tests/field/test_coil.py index de0befb1f..0b1125b34 100644 --- a/tests/field/test_coil.py +++ b/tests/field/test_coil.py @@ -1,6 +1,5 @@ import unittest import json -import os import numpy as np from monty.tempfile import ScratchDir diff --git a/tests/field/test_fieldline.py b/tests/field/test_fieldline.py index 5958f6c21..1ebcfb09f 100644 --- a/tests/field/test_fieldline.py +++ b/tests/field/test_fieldline.py @@ -9,15 +9,13 @@ from simsopt.field.coil import coils_via_symmetries, Coil, Current from simsopt.geo.curvehelical import CurveHelical from simsopt.geo.curvexyzfourier import CurveXYZFourier -import simsoptpp as sopp logging.basicConfig() try: import pyevtk - with_evtk = True except ImportError: - with_evtk = False + pyevtk = None def validate_phi_hits(phi_hits, nphis): @@ -53,7 +51,7 @@ def test_poincare_toroidal(self): assert np.allclose(res_tys[i][:, 3], 0.) assert np.allclose(np.linalg.norm(res_tys[i][:, 1:3], axis=1), R0[i]) assert validate_phi_hits(res_phi_hits[i], nphis) - if with_evtk: + if pyevtk is not None: particles_to_vtk(res_tys, '/tmp/fieldlines') def test_poincare_tokamak(self): diff --git a/tests/field/test_mpi_tracing.py b/tests/field/test_mpi_tracing.py index 4b6a1163b..b94248202 100644 --- a/tests/field/test_mpi_tracing.py +++ b/tests/field/test_mpi_tracing.py @@ -15,7 +15,6 @@ from simsopt.field.tracing import trace_particles_starting_on_curve, compute_fieldlines from simsopt.field.magneticfieldclasses import InterpolatedField, UniformInterpolationRule from simsopt.util.constants import PROTON_MASS, ELEMENTARY_CHARGE, ONE_EV -import simsoptpp as sopp class MPITracingTesting(unittest.TestCase): diff --git a/tests/field/test_normal_field.py b/tests/field/test_normal_field.py index 671392ba0..ea639b563 100644 --- a/tests/field/test_normal_field.py +++ b/tests/field/test_normal_field.py @@ -9,7 +9,7 @@ try: import py_spec -except ImportError as e: +except ImportError: py_spec = None from . import TEST_DIR diff --git a/tests/geo/surface_test_helpers.py b/tests/geo/surface_test_helpers.py index 1189135df..6effa0e37 100644 --- a/tests/geo/surface_test_helpers.py +++ b/tests/geo/surface_test_helpers.py @@ -3,7 +3,7 @@ import numpy as np from simsopt.configs import get_ncsx_data from simsopt.field import coils_via_symmetries, BiotSavart -from simsopt.geo import Volume, Area, ToroidalFlux, SurfaceXYZFourier, SurfaceRZFourier, SurfaceXYZTensorFourier, BoozerSurface, MajorRadius +from simsopt.geo import Volume, Area, ToroidalFlux, SurfaceXYZFourier, SurfaceRZFourier, SurfaceXYZTensorFourier, BoozerSurface TEST_DIR = Path(__file__).parent / ".." / "test_files" diff --git a/tests/geo/test_curve_optimizable.py b/tests/geo/test_curve_optimizable.py index 5fccfed4f..fc8eb4606 100644 --- a/tests/geo/test_curve_optimizable.py +++ b/tests/geo/test_curve_optimizable.py @@ -3,7 +3,6 @@ from monty.tempfile import ScratchDir -from simsopt.geo.curvexyzfourier import CurveXYZFourier, JaxCurveXYZFourier from simsopt.geo.curverzfourier import CurveRZFourier from simsopt.geo.curve import RotatedCurve from simsopt.geo import parameters diff --git a/tests/geo/test_finitebuild.py b/tests/geo/test_finitebuild.py index d1a90ff14..fe890fa29 100644 --- a/tests/geo/test_finitebuild.py +++ b/tests/geo/test_finitebuild.py @@ -1,11 +1,10 @@ import unittest -from .surface_test_helpers import get_surface, get_exact_surface +from .surface_test_helpers import get_surface from simsopt.field.biotsavart import BiotSavart from simsopt.field.coil import Coil, apply_symmetries_to_curves, apply_symmetries_to_currents from simsopt.geo.curveobjectives import CurveLength, CurveCurveDistance from simsopt.geo import CurveFilament, FrameRotation, \ create_multifilament_grid, ZeroRotation, FramedCurveCentroid, FramedCurveFrenet -from simsopt.geo.qfmsurface import QfmSurface from simsopt.objectives.fluxobjective import SquaredFlux from simsopt.objectives.utilities import QuadraticPenalty from simsopt.configs.zoo import get_ncsx_data diff --git a/tests/geo/test_pm_grid.py b/tests/geo/test_pm_grid.py index a680c5849..524b69e4d 100644 --- a/tests/geo/test_pm_grid.py +++ b/tests/geo/test_pm_grid.py @@ -3,15 +3,12 @@ import numpy as np from monty.tempfile import ScratchDir -import simsoptpp as sopp -from simsopt.field import (BiotSavart, Current, DipoleField, InterpolatedField, - coils_via_symmetries, Coil) +from simsopt.field import (BiotSavart, Current, DipoleField, coils_via_symmetries, Coil) from simsopt.geo import (PermanentMagnetGrid, SurfaceRZFourier, SurfaceXYZFourier, create_equally_spaced_curves) from simsopt.objectives import SquaredFlux from simsopt.solve import GPMO, relax_and_split -from pyevtk.hl import pointsToVTK from simsopt.util import * from simsopt.util.polarization_project import (faceedge_vectors, facecorner_vectors, pol_e, pol_f, pol_fe, pol_c, diff --git a/tests/geo/test_surface_garabedian.py b/tests/geo/test_surface_garabedian.py index 14e98fa72..7e61ab49d 100755 --- a/tests/geo/test_surface_garabedian.py +++ b/tests/geo/test_surface_garabedian.py @@ -11,11 +11,6 @@ stellsym_list = [True, False] -try: - import pyevtk - pyevtk_found = True -except ImportError: - pyevtk_found = False #logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) diff --git a/tests/geo/test_surface_rzfourier.py b/tests/geo/test_surface_rzfourier.py index e9330b875..71a070ad0 100755 --- a/tests/geo/test_surface_rzfourier.py +++ b/tests/geo/test_surface_rzfourier.py @@ -1,6 +1,5 @@ import unittest from pathlib import Path -import json from qsc import Qsc import numpy as np @@ -15,12 +14,6 @@ stellsym_list = [True, False] -try: - import pyevtk - pyevtk_found = True -except ImportError: - pyevtk_found = False - class SurfaceRZFourierTests(unittest.TestCase): @@ -75,19 +68,6 @@ def test_shared_dof_init(self): self.assertAlmostEqual(s2.area(), true_area, places=4) self.assertAlmostEqual(s2.volume(), true_volume, places=3) - def test_area_volume(self): - """ - Test the calculation of area and volume for an axisymmetric surface - """ - s = SurfaceRZFourier() - s.rc[0, 0] = 1.3 - s.rc[1, 0] = 0.4 - s.zs[1, 0] = 0.2 - - true_area = 15.827322032265993 - true_volume = 2.0528777154265874 - self.assertAlmostEqual(s.area(), true_area, places=4) - self.assertAlmostEqual(s.volume(), true_volume, places=3) def test_get_dofs(self): """ @@ -748,10 +728,8 @@ def test_convert_back(self): filename = TEST_DIR / 'input.li383_low_res' s1 = SurfaceRZFourier.from_vmec_input(filename) #print('Original SurfaceRZFourier dofs:', s1.x) - x1 = s1.x s2 = SurfaceRZPseudospectral.from_RZFourier(s1, r_shift=2.2, a_scale=0.4) s3 = s2.to_RZFourier() - x3 = s3.x #for j, name in enumerate(s1.local_dof_names): # print(name, x1[j], x3[j], x1[j] - x3[j]) np.testing.assert_allclose(s1.full_x, s3.full_x) diff --git a/tests/geo/test_surfacehenneberg.py b/tests/geo/test_surfacehenneberg.py index 8d479cdc4..4d860d543 100755 --- a/tests/geo/test_surfacehenneberg.py +++ b/tests/geo/test_surfacehenneberg.py @@ -19,11 +19,10 @@ try: import vmec - vmec_found = True except ImportError: - vmec_found = False + vmec = None -if (MPI is not None) and vmec_found: +if (MPI is not None) and vmec is not None: from simsopt.mhd.vmec import Vmec else: Vmec = None @@ -102,12 +101,6 @@ def test_fixed_range(self): """ surf = SurfaceHenneberg(nfp=1, alpha_fac=1, mmax=2, nmax=1) # Order of elements: - names_correct = ['R0nH(0)', 'R0nH(1)', - 'Z0nH(1)', - 'bn(0)', 'bn(1)', - 'rhomn(0,1)', - 'rhomn(1,-1)', 'rhomn(1,0)', 'rhomn(1,1)', - 'rhomn(2,-1)', 'rhomn(2,0)', 'rhomn(2,1)'] surf.fixed_range(20, 20, True) np.testing.assert_equal(surf.local_dofs_free_status, [False]*12) surf.fixed_range(20, 20, False) diff --git a/tests/mhd/test_bootstrap.py b/tests/mhd/test_bootstrap.py index 9a0fdea1f..8ca7e248c 100755 --- a/tests/mhd/test_bootstrap.py +++ b/tests/mhd/test_bootstrap.py @@ -15,12 +15,12 @@ try: import booz_xform -except ImportError as e: +except ImportError: booz_xform = None try: import vmec as vmec_extension -except ImportError as e: +except ImportError: vmec_extension = None logger = logging.getLogger(__name__) diff --git a/tests/mhd/test_integrated_vmec_mpi.py b/tests/mhd/test_integrated_vmec_mpi.py index 17186ce25..14b2ddb2e 100755 --- a/tests/mhd/test_integrated_vmec_mpi.py +++ b/tests/mhd/test_integrated_vmec_mpi.py @@ -2,7 +2,6 @@ import logging import numpy as np -from monty.tempfile import ScratchDir try: from mpi4py import MPI except ImportError: @@ -46,7 +45,7 @@ def test_stellopt_scenarios_1DOF_circularCrossSection_varyR0_targetVolume(self): # logging.basicConfig(level=logging.DEBUG) # logger = logging.getLogger('[{}]'.format(MPI.COMM_WORLD.Get_rank()) + __name__) - logger = logging.getLogger(__name__) + logging.getLogger(__name__) for ngroups in range(1, 1 + MPI.COMM_WORLD.Get_size()): for grad in [False, True]: # In the next line, we can adjust how many groups the pool of MPI diff --git a/tests/mhd/test_profiles.py b/tests/mhd/test_profiles.py index eda67f0de..25fa529eb 100755 --- a/tests/mhd/test_profiles.py +++ b/tests/mhd/test_profiles.py @@ -199,13 +199,12 @@ def test_pressure_exception(self): nD = ProfileScaled(ne, 0.55) nT = ProfileScaled(ne, 0.45) TD = ProfilePolynomial(12.0e3 * np.array([1.0, -1.0])) - TT = TD # Try zero profiles: with self.assertRaises(ValueError): - pressure = ProfilePressure() + ProfilePressure() with self.assertRaises(ValueError): - pressure = ProfilePressure(ne) + ProfilePressure(ne) with self.assertRaises(ValueError): - pressure = ProfilePressure(ne, Te, nD) + ProfilePressure(ne, Te, nD) with self.assertRaises(ValueError): - pressure = ProfilePressure(ne, Te, nD, TD, nT) + ProfilePressure(ne, Te, nD, TD, nT) diff --git a/tests/mhd/test_spec.py b/tests/mhd/test_spec.py index 650f227a0..0ab5fb536 100755 --- a/tests/mhd/test_spec.py +++ b/tests/mhd/test_spec.py @@ -1,7 +1,5 @@ -from cmath import isnan import logging import os -import shutil import unittest import numpy as np diff --git a/tests/objectives/test_constrained.py b/tests/objectives/test_constrained.py index f96215ddf..8a3e0d8fd 100755 --- a/tests/objectives/test_constrained.py +++ b/tests/objectives/test_constrained.py @@ -1,5 +1,4 @@ import unittest -import logging import numpy as np from simsopt.objectives.functions import Identity, Rosenbrock, Failer, Affine from simsopt.objectives.constrained import ConstrainedProblem diff --git a/tests/objectives/test_fluxobjective.py b/tests/objectives/test_fluxobjective.py index 173423273..a58d56615 100755 --- a/tests/objectives/test_fluxobjective.py +++ b/tests/objectives/test_fluxobjective.py @@ -61,13 +61,13 @@ def test_definitions(self): np.testing.assert_allclose(J3, should_be3) with self.assertRaises(ValueError): - J4 = SquaredFlux(surf, bs, target, definition="foobar") + SquaredFlux(surf, bs, target, definition="foobar") def check_taylor_test(self, J): dofs = J.x np.random.seed(1) h = np.random.uniform(size=dofs.shape) - J0, dJ0 = J.J(), J.dJ() + dJ0 = J.dJ() dJh = sum(dJ0 * h) err_old = 1e10 for i in range(11, 17): diff --git a/tests/objectives/test_least_squares.py b/tests/objectives/test_least_squares.py index a67d7f535..939dfcfa5 100755 --- a/tests/objectives/test_least_squares.py +++ b/tests/objectives/test_least_squares.py @@ -1,7 +1,6 @@ import unittest -import logging import numpy as np -from simsopt.objectives.functions import Identity, Rosenbrock +from simsopt.objectives.functions import Identity #from simsopt.core.optimizable import Target from simsopt.objectives.least_squares import LeastSquaresProblem @@ -37,11 +36,11 @@ def test_exceptions(self): # sigma cannot be zero with self.assertRaises(ValueError): - lst = LeastSquaresProblem.from_sigma(3, 0, depends_on=iden) + LeastSquaresProblem.from_sigma(3, 0, depends_on=iden) # Weight cannot be negative with self.assertRaises(ValueError): - lst = LeastSquaresProblem(3, -1.0, depends_on=iden) + LeastSquaresProblem(3, -1.0, depends_on=iden) def test_multiple_funcs_single_input(self): iden1 = Identity(x=10) diff --git a/tests/objectives/test_utilities.py b/tests/objectives/test_utilities.py index a522ebcf0..5357cd6cd 100644 --- a/tests/objectives/test_utilities.py +++ b/tests/objectives/test_utilities.py @@ -4,7 +4,7 @@ import numpy as np from simsopt.geo.curvexyzfourier import CurveXYZFourier -from simsopt.geo.curveobjectives import CurveLength, LpCurveCurvature, LpCurveTorsion +from simsopt.geo.curveobjectives import CurveLength, LpCurveTorsion from simsopt.objectives.utilities import MPIObjective, QuadraticPenalty from simsopt.geo import parameters from simsopt._core.json import GSONDecoder, GSONEncoder, SIMSON diff --git a/tests/solve/test_constrained.py b/tests/solve/test_constrained.py index fd8ca889e..a350b1d7e 100755 --- a/tests/solve/test_constrained.py +++ b/tests/solve/test_constrained.py @@ -8,9 +8,9 @@ MPI = None from simsopt._core.optimizable import Optimizable -from simsopt.objectives.functions import Identity, Rosenbrock, Affine +from simsopt.objectives.functions import Rosenbrock from simsopt.objectives.constrained import ConstrainedProblem -from simsopt.solve.serial import constrained_serial_solve, serial_solve +from simsopt.solve.serial import constrained_serial_solve if MPI is not None: from simsopt.util.mpi import MpiPartition from simsopt.solve.mpi import constrained_mpi_solve diff --git a/tests/solve/test_least_squares.py b/tests/solve/test_least_squares.py index ccda66181..a2a04d77f 100755 --- a/tests/solve/test_least_squares.py +++ b/tests/solve/test_least_squares.py @@ -9,7 +9,7 @@ from simsopt.objectives.functions import Identity, Rosenbrock from simsopt.objectives.least_squares import LeastSquaresProblem -from simsopt.solve.serial import least_squares_serial_solve, serial_solve +from simsopt.solve.serial import least_squares_serial_solve if MPI is not None: from simsopt.util.mpi import MpiPartition from simsopt.solve.mpi import least_squares_mpi_solve diff --git a/tests/solve/test_mpi.py b/tests/solve/test_mpi.py index b58ea6d6b..e98574714 100755 --- a/tests/solve/test_mpi.py +++ b/tests/solve/test_mpi.py @@ -9,7 +9,6 @@ MPI = None from simsopt._core.optimizable import Optimizable -from simsopt.objectives.functions import Beale from simsopt.objectives.least_squares import LeastSquaresProblem if MPI is not None: from simsopt.util.mpi import MpiPartition diff --git a/tests/util/test_mpi_partition.py b/tests/util/test_mpi_partition.py index 18bfd36d2..3a3ddfbff 100755 --- a/tests/util/test_mpi_partition.py +++ b/tests/util/test_mpi_partition.py @@ -8,7 +8,7 @@ if MPI is not None: from simsopt.util.mpi import MpiPartition -from simsopt.util import proc0_print, comm_world +from simsopt.util import proc0_print # logging.basicConfig(level=logging.DEBUG) # logger = logging.getLogger('[{}]'.format(MPI.COMM_WORLD.Get_rank()) + __name__)