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

Added referened and Optimize and Refactor Microgrid Test and Utility Code for Improved Clarity and Reusability #255

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

Conversation

Mattral
Copy link

@Mattral Mattral commented Jan 7, 2025

Description:
This PR introduces optimizations and refactoring across two files to improve code readability, reusability, and maintainability without changing existing functionality. The modifications are focused on enhancing clarity and aligning with best practices.

Summary of Changes:

  1. Microgrid Modular Setup Code:

    • Simplified parameter handling, including safe copying of default values and use of explicit defaults to prevent unintended side effects.
    • Converted default_params to uppercase DEFAULT_PARAMS to clearly indicate its status as a constant, following Python conventions.
    • Leveraged conditional expressions (or operator) to streamline default assignments, making code more concise.
  2. MPC Test Suite:

    • Implemented a setUp method to centralize shared constants (e.g., max_steps, pv_const, load_const) and reusable time series data, reducing repetition across tests.
    • Added a helper method create_microgrid to construct customized microgrid setups, improving test readability and reducing setup complexity.
    • Refactored assertions by calculating reusable values, making tests more concise and easier to understand.
    • Consolidated module imports within the class to enhance consistency and readability across test methods.

📚 Documentation preview 📚: https://pymgrid--255.org.readthedocs.build/en/255/

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.

1 participant