Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability hotfix #266

Merged
merged 6 commits into from
Sep 22, 2022
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
4 changes: 3 additions & 1 deletion desc/compute/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ def compute_geometry(
data["a"] = jnp.sqrt(data["A"] / jnp.pi)
data["R0/a"] = data["V"] / (2 * jnp.sqrt(jnp.pi * data["A"] ** 3))
if check_derivs("V_rr(r)", R_transform, Z_transform):
data["V_rr(r)"] = surface_integrals(grid, jnp.abs(data["sqrt(g)_r"]))
data["V_rr(r)"] = surface_integrals(
grid, data["sqrt(g)_r"] * jnp.sign(data["sqrt(g)"])
)

return data
10 changes: 5 additions & 5 deletions desc/compute/_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,19 @@ def compute_magnetic_well(
# Thermal pressure is constant over a rho surface.
# surface average(pressure) = thermal + surface average(magnetic)
dp_drho = 2 * mu_0 * data["p_r"]
dB2_drho_avg = (
dB2_avg_drho = (
surface_integrals(
grid,
jnp.abs(data["sqrt(g)_r"]) * data["|B|^2"]
data["sqrt(g)_r"] * jnp.sign(data["sqrt(g)"]) * data["|B|^2"]
+ jnp.abs(data["sqrt(g)"]) * 2 * dot(data["B"], data["B_r"]),
)
- surface_integrals(grid, jnp.abs(data["sqrt(g)_r"])) * B2_avg
- data["V_rr(r)"] * B2_avg
) / data["V_r(r)"]
data["magnetic well"] = (
data["V(r)"] * (dp_drho + dB2_drho_avg) / (data["V_r(r)"] * B2_avg)
data["V(r)"] * (dp_drho + dB2_avg_drho) / (data["V_r(r)"] * B2_avg)
)

# equivalent method (besides scaling factor) that avoids computing the volume
# data["magnetic well"] = data["rho"] * (dp_drho + dB2_drho_avg) / B2_avg
# data["magnetic well"] = data["rho"] * (dp_drho + dB2_avg_drho) / B2_avg

return data
4 changes: 2 additions & 2 deletions desc/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def solve(
print("Start of solver")
objective.print_value(objective.x(eq))
for key, value in result["history"].items():
# don't set nonexistent profile
# don't set nonexistent profile (values are empty ndarrays)
if not (key == "c_l" or key == "i_l") or value[-1].size:
setattr(eq, key, value[-1])

Expand Down Expand Up @@ -474,7 +474,7 @@ def optimize(
print("Start of solver")
objective.print_value(objective.x(eq))
for key, value in result["history"].items():
# don't set nonexistent profile
# don't set nonexistent profile (values are empty ndarrays)
if not (key == "c_l" or key == "i_l") or value[-1].size:
setattr(eq, key, value[-1])
if verbose > 0:
Expand Down
4 changes: 2 additions & 2 deletions desc/perturbations.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def perturb(
value = put( # parameter values below threshold are set to 0
value, np.where(np.abs(value) < 10 * np.finfo(value.dtype).eps)[0], 0
)
# don't set nonexistent profile
# don't set nonexistent profile (values are empty ndarrays)
if not (key == "c_l" or key == "i_l") or value.size:
setattr(eq_new, key, value)

Expand Down Expand Up @@ -696,7 +696,7 @@ def optimal_perturb(
value = put( # parameter values below threshold are set to 0
value, np.where(np.abs(value) < 10 * np.finfo(value.dtype).eps)[0], 0
)
# don't set nonexistent profile
# don't set nonexistent profile (values are empty ndarrays)
if not (key == "c_l" or key == "i_l") or value.size:
setattr(eq_new, key, value)

Expand Down
16 changes: 8 additions & 8 deletions devtools/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
Scripts for Linting with Pylint and Flake8
##########################################

Useage
Usage
======

To use, run either the run_pylint_linting.sh or run_flake8_linting.sh scripts

These will generate a pylint.output file, or flake8_errors.ouput and flake8_summary.output files.

Currently, black is still ran through github actions.
Currently, black is still ran through GitHub actions.

Most formatting-level errors are being supressed; errors that touch the code logic are primarily the ones being raised.
Most formatting-level errors are being suppressed; errors that touch the code logic are primarily the ones being raised.

Currently, black is still ran through github actions.
Currently, black is still ran through GitHub actions.



Expand All @@ -40,13 +40,13 @@ Configuration
Flake8
------

Currently, error messages about whitespace and indenting that black does not care about have been supressed.
Currently, error messages about whitespace and indenting that black does not care about have been suppressed.
These will be fixed in a future cleanup branch.
More errors can be added to the [flake8] section of settings.cfg after "ignore=", seperated by commas.
More errors can be added to the [flake8] section of settings.cfg after "ignore=", separated by commas.

Pylint:
-------
Currently several classes of error are being supressed, mostly to do with preferring encapsulating behavior into simpler classes and modules.
Currently several classes of error are being suppressed, mostly to do with preferring encapsulating behavior into simpler classes and modules.
To disable certain classes of error message, go to the [MESSAGES] section of pylinrc, and add the error to "disable=" separated by commas.
Additionally, several very minor errors are being supressed to be fixed in a future cleanup branch.
Additionally, several very minor errors are being suppressed to be fixed in a future cleanup branch.

2 changes: 1 addition & 1 deletion devtools/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ known-third-party=enchant

# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
# only in one or another interpreter, leading to false positives when analyzed.
analyse-fallback-blocks=no


Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def DSHAPE_current(tmpdir_factory):
output_dir = tmpdir_factory.mktemp("result")
desc_h5_path = output_dir.join("DSHAPE_current_out.h5")
desc_nc_path = output_dir.join("DSHAPE_current_out.nc")
# TODO: change these paths too? (note that DSHAPE_current converges to DSHAPE)
vmec_nc_path = ".//tests//inputs//wout_DSHAPE.nc"
booz_nc_path = output_dir.join("DSHAPE_bx.nc")

Expand Down