Skip to content

Commit

Permalink
Unused imports deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkumar committed Oct 27, 2023
1 parent a3419b7 commit 387e490
Show file tree
Hide file tree
Showing 52 changed files with 52 additions and 121 deletions.
1 change: 0 additions & 1 deletion examples/1_Simple/just_a_quadratic.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion examples/1_Simple/permanent_magnet_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
2 changes: 1 addition & 1 deletion examples/1_Simple/stage_two_optimization_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion examples/1_Simple/tracing_fieldlines_QA.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import time
import os
import logging
import sys
from pathlib import Path
import numpy as np

Expand Down
2 changes: 0 additions & 2 deletions examples/2_Intermediate/QSC.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

import logging
import numpy as np
from qsc import Qsc

from simsopt._core import Optimizable
Expand Down
6 changes: 3 additions & 3 deletions examples/2_Intermediate/boozerQA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions examples/2_Intermediate/permanent_magnet_MUSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
https://github.com/akaptano/simsopt_permanent_magnet_advanced_scripts.git
"""

import os
import pickle
import time
from pathlib import Path

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion examples/2_Intermediate/permanent_magnet_PM4Stell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Ken Hammond and the PM4Stell + MAGPIE teams.
'''

import os
from pathlib import Path
import time

Expand Down
3 changes: 0 additions & 3 deletions examples/2_Intermediate/permanent_magnet_QA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/2_Intermediate/stage_two_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions examples/3_Advanced/single_stage_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
##########################################################################################
Expand Down Expand Up @@ -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()}")
Expand Down
9 changes: 4 additions & 5 deletions examples/3_Advanced/single_stage_optimization_finite_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
##########################################################################################
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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()}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import os
from mpi4py import MPI
import numpy as np

from simsopt.mhd import Vmec
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/field/coil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion src/simsopt/field/mgrid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import numpy as np
from scipy.io import netcdf_file

Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/geo/curveperturbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/simsopt/geo/curverzfourier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np

import simsoptpp as sopp
from .._core.json import GSONDecoder
from .curve import Curve

__all__ = ['CurveRZFourier']
Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/geo/permanent_magnet_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/geo/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/geo/surfacegarabedian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/simsopt/mhd/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
6 changes: 3 additions & 3 deletions src/simsopt/mhd/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/objectives/least_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
3 changes: 1 addition & 2 deletions src/simsopt/solve/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

try:
from mpi4py import MPI
except ImportError as err:
except ImportError:

Check warning on line 22 in src/simsopt/solve/mpi.py

View check run for this annotation

Codecov / codecov/patch

src/simsopt/solve/mpi.py#L22

Added line #L22 was not covered by tests
MPI = None

from .._core.optimizable import Optimizable
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion tests/core/test_integrated.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
import logging

import numpy as np
from monty.tempfile import ScratchDir
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion tests/field/test_coil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest
import json
import os

import numpy as np
from monty.tempfile import ScratchDir
Expand Down
Loading

0 comments on commit 387e490

Please sign in to comment.