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

Test microstructure and -tiles #457

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft

Test microstructure and -tiles #457

wants to merge 23 commits into from

Conversation

markriegler
Copy link
Collaborator

@markriegler markriegler commented Aug 29, 2024

Overview

Addressing issue #392: this should add tests related to all microstructure- and microtiles-related code.

Addressing issue #458: some changes to the code of the microtiles and possibly the microstructure are needed in order to satisfy the tests.

Checklist of what to test

  • Derivatives of the tiles (incl. tiles with closure)
  • Bound checks of tiles (incl. tiles with closure)
  • ...

Summary by CodeRabbit

  • New Features

    • Introduced support for sensitivity analysis across multiple tile classes.
    • Added new attributes for parameter bounds and shapes in several classes to enhance configurability.
    • Corrected parameter naming for improved clarity and consistency.
  • Bug Fixes

    • Fixed spelling errors in parameter names and documentation strings.
    • Enhanced error messages for better user guidance.
  • Tests

    • Implemented a comprehensive suite of unit tests for validating tile class functionalities and behaviors.

@markriegler markriegler added the testing All about software testing label Aug 29, 2024
@markriegler markriegler self-assigned this Aug 29, 2024
@markriegler markriegler linked an issue Aug 29, 2024 that may be closed by this pull request
3 tasks
Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes encompass a series of updates across multiple files in the splinepy library, focusing on correcting parameter names, enhancing documentation, and introducing new class attributes for improved functionality. Key modifications include the addition of sensitivity analysis capabilities, refined parameter validation, and the implementation of unit tests to ensure the integrity of various tile classes. Overall, the updates aim to enhance code clarity, maintainability, and robustness.

Changes

Files Change Summary
examples/show_microstructures.py Corrected parameter name from "seperator_distance" to "separator_distance" in function calls.
splinepy/microstructure/microstructure.py Fixed spelling error in docstrings from "facilitatae" to "facilitate".
splinepy/microstructure/tiles/__init__.py Added cross_3d module to import statements and exported module list.
splinepy/microstructure/tiles/chi.py Changed _evaluation_points from a 2D array to a 1D array; added _sensitivities_implemented and _parameter_bounds attributes; updated create_tile method for parameter validation.
splinepy/microstructure/tiles/cross_2d.py Introduced new attributes for configuration and error handling; improved error messaging in create_tile.
splinepy/microstructure/tiles/cross_3d.py Added new attributes for parameter management and validation; enhanced error handling in create_tile.
splinepy/microstructure/tiles/cross_3d_linear.py Added attributes for sensitivity analysis and parameter handling.
splinepy/microstructure/tiles/cube_void.py Introduced attributes for sensitivity analysis and parameter shape; modified create_tile logic to use _parameters_shape.
splinepy/microstructure/tiles/double_lattice.py Added attributes for sensitivity analysis and parameter bounds; corrected docstring in create_tile.
splinepy/microstructure/tiles/ellips_v_oid.py Introduced attributes for sensitivity analysis and parameter bounds; defined expected parameter shape.
splinepy/microstructure/tiles/hollow_cube.py Added attributes for sensitivity analysis; streamlined parameter validation logic in create_tile.
splinepy/microstructure/tiles/hollow_octagon.py Enhanced sensitivity analysis handling; broadened v_h_void parameter validation range.
splinepy/microstructure/tiles/hollow_octagon_extrude.py Improved handling of parameter_sensitivities and validation logic; renamed _closing_tile method.
splinepy/microstructure/tiles/inverse_cross_3d.py Corrected "seperator_distance" to "separator_distance"; refined logic for handling separator distance and parameter sensitivities.
splinepy/microstructure/tiles/snappy.py Added attributes for sensitivity analysis; adjusted control flow in _closing_tile and create_tile.
tests/test_microstructure.py Implemented unit tests for various tile classes, focusing on control point validation, parameter handling, closure functionality, and derivative correctness.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TileClass
    participant ParameterManager

    User->>TileClass: create_tile(parameters)
    TileClass->>ParameterManager: validate_parameters(parameters)
    ParameterManager-->>TileClass: parameters_validated
    TileClass->>User: return created_tile
Loading

🐇 In the code, I hop and play,
New names and bounds brighten the day!
With tests that check each little part,
The changes make my code a work of art!
So let’s dance and twirl with glee,
For better code is a joy to see! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 148f29e and d46121b.

Files selected for processing (16)
  • examples/show_microstructures.py (2 hunks)
  • splinepy/microstructure/microstructure.py (2 hunks)
  • splinepy/microstructure/tiles/init.py (2 hunks)
  • splinepy/microstructure/tiles/chi.py (2 hunks)
  • splinepy/microstructure/tiles/cross_2d.py (2 hunks)
  • splinepy/microstructure/tiles/cross_3d.py (2 hunks)
  • splinepy/microstructure/tiles/cross_3d_linear.py (1 hunks)
  • splinepy/microstructure/tiles/cube_void.py (2 hunks)
  • splinepy/microstructure/tiles/double_lattice.py (2 hunks)
  • splinepy/microstructure/tiles/ellips_v_oid.py (1 hunks)
  • splinepy/microstructure/tiles/hollow_cube.py (2 hunks)
  • splinepy/microstructure/tiles/hollow_octagon.py (4 hunks)
  • splinepy/microstructure/tiles/hollow_octagon_extrude.py (2 hunks)
  • splinepy/microstructure/tiles/inverse_cross_3d.py (33 hunks)
  • splinepy/microstructure/tiles/snappy.py (5 hunks)
  • tests/test_microstructure.py (1 hunks)
Additional comments not posted (79)
splinepy/microstructure/tiles/__init__.py (2)

11-11: LGTM!

The addition of cross_3d to the import statements is correct and consistent with the other imports.


46-46: LGTM!

The addition of cross_3d to the exported module list is correct and consistent with the other exports.

splinepy/microstructure/tiles/chi.py (7)

19-19: LGTM!

The change in _evaluation_points from _np.array([[0.5, 0.5]]) to _np.array([[0.5]]) is correct and consistent with the rest of the class.


21-21: LGTM!

The addition of _sensitivities_implemented as True is correct and indicates that sensitivity analysis features are now supported within this class.


22-22: LGTM!

The addition of _parameter_bounds as [[ -_np.pi / 2, _np.pi / 2 ]] is correct and provides explicit limits for the parameters.


23-23: LGTM!

The addition of _parameters_shape as (1, 1) is correct and aids in maintaining consistency in parameter handling throughout the class.


54-63: LGTM!

The modification of the create_tile method to incorporate angle_bounds from _parameter_bounds enhances maintainability and clarity by centralizing the bounds in a single attribute.


59-63: LGTM!

The improved error message in the create_tile method dynamically incorporates the actual bounds from angle_bounds, providing more informative feedback to the user.


54-63: LGTM!

The overall changes in the create_tile method reflect a shift towards a more structured and maintainable approach to parameter management and validation.

splinepy/microstructure/tiles/cube_void.py (5)

28-28: LGTM!

The addition of _sensitivities_implemented as True is correct and indicates that sensitivity analysis features are now supported within this class.


31-36: LGTM!

The addition of _parameter_bounds as [[0.0, 1.0], [0.0, 1.0], [-_np.pi / 2, _np.pi / 2], [-_np.pi / 2, _np.pi / 2]] is correct and provides explicit limits for the parameters.


37-37: LGTM!

The addition of _parameters_shape as (1, 4) is correct and aids in maintaining consistency in parameter handling throughout the class.


104-106: LGTM!

The modification of the create_tile method to incorporate _parameters_shape for default initialization of parameters enhances flexibility and maintainability by utilizing _parameters_shape instead of hardcoding the shape directly.


104-106: LGTM!

The overall changes in the create_tile method reflect a shift towards a more robust and flexible design, facilitating better parameter management.

examples/show_microstructures.py (3)

349-349: LGTM!

The parameter name "seperator_distance" has been corrected to "separator_distance". This change improves clarity and consistency in the codebase.


355-355: LGTM!

The parameter name "seperator_distance" has been corrected to "separator_distance". This change improves clarity and consistency in the codebase.


368-368: LGTM!

The parameter name "seperator_distance" has been corrected to "separator_distance". This change improves clarity and consistency in the codebase.

splinepy/microstructure/tiles/double_lattice.py (4)

23-23: LGTM!

The attribute _sensitivities_implemented has been added to the DoubleLattice class. This indicates that sensitivity analysis features are now supported within the class.


24-24: LGTM!

The attribute _parameter_bounds has been added to the DoubleLattice class. This specifies the bounds for parameters used in the double lattice calculations.


25-25: LGTM!

The attribute _parameters_shape has been added to the DoubleLattice class. This defines the expected shape of the parameters used in the class.


50-50: LGTM!

The docstring of the create_tile method has been modified for clarity. This improves the clarity and grammatical accuracy of the documentation.

tests/test_microstructure.py (7)

1-10: LGTM!

The imports and constants are necessary for the tests.


19-26: LGTM!

The function check_control_points correctly checks if all control points lie within the unit square/cube.


29-46: LGTM!

The function make_bounds_feasible correctly converts bounds to an open set.


49-97: LGTM!

The function test_tile_class correctly checks if all tile classes have the appropriate members and functions.


99-129: LGTM!

The function test_tile_bounds correctly tests if the tile is still in the unit cube at the bounds.


132-177: LGTM!

The function test_tile_closure correctly checks if closing tiles also lie in the unit cube.


179-281: LGTM!

The function test_tile_derivatives correctly tests the correctness of the tile derivatives using Finite Differences.

splinepy/microstructure/tiles/hollow_cube.py (4)

31-31: LGTM!

The _sensitivities_implemented attribute is correctly added to indicate that sensitivity analysis is supported.


32-32: LGTM!

The _parameter_bounds attribute is correctly added to define the valid range for parameters.


33-33: LGTM!

The _parameters_shape attribute is correctly added to specify the expected shape of the parameters.


71-72: LGTM!

The parameter validation logic has been correctly streamlined to use a single condition with NumPy's array operations.

splinepy/microstructure/tiles/ellips_v_oid.py (3)

30-30: LGTM!

The _sensitivities_implemented attribute is correctly added to indicate that sensitivity analysis is supported.


34-39: LGTM!

The _parameter_bounds attribute is correctly added to define the valid range for parameters.


40-40: LGTM!

The _parameters_shape attribute is correctly added to specify the expected shape of the parameters.

splinepy/microstructure/tiles/snappy.py (6)

23-23: LGTM!

The _sensitivities_implemented attribute is correctly added to indicate that sensitivity analysis is supported.


24-24: LGTM!

The _closure_directions attribute is correctly added to define the closure directions.


25-25: LGTM!

The _parameter_bounds attribute is correctly added to define the valid range for parameters.


26-26: LGTM!

The _parameters_shape attribute is correctly added to specify the expected shape of the parameters.


68-70: LGTM!

The logic has been correctly adjusted to conditionally check parameters only if they are not None.


371-371: Fix the typo in the error message.

The error message for unimplemented parameterization has been corrected from "Parametriazation" to "Parametrization."

Apply this diff to fix the typo in the error message:

-                "Parametriazation is not implemented for this tile yet"
+                "Parametrization is not implemented for this tile yet"

Likely invalid or redundant comment.

splinepy/microstructure/tiles/cross_2d.py (5)

29-29: LGTM!

The addition of _sensitivities_implemented attribute is clear and indicates that sensitivity analysis features are now supported.


30-30: LGTM!

The addition of _closure_directions attribute enhances the configurability of the tile's behavior in a two-dimensional space.


31-33: LGTM!

The addition of _parameter_bounds attribute ensures that the parameters are constrained to a specific range, improving robustness.


34-34: LGTM!

The addition of _parameters_shape attribute facilitates validation and error checking.


427-428: LGTM!

The updated error message provides clearer guidance on the acceptable range for the center_expansion parameter.

splinepy/microstructure/tiles/hollow_octagon_extrude.py (11)

21-21: LGTM!

The addition of _sensitivities_implemented attribute is clear and indicates that sensitivity analysis features are now supported.


23-23: LGTM!

The addition of _closure_directions attribute enhances the configurability of the tile's behavior in a three-dimensional space.


24-24: LGTM!

The addition of _parameter_bounds attribute ensures that the parameters are constrained to a specific range, improving robustness.


25-25: LGTM!

The addition of _parameters_shape attribute facilitates validation and error checking.


74-78: LGTM!

The handling of parameter_sensitivities in create_tile method now allows the method to process sensitivity information, enhancing its flexibility and usability.


84-87: LGTM!

The validation for the v_h_void parameter has been modified to allow a lower bound of 0.0 instead of 0.01, broadening the acceptable range for this parameter.


89-245: LGTM!

The logic for generating spline control points in create_tile method now constructs control points for splines in a loop that iterates over the number of derivatives, allowing for the creation of derivative-specific splines.


247-247: LGTM!

The return statement of create_tile method now returns both the primary splines and the derivatives, providing a more comprehensive output.


249-249: LGTM!

The renaming of closing_tile method to _closing_tile clarifies the intended usage context of the method.


76-80: LGTM!

The handling of parameter_sensitivities in _closing_tile method now allows the method to process sensitivity information, enhancing its flexibility and usability.


83-87: LGTM!

The validation for the v_h_void parameter has been modified to allow a lower bound of 0.0 instead of 0.01, broadening the acceptable range for this parameter.

splinepy/microstructure/tiles/hollow_octagon.py (8)

21-21: LGTM!

The addition of _sensitivities_implemented attribute is clear and indicates that sensitivity analysis features are now supported.


22-22: LGTM!

The addition of _closure_directions attribute enhances the configurability of the tile's behavior in a two-dimensional space.


23-23: LGTM!

The addition of _parameter_bounds attribute ensures that the parameters are constrained to a specific range, improving robustness.


24-24: LGTM!

The addition of _parameters_shape attribute facilitates validation and error checking.


76-80: LGTM!

The handling of parameter_sensitivities in _closing_tile method now allows the method to process sensitivity information, enhancing its flexibility and usability.


83-87: LGTM!

The validation for the v_h_void parameter has been modified to allow a lower bound of 0.0 instead of 0.01, broadening the acceptable range for this parameter.


89-418: LGTM!

The logic for generating spline control points in _closing_tile method now constructs control points for splines in a loop that iterates over the number of derivatives, allowing for the creation of derivative-specific splines.


420-420: LGTM!

The return statement of _closing_tile method now returns both the primary splines and the derivatives, providing a more comprehensive output.

splinepy/microstructure/tiles/cross_3d_linear.py (4)

31-31: LGTM!

The addition of _sensitivities_implemented attribute is clear and indicates that the class supports sensitivity analysis.


32-32: LGTM!

The addition of _closure_directions attribute enhances the configurability of the class by defining valid closure directions.


33-35: LGTM!

The addition of _parameter_bounds attribute ensures that the parameters used in the class are within the specified bounds, enhancing robustness.


36-36: LGTM!

The addition of _parameters_shape attribute ensures that the parameters used in the class have the correct shape, enhancing robustness.

splinepy/microstructure/tiles/cross_3d.py (5)

31-31: LGTM!

The addition of _sensitivities_implemented attribute is clear and indicates that the class supports sensitivity analysis.


32-32: LGTM!

The addition of _closure_directions attribute enhances the configurability of the class by defining valid closure directions.


33-35: LGTM!

The addition of _parameter_bounds attribute ensures that the parameters used in the class are within the specified bounds, enhancing robustness.


36-36: LGTM!

The addition of _parameters_shape attribute ensures that the parameters used in the class have the correct shape, enhancing robustness.


566-569: LGTM!

The addition of closure validation in the create_tile method enhances error handling by ensuring that only supported closure types are processed.

splinepy/microstructure/microstructure.py (2)

12-12: LGTM!

The correction of the class-level docstring enhances the clarity and professionalism of the documentation.


21-21: LGTM!

The correction of the constructor's docstring enhances the clarity and professionalism of the documentation.

splinepy/microstructure/tiles/inverse_cross_3d.py (3)

35-39: LGTM!

The class attributes are correctly defined and initialized.


893-893: LGTM! But verify the function usage in the codebase.

The function is correctly implemented. However, ensure that all function calls to create_tile match the new signature.

The code changes are approved.

Run the following script to verify the function usage:


48-48: LGTM! But verify the function usage in the codebase.

The function is correctly implemented. However, ensure that all function calls to _closing_tile match the new signature.

The code changes are approved.

Run the following script to verify the function usage:

Verification successful

Function usage is consistent with the updated signature.

The _closing_tile function in splinepy/microstructure/tiles/inverse_cross_3d.py is correctly defined and used with the separator_distance parameter. No issues were found regarding its usage in this context.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `_closing_tile` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 $'_closing_tile'

Length of output: 68


Script:

#!/bin/bash
# Description: Verify all function calls to `_closing_tile` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg '_closing_tile' --glob '*.py' -A 5

Length of output: 9016

@markriegler markriegler linked an issue Aug 29, 2024 that may be closed by this pull request
4 tasks
@markriegler markriegler marked this pull request as draft August 29, 2024 09:22
@markriegler
Copy link
Collaborator Author

markriegler commented Aug 29, 2024

The current status is:

  • Added test to check if tile classes have the correct variables and functions
  • Added new variables (e.g. if sensitivities are implemented for this class)
  • Added bound test: check if all control points of tile (with and without closure) lie in unit square/cube
    • Right now, two classes are skipped for testing:
      • EllipsVoid (because the control points easily lie outside of unit cube, but the tile itself lies in the unit cube)
      • Snappy (because there is no parameters-array as an input, but additional parameters like a, b, r and the test is constructed for the parameters-array as an input)
  • Add test for tile derivatives: test derivatives of tiles w.r.t. the parameters by comparing implemented derivatives to the ones obtained by finite differences. This also checks if derivatives work when closure is applied

@markriegler markriegler linked an issue Oct 10, 2024 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing All about software testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microtile closure Microtile derivatives Test Microstructure
1 participant