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

Papercut: enumify text based choices #3021

Conversation

athoynilimanew
Copy link
Contributor

@athoynilimanew athoynilimanew commented Feb 15, 2024

Linked Issues

Text based choices should be verified for spelling etc, enums will provide that functionality or possibly class attributes

Closes #{1044}

Description

Emunified a number of text based choices in several modules.

Interface Changes

Checklist

I confirm that I have completed the following checks:

  • Tests run locally and pass pytest tests --reactor
  • Code quality checks run locally and pass pre-commit run --from-ref develop --to-ref HEAD
  • Documentation built locally and checked sphinx-build -W documentation/source documentation/build

@athoynilimanew athoynilimanew requested review from a team as code owners February 15, 2024 15:27
@athoynilimanew
Copy link
Contributor Author

@oliverfunk Could you please review the papercut PR?

Copy link
Contributor

github-actions bot commented Feb 16, 2024

⚠️ Warning Report

Found 0 new warnings, 0 fixed warnings. 🎉

All warnings (15)

On runtest

  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/h5py/__init__.py:36: UserWarning: h5py is running against HDF5 1.14.3 when it was built against 1.14.2, this may cause problems
  • /home/runner/work/bluemira/bluemira/eudemo/eudemo/tf_coils/tf_coils.py:338: DeprecationWarning: Argument 'separatrix' is deprecated, argument 'ripple_wire' is used instead.
  • /home/runner/work/bluemira/bluemira/bluemira/base/reactor.py:677: DeprecationWarning: Using kwarg 'dim' is no longer supported. Simply pass in the dimensions you would like to show, e.g. show_cad('xz')
  • /home/runner/work/bluemira/bluemira/tests/builders/test_tf_coils.py:46: DeprecationWarning: RippleConstrainedLengthGOP API has changed, please specify how you want to constrain TF ripple by using one of the available RipplePointSelector classes. Defaulting to an EquispacedSelector with n_rip_points=3 for now.

On collect

  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_problems' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/pkg_resources/__init__.py:2846: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('mpl_toolkits'). Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.utilities.optimiser' is deprecated and will be removed in version 2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.utilities.opt_problems' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_constraint_funcs' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.geometry.optimisation._optimisation_old' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/pkg_resources/__init__.py:2846: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('sphinxcontrib'). Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_objectives' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_constraints' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.utilities.opt_tools' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Attention: 72 lines in your changes are missing coverage. Please review.

Comparison is base (9e89a23) 79.79% compared to head (773020b) 79.43%.
Report is 2 commits behind head on develop.

Files Patch % Lines
bluemira/fuel_cycle/analysis.py 0.00% 20 Missing ⚠️
bluemira/fuel_cycle/lifecycle.py 0.00% 13 Missing ⚠️
bluemira/equilibria/equilibrium.py 44.44% 10 Missing ⚠️
bluemira/fuel_cycle/tools.py 46.15% 7 Missing ⚠️
bluemira/equilibria/plotting.py 14.28% 6 Missing ⚠️
bluemira/equilibria/positioner.py 80.00% 5 Missing ⚠️
bluemira/structural/model.py 82.35% 3 Missing ⚠️
bluemira/builders/pf_coil.py 83.33% 2 Missing ⚠️
bluemira/geometry/tools.py 88.23% 2 Missing ⚠️
bluemira/structural/element.py 85.71% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3021      +/-   ##
===========================================
- Coverage    79.79%   79.43%   -0.37%     
===========================================
  Files          226      226              
  Lines        25120    25273     +153     
===========================================
+ Hits         20045    20076      +31     
- Misses        5075     5197     +122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

bluemira/builders/pf_coil.py Outdated Show resolved Hide resolved
bluemira/builders/pf_coil.py Outdated Show resolved Hide resolved
bluemira/builders/pf_coil.py Outdated Show resolved Hide resolved
athoynilimanew and others added 2 commits February 19, 2024 14:42
Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com>
bluemira/equilibria/equilibrium.py Outdated Show resolved Hide resolved
bluemira/equilibria/equilibrium.py Outdated Show resolved Hide resolved
bluemira/equilibria/plotting.py Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Feb 20, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@oliverfunk oliverfunk merged commit 519f50f into Fusion-Power-Plant-Framework:develop Feb 20, 2024
3 of 4 checks passed
OceanNuclear pushed a commit that referenced this pull request Feb 20, 2024
* ✅ Enumification of text based choices in bluemira.fuel_cycle

* ✅ enumified text choices in bluemira.geometry

* fied pf_coil.py

* ✅ enumify text based choices in bluemira.equilibria

* ✅ enumify text based choices in bluemira.structural

* ✅ enumify some text based choics in eudemo.eudemo

* 🐛 fix circular import

* 🐛 Fix Failing test_coordinates.py

* 🐛 Fix failing test_tools.py

* 🐛 fix failing test_pyclipper_offset.py

* 🐛 remove plane=None test from test_KeyError_if_invalid_plane

* 🚨 Fix test function name

* Update bluemira/builders/pf_coil.py

Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com>

* ✅ Modify codes to resolve reviewer's comments

* ✅ remove unnecessary .upper(), and a few name changes

* 🐛 fix failing test_model.py

* 🐛 further cleanup

* 🐛 fix circular import error and duplication of CoilType

* updated docstrings

---------

Co-authored-by: Athoy Nilima <athoy.nilima@ukaea.uk>
Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com>
Co-authored-by: Oliver Funk <oli.funk@gmail.com>
@je-cook je-cook mentioned this pull request Feb 27, 2024
3 tasks
Copy link
Contributor

@je-cook je-cook left a comment

Choose a reason for hiding this comment

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

There are quite a few problems here.

Add them to #3036 for the fixes also all of the docstrings that start with 'Enumeration of ....' should be changed

bluemira/builders/pf_coil.py Show resolved Hide resolved
except KeyError:
raise ValueError(
"Please select a numerical stabilisation strategy"
' from: 1) "virtual" \n 2) "feedback" 3) None.'
Copy link
Contributor

@je-cook je-cook Feb 27, 2024

Choose a reason for hiding this comment

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

please autofill the options with the cls._member_names_ attribute eg

f"{*cls._member_names_,}"

also the error message sounds like the user can input something (which they can't). Maybe something like:
f"{cls.__name__} has no strategy {value} please select from {*cls._member_names_,}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in PR #3036, commit 3c9ff6d.

FEEDBACK = auto()

@classmethod
def _missing_(cls, value):
Copy link
Contributor

Choose a reason for hiding this comment

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

typing of value is missing def _missing_(cls, value: str):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in PR #3036, commit 3c9ff6d.

self.controller = VirtualController(self, gz=2.2)
elif vcontrol_type is VerticalPositionControlType.FEEDBACK:
raise NotImplementedError
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

this error message will never be hit as it will error on L1073 on the initialisation of the enum, please remove the else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in PR #3036, commit 3c9ff6d. removed else, put two ifs (instead of if-elif without else)

try:
return cls[value.upper()]
except KeyError:
raise ValueError(f"{value} is a wrong ReactorType. Choose from: ST or Normal") from None
Copy link
Contributor

Choose a reason for hiding this comment

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

same as previous enum comments, no typing on value and error message:
f"{cls.__name__} has no entry {value} please select from {*cls._member_names_,}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in #3036, commit b4e1ad1

return cls[value.upper()]
except KeyError:
raise StructuralError(
f"Unknown SubLoad type {value}. Choose from: force, moment or all"
Copy link
Contributor

Choose a reason for hiding this comment

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

typing and error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in PR #3036, commit ff3bd82

from bluemira.structural.error import StructuralError
from bluemira.structural.geometry import Geometry
from bluemira.structural.loads import LoadCase
from bluemira.structural.result import Result
from bluemira.structural.symmetry import CyclicSymmetry


class BoundaryConditionMethodType(Enum):
Copy link
Contributor

Choose a reason for hiding this comment

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

rename BoundaryConditionMethod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed in PR: #3036 , commit 4407c3c

@@ -524,8 +547,8 @@ def _apply_boundary_conditions(
k = np.delete(k, i, axis=0)
k = np.delete(k, i, axis=1)
p = np.delete(p, i)
else:
raise StructuralError(f"Unrecognised method: {method}.")
# else:
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed in PR #3036, commit faf0f07

blanket_pump_strat = H2OPumping(
0.005,
eta_isentropic=params.bb_pump_eta_isen.value,
eta_electric=params.bb_pump_eta_el.value,
)
bop_cycle = PredeterminedEfficiency(0.33)
else:
raise ValueError(f"Unrecognised blanket type {params.blanket_type.value}")
# else:
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed in PR #3036, commit 0678f70

@@ -456,12 +456,13 @@ def test_hull_around_two_circles_xy_plane(self):
bounding_box = hull.bounding_box
assert bounding_box.z_min == bounding_box.z_max == 0

@pytest.mark.parametrize("bad_plane", ["ab", "", None, ["x", "y"]])
@pytest.mark.parametrize("bad_plane", ["ab", "", ["x", "y"]])
Copy link
Contributor

Choose a reason for hiding this comment

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

this test case shouldnt be removed

Copy link
Contributor Author

@athoynilimanew athoynilimanew Feb 28, 2024

Choose a reason for hiding this comment

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

refined the test cases in PR #3036, commit 0a4af30. Made two tests, one for ValueError (for "ab", "") and other for TypeError (for None, ["x", "y"]). Because of the Enumification, .upper() on wrong type is not possible so a TypeError is raised instead. See tools.py

@je-cook je-cook added the quality Tasks relating to quality issues or improvements label Mar 4, 2024
OceanNuclear pushed a commit that referenced this pull request Jun 17, 2024
* ✅ Enumification of text based choices in bluemira.fuel_cycle

* ✅ enumified text choices in bluemira.geometry

* fied pf_coil.py

* ✅ enumify text based choices in bluemira.equilibria

* ✅ enumify text based choices in bluemira.structural

* ✅ enumify some text based choics in eudemo.eudemo

* 🐛 fix circular import

* 🐛 Fix Failing test_coordinates.py

* 🐛 Fix failing test_tools.py

* 🐛 fix failing test_pyclipper_offset.py

* 🐛 remove plane=None test from test_KeyError_if_invalid_plane

* 🚨 Fix test function name

* Update bluemira/builders/pf_coil.py

Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com>

* ✅ Modify codes to resolve reviewer's comments

* ✅ remove unnecessary .upper(), and a few name changes

* 🐛 fix failing test_model.py

* 🐛 further cleanup

* 🐛 fix circular import error and duplication of CoilType

* updated docstrings

---------

Co-authored-by: Athoy Nilima <athoy.nilima@ukaea.uk>
Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com>
Co-authored-by: Oliver Funk <oli.funk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quality Tasks relating to quality issues or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants