Skip to content

Commit 387e490

Browse files
committed
Unused imports deleted
1 parent a3419b7 commit 387e490

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+52
-121
lines changed

examples/1_Simple/just_a_quadratic.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22

3-
import logging
43
from simsopt.objectives.functions import Identity
54
from simsopt.objectives import LeastSquaresProblem
65
from simsopt.solve import least_squares_serial_solve

examples/1_Simple/permanent_magnet_simple.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from matplotlib import pyplot as plt
2727
from simsopt.field import DipoleField, ToroidalField
2828
from simsopt.geo import PermanentMagnetGrid, SurfaceRZFourier
29-
from simsopt.objectives import SquaredFlux
3029
from simsopt.solve import GPMO
3130
from simsopt.util.permanent_magnet_helper_functions import *
3231

examples/1_Simple/stage_two_optimization_minimal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def fun(dofs):
135135
""")
136136
res = minimize(fun, dofs, jac=True, method='L-BFGS-B',
137137
options={'maxiter': MAXITER, 'maxcor': 300, 'iprint': 5}, tol=1e-15)
138-
curves_to_vtk(curves, OUT_DIR + f"curves_opt", close=True)
138+
curves_to_vtk(curves, OUT_DIR + "curves_opt", close=True)
139139
pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]}
140140
s.to_vtk(OUT_DIR + "surf_opt", extra_data=pointData)
141141

examples/1_Simple/tracing_fieldlines_QA.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import time
1818
import os
1919
import logging
20-
import sys
2120
from pathlib import Path
2221
import numpy as np
2322

examples/2_Intermediate/QSC.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python3
22

3-
import logging
4-
import numpy as np
53
from qsc import Qsc
64

75
from simsopt._core import Optimizable

examples/2_Intermediate/boozerQA.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from simsopt.configs import get_ncsx_data
88
from simsopt.field import BiotSavart, coils_via_symmetries
99
from simsopt.geo import SurfaceXYZTensorFourier, BoozerSurface, curves_to_vtk, boozer_surface_residual, \
10-
ToroidalFlux, Volume, MajorRadius, CurveLength, CurveCurveDistance, NonQuasiSymmetricRatio, Iotas
10+
Volume, MajorRadius, CurveLength, NonQuasiSymmetricRatio, Iotas
1111
from simsopt.objectives import QuadraticPenalty
1212
from simsopt.util import in_github_actions
1313

@@ -83,7 +83,7 @@
8383
# sum the objectives together
8484
JF = J_nonQSRatio + J_iotas + J_major_radius + Jls
8585

86-
curves_to_vtk(curves, OUT_DIR + f"curves_init")
86+
curves_to_vtk(curves, OUT_DIR + "curves_init")
8787
boozer_surface.surface.to_vtk(OUT_DIR + "surf_init")
8888

8989
# let's fix the coil current
@@ -144,7 +144,7 @@ def fun(dofs):
144144
MAXITER = 50 if in_github_actions else 1e3
145145

146146
res = minimize(fun, dofs, jac=True, method='BFGS', options={'maxiter': MAXITER}, tol=1e-15)
147-
curves_to_vtk(curves, OUT_DIR + f"curves_opt")
147+
curves_to_vtk(curves, OUT_DIR + "curves_opt")
148148
boozer_surface.surface.to_vtk(OUT_DIR + "surf_opt")
149149

150150
print("End of 2_Intermediate/boozerQA.py")

examples/2_Intermediate/permanent_magnet_MUSE.py

-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
https://github.com/akaptano/simsopt_permanent_magnet_advanced_scripts.git
2222
"""
2323

24-
import os
25-
import pickle
2624
import time
2725
from pathlib import Path
2826

@@ -257,7 +255,6 @@
257255
# surface is at least 64 x 64 resolution.
258256
vmec_flag = False
259257
if vmec_flag:
260-
from mpi4py import MPI
261258
from simsopt.mhd.vmec import Vmec
262259
from simsopt.util.mpi import MpiPartition
263260
mpi = MpiPartition(ngroups=1)

examples/2_Intermediate/permanent_magnet_PM4Stell.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Ken Hammond and the PM4Stell + MAGPIE teams.
1616
'''
1717

18-
import os
1918
from pathlib import Path
2019
import time
2120

examples/2_Intermediate/permanent_magnet_QA.py

-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
are available to OpenMP, e.g. through setting OMP_NUM_THREADS).
3232
"""
3333

34-
import os
3534
import time
3635
from pathlib import Path
3736

3837
import numpy as np
39-
from matplotlib import pyplot as plt
4038

4139
from simsopt.field import BiotSavart, DipoleField
4240
from simsopt.geo import PermanentMagnetGrid, SurfaceRZFourier
@@ -242,7 +240,6 @@
242240
# surface is at least 64 x 64 resolution.
243241
vmec_flag = False
244242
if vmec_flag:
245-
from mpi4py import MPI
246243
from simsopt.mhd.vmec import Vmec
247244
from simsopt.util.mpi import MpiPartition
248245
mpi = MpiPartition(ngroups=1)

examples/2_Intermediate/stage_two_optimization.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def fun(dofs):
166166
################################################################################
167167
""")
168168
res = minimize(fun, dofs, jac=True, method='L-BFGS-B', options={'maxiter': MAXITER, 'maxcor': 300}, tol=1e-15)
169-
curves_to_vtk(curves, OUT_DIR + f"curves_opt_short")
169+
curves_to_vtk(curves, OUT_DIR + "curves_opt_short")
170170
pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]}
171171
s.to_vtk(OUT_DIR + "surf_opt_short", extra_data=pointData)
172172

@@ -177,7 +177,7 @@ def fun(dofs):
177177
dofs = res.x
178178
LENGTH_WEIGHT *= 0.1
179179
res = minimize(fun, dofs, jac=True, method='L-BFGS-B', options={'maxiter': MAXITER, 'maxcor': 300}, tol=1e-15)
180-
curves_to_vtk(curves, OUT_DIR + f"curves_opt_long")
180+
curves_to_vtk(curves, OUT_DIR + "curves_opt_long")
181181
pointData = {"B_N": np.sum(bs.B().reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)[:, :, None]}
182182
s.to_vtk(OUT_DIR + "surf_opt_long", extra_data=pointData)
183183

examples/3_Advanced/single_stage_optimization.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99
import os
1010
import numpy as np
11-
from mpi4py import MPI
1211
from pathlib import Path
1312
from scipy.optimize import minimize
1413
from simsopt.util import MpiPartition, proc0_print, comm_world
@@ -57,7 +56,7 @@
5756
ARCLENGTH_WEIGHT = 1e-9 # Weight for the arclength variation penalty in the objective function
5857
##########################################################################################
5958
##########################################################################################
60-
directory = f'optimization_QH'
59+
directory = 'optimization_QH'
6160
vmec_verbose = False
6261
# Create output directories
6362
this_path = os.path.join(parent_path, directory)
@@ -109,7 +108,7 @@
109108
J_LENGTH_PENALTY = LENGTH_CON_WEIGHT * sum([QuadraticPenalty(Jls[i], LENGTH_THRESHOLD) for i in range(len(base_curves))])
110109
JF = Jf + J_CC + J_LENGTH + J_LENGTH_PENALTY + J_CURVATURE + J_MSC
111110
##########################################################################################
112-
proc0_print(f' Starting optimization')
111+
proc0_print(' Starting optimization')
113112
##########################################################################################
114113
# Initial stage 2 optimization
115114
##########################################################################################
@@ -229,7 +228,7 @@ def fun(dofs, prob_jacobian=None, info={'Nfeval': 0}):
229228
pointData = {"B_N": BdotN_surf[:, :, None]}
230229
surf.to_vtk(os.path.join(coils_results_path, "surf_opt"), extra_data=pointData)
231230
bs.save(os.path.join(coils_results_path, "biot_savart_opt.json"))
232-
vmec.write_input(os.path.join(this_path, f'input.final'))
231+
vmec.write_input(os.path.join(this_path, 'input.final'))
233232
proc0_print(f"Aspect ratio after optimization: {vmec.aspect()}")
234233
proc0_print(f"Mean iota after optimization: {vmec.mean_iota()}")
235234
proc0_print(f"Quasisymmetry objective after optimization: {qs.total()}")

examples/3_Advanced/single_stage_optimization_finite_beta.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111
import os
1212
import numpy as np
13-
from mpi4py import MPI
1413
from math import isnan
1514
from pathlib import Path
1615
from scipy.optimize import minimize
@@ -62,7 +61,7 @@
6261
ARCLENGTH_WEIGHT = 1e-9 # Weight for the arclength variation penalty in the objective function
6362
##########################################################################################
6463
##########################################################################################
65-
directory = f'optimization_QH_finitebeta'
64+
directory = 'optimization_QH_finitebeta'
6665
vmec_verbose = False
6766
# Create output directories
6867
this_path = os.path.join(parent_path, directory)
@@ -122,7 +121,7 @@
122121
JF = Jf + J_CC + J_LENGTH + J_LENGTH_PENALTY + J_CURVATURE + J_MSC
123122

124123
##########################################################################################
125-
proc0_print(f' Starting optimization')
124+
proc0_print(' Starting optimization')
126125
##########################################################################################
127126
# Initial stage 2 optimization
128127
##########################################################################################
@@ -169,7 +168,7 @@ def fun_J(prob, coils_prob):
169168
try:
170169
vc = VirtualCasing.from_vmec(vmec, src_nphi=vc_src_nphi, trgt_nphi=nphi_VMEC, trgt_ntheta=ntheta_VMEC, filename=None)
171170
Jf.target = vc.B_external_normal
172-
except ObjectiveFailure as e:
171+
except ObjectiveFailure:
173172
pass
174173

175174
bs.set_points(surf.gamma().reshape((-1, 3)))
@@ -265,7 +264,7 @@ def fun(dofss, prob_jacobian, info={'Nfeval': 0}):
265264
pointData = {"B_N": BdotN_surf[:, :, None]}
266265
surf.to_vtk(os.path.join(coils_results_path, "surf_opt"), extra_data=pointData)
267266
bs.save(os.path.join(coils_results_path, "biot_savart_opt.json"))
268-
vmec.write_input(os.path.join(this_path, f'input.final'))
267+
vmec.write_input(os.path.join(this_path, 'input.final'))
269268
proc0_print(f"Aspect ratio after optimization: {vmec.aspect()}")
270269
proc0_print(f"Mean iota after optimization: {vmec.mean_iota()}")
271270
proc0_print(f"Quasisymmetry objective after optimization: {qs.total()}")

examples/stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
import os
4-
from mpi4py import MPI
54
import numpy as np
65

76
from simsopt.mhd import Vmec

examples/stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
import numpy as np
4-
from mpi4py import MPI
54

65
from simsopt.objectives import LeastSquaresProblem
76
from simsopt.mhd import Vmec

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ build-backend = "setuptools.build_meta"
77
[tool.ruff]
88
src = ["src/simsopt"]
99
ignore = ["E226","E265","E266","E4","E501","E701","E702","E712","E722","E731","E741","F403","F405","F406","W5"]
10+
extend-exclude = ["thirdparty"]
1011
[tool.ruff.per-file-ignores]
1112
"__init__.py" = ["E402","F401"]
13+
"src/simsopt/field/magneticfieldclasses.py" = ["E743"]
1214
"tests/verify_MPI_not_initialized.py" = ["F401"]
1315
"tests/geo/test_plot.py" = ["F401"]
1416
"tests/geo/test_curve.py" = ["F401"]

src/simsopt/field/coil.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from simsopt._core.optimizable import Optimizable
55
from simsopt._core.derivative import Derivative
66
from simsopt.geo.curvexyzfourier import CurveXYZFourier
7-
from simsopt.geo.curve import RotatedCurve, Curve
7+
from simsopt.geo.curve import RotatedCurve
88
import simsoptpp as sopp
99

1010

src/simsopt/field/mgrid.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import numpy as np
32
from scipy.io import netcdf_file
43

src/simsopt/geo/curveperturbed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
from sympy import Symbol, lambdify, exp
55

6-
from .._core.json import GSONable, GSONDecoder
6+
from .._core.json import GSONable
77
from .._core.util import RealArray
88

99
import simsoptpp as sopp

src/simsopt/geo/curverzfourier.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22

33
import simsoptpp as sopp
4-
from .._core.json import GSONDecoder
54
from .curve import Curve
65

76
__all__ = ['CurveRZFourier']

src/simsopt/geo/permanent_magnet_grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pyevtk.hl import pointsToVTK
66

77
from .._core.descriptor import OneofStrings
8-
from . import Surface, SurfaceRZFourier
8+
from . import Surface
99
import simsoptpp as sopp
1010

1111
__all__ = ['PermanentMagnetGrid']

src/simsopt/geo/surface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .._core.optimizable import Optimizable
1212
from .._core.dev import SimsoptRequires
1313
from .plotting import fix_matplotlib_3d
14-
from .._core.json import GSONable, GSONDecoder
14+
from .._core.json import GSONable
1515

1616
__all__ = ['Surface', 'signed_distance_from_surface', 'SurfaceClassifier', 'SurfaceScaled', 'best_nphi_over_ntheta']
1717

src/simsopt/geo/surfacegarabedian.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
import simsoptpp as sopp
6-
from .._core.descriptor import Integer, Float, PositiveInteger, OneofIntegers, OneofStrings
6+
from .._core.descriptor import Integer
77
from .surface import Surface
88
from .surfacerzfourier import SurfaceRZFourier
99

src/simsopt/mhd/profiles.py

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from .._core.optimizable import Optimizable
1818
from .._core.descriptor import PositiveInteger
19-
from .._core.types import RealArray
2019

2120
__all__ = ['Profile', 'ProfilePolynomial', 'ProfileScaled', 'ProfileSpline',
2221
'ProfilePressure', 'ProfileSpec']

src/simsopt/mhd/spec.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def run(self, update_guess: bool = True):
798798
si.zac[0:mn] = self.axis['zac']
799799

800800
# Set initial guess
801-
if not self.initial_guess is None:
801+
if self.initial_guess is not None:
802802
# Set all modes to zero
803803
spec.allglobal.mmrzrz[:] = 0
804804
spec.allglobal.nnrzrz[:] = 0
@@ -939,7 +939,7 @@ def run(self, update_guess: bool = True):
939939
spec.allglobal.broadcast_inputs()
940940
logger.debug('About to call preset')
941941
spec.preset()
942-
logger.debug(f'About to call init_outfile')
942+
logger.debug('About to call init_outfile')
943943
spec.sphdf5.init_outfile()
944944
logger.debug('About to call mirror_input_to_outfile')
945945
spec.sphdf5.mirror_input_to_outfile()
@@ -948,7 +948,7 @@ def run(self, update_guess: bool = True):
948948
spec.allglobal.wrtend()
949949
logger.debug('About to call init_convergence_output')
950950
spec.sphdf5.init_convergence_output()
951-
logger.debug(f'About to call spec')
951+
logger.debug('About to call spec')
952952
spec.spec()
953953
logger.debug('About to call diagnostics')
954954
spec.final_diagnostics()

src/simsopt/objectives/least_squares.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from .._core.optimizable import Optimizable
2020
from .._core.util import ObjectiveFailure
21-
from .._core.types import RealArray, IntArray, BoolArray
21+
from .._core.types import RealArray
2222

2323
__all__ = ['LeastSquaresProblem']
2424

src/simsopt/solve/mpi.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
try:
2121
from mpi4py import MPI
22-
except ImportError as err:
22+
except ImportError:
2323
MPI = None
2424

2525
from .._core.optimizable import Optimizable
@@ -494,7 +494,6 @@ def nlc_jac(x):
494494
if prob.has_nlc:
495495
constraint_file.close()
496496

497-
datalog_started = False
498497
logger.info("Completed solve.")
499498

500499
# Finally, make sure all procs get the optimal state vector.

tests/core/test_dev.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
except ImportError:
66
np = None
77

8-
from simsopt._core.dev import SimsoptRequires, deprecated
8+
from simsopt._core.dev import SimsoptRequires
99
from simsopt._core.optimizable import Optimizable
1010

1111

tests/core/test_integrated.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import unittest
2-
import logging
32

43
import numpy as np
54
from monty.tempfile import ScratchDir

tests/core/test_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
from simsopt._core.util import isnumber, isbool, unique, \
6-
ObjectiveFailure, finite_difference_steps, nested_lists_to_array
6+
finite_difference_steps, nested_lists_to_array
77

88

99
class IsboolTests(unittest.TestCase):

tests/field/test_coil.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
import json
3-
import os
43

54
import numpy as np
65
from monty.tempfile import ScratchDir

0 commit comments

Comments
 (0)