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

Feature/update float3d example #450

Merged
merged 7 commits into from
Nov 16, 2024
Merged

Feature/update float3d example #450

merged 7 commits into from
Nov 16, 2024

Conversation

blooop
Copy link
Collaborator

@blooop blooop commented Nov 3, 2024

Summary by Sourcery

Enhancements:

  • Refactor the VolumeSample class to VolumeSweep and integrate the functionality of VolumeResult into it, simplifying the class structure and improving code readability.

Copy link
Contributor

sourcery-ai bot commented Nov 3, 2024

Reviewer's Guide by Sourcery

This PR refactors the 3D volume example by consolidating the VolumeSample and VolumeResult classes into a single VolumeSweep class, and converting the standalone benchmark function into a class method. The changes also include updates to the plotting configuration and parameter handling.

Updated class diagram for VolumeSweep

classDiagram
    class VolumeSweep {
        FloatSweep x
        FloatSweep y
        FloatSweep z
        ResultVar value
        ResultVar occupancy
        ResultVar interesting
        list interesting_vec
        list interesting_vec_and_occ
        +__call__(**kwargs) dict
        +update_params_from_kwargs(**kwargs)
    }
    note for VolumeSweep "Consolidated from VolumeSample and VolumeResult"
Loading

File-Level Changes

Change Details Files
Consolidate volume-related classes and convert benchmark function to class method
  • Rename VolumeSample class to VolumeSweep
  • Merge VolumeResult class properties into VolumeSweep
  • Convert bench_fn to call method within VolumeSweep class
  • Add update_params_from_kwargs handling in call method
  • Update self references for accessing class properties
bencher/example/example_float3D.py
Simplify bench creation and update plotting configuration
  • Replace explicit Bench constructor with to_bench() method call
  • Update input_vars to use string references instead of class parameters
  • Simplify result_vars configuration using string names
  • Add max_level specification for z parameter
  • Increase default run configuration level from 3 to 6
bencher/example/example_float3D.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@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.

Hey @blooop - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The docstring in __call__ still refers to the old function signature with point parameter - it should be updated to reflect the new kwargs-based interface
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

import bencher as bch


class VolumeSample(bch.ParametrizedSweep):
class VolumeSweep(bch.ParametrizedSweep):
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider separating input parameters and results into distinct classes to improve code organization

The merged VolumeSweep class combines input parameters with results, making the code harder to maintain. Here's how to achieve the same fluent API while maintaining better separation of concerns:

class VolumeSample(bch.ParametrizedSweep):
    x = bch.FloatSweep(default=0, bounds=[-1.0, 1.0], doc="x coordinate", samples=4)
    y = bch.FloatSweep(default=0, bounds=[-1.0, 1.0], doc="y coordinate", samples=5)
    z = bch.FloatSweep(default=0, bounds=[-1.0, 1.0], doc="z coordinate", samples=6)

    def compute(self, **kwargs) -> 'VolumeResult':
        self.update_params_from_kwargs(**kwargs)
        result = VolumeResult()
        result.value = np.linalg.norm(np.array([self.x, self.y, self.z]))
        # ... set other result fields ...
        return result

    def to_bench(self, **kwargs) -> bch.Bench:
        return bch.Bench(
            compute_fn=self.compute,
            param_cls=self.__class__,
            **kwargs
        )

class VolumeResult(bch.ParametrizedSweep):
    value = bch.ResultVar("ul", doc="The scalar value of the 3D volume field")
    # ... other result fields ...

This approach:

  • Maintains clear separation between inputs and outputs
  • Preserves type safety in plot_sweep() calls
  • Keeps the fluent API benefits
  • Makes the data flow more explicit

Copy link

codecov bot commented Nov 16, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.48%. Comparing base (3f0928f) to head (6d1f873).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
bencher/example/example_float3D.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #450      +/-   ##
==========================================
- Coverage   90.48%   90.48%   -0.01%     
==========================================
  Files          61       61              
  Lines        3384     3383       -1     
==========================================
- Hits         3062     3061       -1     
  Misses        322      322              

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

@blooop blooop merged commit e88bd5d into main Nov 16, 2024
7 checks passed
@blooop blooop deleted the feature/update_float3d_example branch November 16, 2024 13:46
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