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

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jan 21, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from joamatab January 21, 2023 19:21
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -112 to +123
name="sim_{}".format(stage),
name=f"sim_{stage}",
wavelength=1550,
eps=eps,
solver_info=solver_info,
sources=[
maxwell.WaveguideModeSource(center=[-1400, 0, 0],
extents=[0, 2500, 1000],
normal=[1, 0, 0],
mode_num=0,
power=1)
maxwell.WaveguideModeSource(
center=[-1400, 0, 0],
extents=[0, 2500, 1000],
normal=[1, 0, 0],
mode_num=0,
power=1,
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_objective refactored with the following changes:

name="sim_{}".format(stage),
name=f"sim_{stage}",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_objective refactored with the following changes:

Comment on lines -276 to +284
plt.imshow(
np.abs(data["monitor_data"]["sim_{}.eps".format(stage)][1].squeeze()))
plt.imshow(np.abs(data["monitor_data"][f"sim_{stage}.eps"][1].squeeze()))
plt.colorbar()
plt.subplot(1, 2, 2)
plt.imshow(
np.abs(data["monitor_data"]["sim_{}.field".format(stage)][1].squeeze()))
plt.imshow(np.abs(data["monitor_data"][f"sim_{stage}.field"][1].squeeze()))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function visualize refactored with the following changes:

print("x: {}, y: {}, obj: {}".format(x_val.array, y_val.array,
obj_val.array))
print(f"x: {x_val.array}, y: {y_val.array}, obj: {obj_val.array}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

print("x: {}, y: {}, obj: {}".format(x_val.array, y_val.array,
obj_val.array))
print(f"x: {x_val.array}, y: {y_val.array}, obj: {obj_val.array}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

Comment on lines -102 to -108
fields = {
return {
'wavenumber': wavenumber,
'E': unvec(e, shape),
'H': unvec(h, shape),
}

return fields
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function solve_waveguide_mode_2d refactored with the following changes:

Comment on lines -352 to -358
results = {
return {
'wavenumber': fields_2d['wavenumber'],
'H': H,
'E': E,
}

return results
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function solve_waveguide_mode refactored with the following changes:

Comment on lines -395 to +391
exp_iphi = np.exp(
1j * polarity * wavenumber * dxes[1][int(axis)][slices[int(axis)]])
exp_iphi = np.exp(1j * polarity * wavenumber * dxes[1][axis][slices[axis]])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function compute_source refactored with the following changes:

Comment on lines -442 to +445
if polarity == 1:
Mslice = copy.deepcopy(slices)
Jslice = copy.deepcopy(slices)
Jslice[axis] = slice(Jslice[axis].start + 1, Jslice[axis].stop + 1)
elif polarity == -1:
if polarity == -1:
Mslice = copy.deepcopy(slices)
Mslice[axis] = slice(Mslice[axis].start - 1, Mslice[axis].stop - 1)
Jslice = copy.deepcopy(slices)

elif polarity == 1:
Mslice = copy.deepcopy(slices)
Jslice = copy.deepcopy(slices)
Jslice[axis] = slice(Jslice[axis].start + 1, Jslice[axis].stop + 1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function compute_source_angle refactored with the following changes:

  • Simplify conditional into switch-like form (switch)

Comment on lines -533 to +528
dn[0:npts] = 1
dn[:npts] = 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function compute_overlap_e refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jan 21, 2023

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.10%.

Quality metrics Before After Change
Complexity 7.09 ⭐ 6.86 ⭐ -0.23 👍
Method Length 92.00 🙂 91.42 🙂 -0.58 👍
Working memory 8.73 🙂 8.77 🙂 0.04 👎
Quality 59.53% 🙂 59.63% 🙂 0.10% 👍
Other metrics Before After Change
Lines 26242 25917 -325
Changed files Quality Before Quality After Quality Change
examples/goos/bend90/bend90.py 59.53% 🙂 59.55% 🙂 0.02% 👍
examples/goos/grating_1d/grating_1d.py 64.77% 🙂 64.77% 🙂 0.00%
examples/goos/optplan_examples/simple_opt.py 75.57% ⭐ 73.69% 🙂 -1.88% 👎
examples/goos/optplan_examples/simple_opt_reloaded.py 82.78% ⭐ 81.20% ⭐ -1.58% 👎
examples/invdes/grating_coupler/grating.py 53.59% 🙂 53.96% 🙂 0.37% 👍
examples/invdes/wdm2/wdm2.py 60.96% 🙂 62.36% 🙂 1.40% 👍
spins/fdfd_solvers/local_matrix_solvers.py 68.94% 🙂 70.95% 🙂 2.01% 👍
spins/fdfd_solvers/maxwell.py 15.60% ⛔ 15.58% ⛔ -0.02% 👎
spins/fdfd_solvers/waveguide_mode.py 37.24% 😞 37.30% 😞 0.06% 👍
spins/fdfd_tools/free_space_sources.py 34.62% 😞 34.54% 😞 -0.08% 👎
spins/fdfd_tools/functional.py 76.22% ⭐ 77.58% ⭐ 1.36% 👍
spins/fdfd_tools/grid.py 54.54% 🙂 54.98% 🙂 0.44% 👍
spins/fdfd_tools/operators.py 56.17% 🙂 56.43% 🙂 0.26% 👍
spins/fdfd_tools/solvers.py 64.33% 🙂 66.04% 🙂 1.71% 👍
spins/fdfd_tools/test_grid.py 73.63% 🙂 73.83% 🙂 0.20% 👍
spins/fdfd_tools/waveguide.py 66.36% 🙂 66.23% 🙂 -0.13% 👎
spins/fdfd_tools/waveguide_mode.py 43.45% 😞 43.81% 😞 0.36% 👍
spins/gds/gen_gds.py 15.82% ⛔ 18.88% ⛔ 3.06% 👍
spins/gds/parse_gds.py 70.35% 🙂 71.13% 🙂 0.78% 👍
spins/goos/array.py 84.11% ⭐ 84.07% ⭐ -0.04% 👎
spins/goos/compat.py 51.70% 🙂 51.72% 🙂 0.02% 👍
spins/goos/flows.py 56.25% 🙂 57.05% 🙂 0.80% 👍
spins/goos/generic.py 83.34% ⭐ 83.91% ⭐ 0.57% 👍
spins/goos/graph_executor.py 28.77% 😞 29.09% 😞 0.32% 👍
spins/goos/grating.py 44.06% 😞 44.02% 😞 -0.04% 👎
spins/goos/material.py 95.15% ⭐ 94.53% ⭐ -0.62% 👎
spins/goos/math.py 78.09% ⭐ 80.52% ⭐ 2.43% 👍
spins/goos/schema_registry.py 92.90% ⭐ 92.62% ⭐ -0.28% 👎
spins/goos/shapes.py 81.64% ⭐ 82.51% ⭐ 0.87% 👍
spins/goos/test_graph_executor.py 81.20% ⭐ 82.05% ⭐ 0.85% 👍
spins/goos/util.py 70.02% 🙂 70.02% 🙂 0.00%
spins/goos/optplan/context.py 93.38% ⭐ 93.24% ⭐ -0.14% 👎
spins/goos/optplan/optplan.py 66.74% 🙂 67.27% 🙂 0.53% 👍
spins/goos/optplan/schema.py 60.54% 🙂 60.77% 🙂 0.23% 👍
spins/goos/optplan/schema_optplan.py 75.32% ⭐ 74.43% 🙂 -0.89% 👎
spins/goos/optplan/schema_types.py 80.10% ⭐ 82.73% ⭐ 2.63% 👍
spins/goos/optplan/schema_utils.py 80.12% ⭐ 81.00% ⭐ 0.88% 👍
spins/goos_sim/maxwell/render.py 69.43% 🙂 68.72% 🙂 -0.71% 👎
spins/goos_sim/maxwell/simspace.py 60.80% 🙂 61.80% 🙂 1.00% 👍
spins/goos_sim/maxwell/simulate.py 71.93% 🙂 72.27% 🙂 0.34% 👍
spins/gridlock/direction.py 84.15% ⭐ 87.51% ⭐ 3.36% 👍
spins/gridlock/float_raster.py 48.17% 😞 48.15% 😞 -0.02% 👎
spins/gridlock/grid.py 43.98% 😞 44.64% 😞 0.66% 👍
spins/gridlock/selection_matrix.py 53.54% 🙂 53.78% 🙂 0.24% 👍
spins/invdes/optimization/gradient_descent.py 76.02% ⭐ 76.17% ⭐ 0.15% 👍
spins/invdes/optimization/problems.py 78.59% ⭐ 78.15% ⭐ -0.44% 👎
spins/invdes/optimization/scipy_optimizer.py 42.29% 😞 42.03% 😞 -0.26% 👎
spins/invdes/optimization/test_constrained_optimizer.py 63.58% 🙂 63.28% 🙂 -0.30% 👎
spins/invdes/parametrization/cubic_utils.py 36.70% 😞 36.72% 😞 0.02% 👍
spins/invdes/parametrization/grating_parametrization.py 72.26% 🙂 72.06% 🙂 -0.20% 👎
spins/invdes/parametrization/parametrization.py 72.47% 🙂 72.33% 🙂 -0.14% 👎
spins/invdes/parametrization/test_parametrization.py 60.68% 🙂 60.68% 🙂 0.00%
spins/invdes/problem/emobjective.py 73.37% 🙂 73.36% 🙂 -0.01% 👎
spins/invdes/problem/farfield.py 44.68% 😞 44.73% 😞 0.05% 👍
spins/invdes/problem/ffobjective.py 64.80% 🙂 63.80% 🙂 -1.00% 👎
spins/invdes/problem/graph_executor.py 35.39% 😞 35.92% 😞 0.53% 👍
spins/invdes/problem/grating.py 82.17% ⭐ 83.17% ⭐ 1.00% 👍
spins/invdes/problem/objective.py 86.91% ⭐ 87.01% ⭐ 0.10% 👍
spins/invdes/problem/selection_matrix.py 48.32% 😞 49.20% 😞 0.88% 👍
spins/invdes/problem/simulation.py 60.96% 🙂 61.94% 🙂 0.98% 👍
spins/invdes/problem/slack_optimization_problem.py 89.39% ⭐ 90.43% ⭐ 1.04% 👍
spins/invdes/problem/structure_objectives.py 79.57% ⭐ 81.71% ⭐ 2.14% 👍
spins/invdes/problem/test_emobjective.py 63.61% 🙂 63.61% 🙂 0.00%
spins/invdes/problem/test_graph_executor.py 84.92% ⭐ 85.02% ⭐ 0.10% 👍
spins/invdes/problem/test_objective.py 67.12% 🙂 66.91% 🙂 -0.21% 👎
spins/invdes/problem_graph/creator_em.py 65.79% 🙂 65.90% 🙂 0.11% 👍
spins/invdes/problem_graph/creator_param.py 64.85% 🙂 65.02% 🙂 0.17% 👍
spins/invdes/problem_graph/grating.py 38.34% 😞 37.70% 😞 -0.64% 👎
spins/invdes/problem_graph/schema_utils.py 80.12% ⭐ 81.00% ⭐ 0.88% 👍
spins/invdes/problem_graph/simspace.py 55.53% 🙂 54.81% 🙂 -0.72% 👎
spins/invdes/problem_graph/solver.py 54.28% 🙂 54.36% 🙂 0.08% 👍
spins/invdes/problem_graph/test_optplan.py 75.38% ⭐ 75.38% ⭐ 0.00%
spins/invdes/problem_graph/workspace.py 71.18% 🙂 71.25% 🙂 0.07% 👍
spins/invdes/problem_graph/functions/poynting.py 72.32% 🙂 72.32% 🙂 0.00%
spins/invdes/problem_graph/log_tools/loader.py 66.49% 🙂 66.03% 🙂 -0.46% 👎
spins/invdes/problem_graph/log_tools/monitor_spec.py 75.97% ⭐ 76.07% ⭐ 0.10% 👍
spins/invdes/problem_graph/log_tools/plotter.py 41.47% 😞 42.05% 😞 0.58% 👍
spins/invdes/problem_graph/optplan/context.py 89.65% ⭐ 88.65% ⭐ -1.00% 👎
spins/invdes/problem_graph/optplan/io.py 65.26% 🙂 66.53% 🙂 1.27% 👍
spins/invdes/problem_graph/optplan/optplan.py 80.85% ⭐ 79.29% ⭐ -1.56% 👎
spins/invdes/problem_graph/optplan/schema_function.py 81.15% ⭐ 81.15% ⭐ 0.00%
spins/invdes/problem_graph/optplan/test_context.py 88.48% ⭐ 88.48% ⭐ 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
spins/goos/grating.py _get_general_edge_loc_dp 70 ⛔ 735 ⛔ 26 ⛔ 2.67% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
spins/fdfd_solvers/maxwell.py MaxwellSolver.solve 57 ⛔ 2271 ⛔ 3.17% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
spins/goos/graph_executor.py eval_grad 41 ⛔ 459 ⛔ 8.98% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
spins/gridlock/grid.py Grid.__init__ 36 ⛔ 446 ⛔ 16 ⛔ 15.14% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
spins/invdes/problem/graph_executor.py eval_grad 31 😞 359 ⛔ 16.43% ⛔ Refactor to reduce nesting. Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants