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

Refactor derivative operator creation with factory function #115

Merged
merged 2 commits into from Mar 27, 2024

Conversation

bjorgve
Copy link
Member

@bjorgve bjorgve commented Mar 27, 2024

Refactor Derivative Operator Creation

This pull request introduces a significant refactor to the way derivative operators are created within the vampyr Python interface. A new factory function named Derivative has been added to simplify the creation process and provide a more intuitive interface for users.

Usage Instructions:

To create a derivative operator, you can now use the Derivative function with the desired type as a string argument. Here are the possible types and their corresponding operator configurations:

  • "center": Creates an ABGVOperator with parameters (0.5, 0.5)
  • "simple": Creates an ABGVOperator with parameters (0.0, 0.0)
  • "forward": Creates an ABGVOperator with parameters (0.0, 1.0)
  • "backward": Creates an ABGVOperator with parameters (1.0, 0.0)
  • "b-spline": Creates a BSOperator with a specified order (default is 1)
  • "ph": Creates a PHOperator with a specified order (default is 1)

Here's an example of how to use the new interface:

# Assuming `mra` is an instance of MultiResolutionAnalysis<D>
D_abgv_center = vampyr.Derivative(mra, type="center")
D_abgv_simple = vampyr.Derivative(mra, type="simple")
D_abgv_forward = vampyr.Derivative(mra, type="forward")
D_abgv_backward = vampyr.Derivative(mra, type="backward")
D_b_spline = vampyr.Derivative(mra, type="b-spline", order=2)
D_ph = vampyr.Derivative(mra, type="ph", order=2)

This commit introduces a new factory function `Derivative` to the
`derivatives` module. This function streamlines the creation of
derivative operators by allowing users to specify the type of
derivative operator they wish to create using a string identifier.
The supported types are "center", "simple", "forward", "backward",
"b-spline", and "ph", which correspond to the ABGVOperator with
specific parameters and the BSOperator and PHOperator with a
specified order.

The factory function returns a unique pointer to the created
derivative operator, ensuring proper memory management and
simplifying the Python interface.

Additionally, this commit removes the direct exposure of the
specific derivative operator classes to the Python interface,
encouraging the use of the new factory function for creating
derivative operators.
Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.19%. Comparing base (2c52b30) to head (2a87fae).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #115   +/-   ##
=======================================
  Coverage   63.19%   63.19%           
=======================================
  Files           4        4           
  Lines         269      269           
=======================================
  Hits          170      170           
  Misses         99       99           

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

@stigrj
Copy link
Contributor

stigrj commented Mar 27, 2024

Excellent! Perhaps add a default also for the type="center"?

@stigrj stigrj merged commit 9562ace into MRChemSoft:master Mar 27, 2024
10 checks passed
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.

None yet

2 participants