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

Feat/coupling expansion #73

Merged
merged 49 commits into from
Dec 6, 2024
Merged

Feat/coupling expansion #73

merged 49 commits into from
Dec 6, 2024

Conversation

LemurPwned
Copy link
Owner

@LemurPwned LemurPwned commented Jun 15, 2024

Summary by Sourcery

Expand the functionality of the AxialDriver and ScalarDriver classes with new methods and overloads. Enhance the Stack class with phase offset and effective coupling strength handling. Improve documentation and error handling across multiple modules. Update the pre-commit configuration and add new test cases for driver operations.

New Features:

  • Introduce multiple overloads for the AxialDriver class constructor to support initialization with different parameter types.
  • Add new methods to the ScalarDriver class for arithmetic operations and phase shifting.
  • Implement new methods in the Stack class to handle phase offsets and effective coupling strengths.
  • Add support for HDMI drivers in the Layer and Junction classes.
  • Introduce new functions in the resistance module to compute GMR and handle 3D arrays for time series resistance calculations.

Enhancements:

  • Enhance docstrings across multiple classes and methods for better clarity and documentation.
  • Refactor the Stack class to include phase offsets and effective coupling strength calculations.
  • Improve error handling in the Stack class for coupling strength vector size validation.
  • Update plotting functions in the utils/plotting.py to use consistent string formatting.
  • Refactor the LLGBJunction class to include detailed docstrings and improved method signatures.

Documentation:

  • Update the mkdocs configuration to include new API documentation paths.
  • Add new API documentation files for core, stack, noise, and LLGB modules.
  • Improve the main documentation index with updated installation instructions and links.

Tests:

  • Add new test cases in test_drivers.py to validate arithmetic operations on drivers.
  • Comment out certain test assertions in test_models.py to avoid numerical errors during testing.

Chores:

  • Update the pre-commit configuration to exclude third-party directories from certain checks.
  • Remove outdated docgen.py script from the hooks section in mkdocs.yml.
  • New Features:
    • Introduced multiple overloads for the AxialDriver class constructor to support initialization with different parameter types.
    • Added new methods to the ScalarDriver class for arithmetic operations and phase shifting.
    • Implemented new methods in the Stack class to handle phase offsets and effective coupling strengths.
    • Added support for HDMI drivers in the Layer and Junction classes.
    • Introduced new functions in the resistance module to compute GMR and handle 3D arrays for time series resistance calculations.
  • Enhancements:
    • Enhanced docstrings across multiple classes and methods for better clarity and documentation.
    • Refactored the Stack class to include phase offsets and effective coupling strength calculations.
    • Improved the error handling in the Stack class for coupling strength vector size validation.
    • Updated the plotting functions in the utils/plotting.py to use consistent string formatting.
    • Refactored the LLGBJunction class to include detailed docstrings and improved method signatures.
  • Documentation:
    • Updated the mkdocs configuration to include new API documentation paths.
    • Added new API documentation files for core, stack, noise, and LLGB modules.
    • Improved the main documentation index with updated installation instructions and links.
  • Tests:
    • Added new test cases in test_drivers.py to validate arithmetic operations on drivers.
    • Commented out certain test assertions in test_models.py to avoid numerical errors during testing.
  • Chores:
    • Updated the pre-commit configuration to exclude third-party directories from certain checks.
    • Removed outdated docgen.py script from the hooks section in mkdocs.yml.

Copy link
Contributor

sourcery-ai bot commented Jun 15, 2024

Reviewer's Guide by Sourcery

This pull request introduces significant enhancements to the codebase, including support for HDMI drivers, improved coupling mechanisms, and enhanced code quality through formatting and linting. The changes primarily focus on expanding the functionality of the magnetic junction simulation system while improving code organization and maintainability.

Class diagram for updated Driver classes

classDiagram
    class Driver {
        - T constantValue
        - T amplitude
        - T frequency
        - T phase
        - T period
        - T cycle
        - T timeStart
        - T timeStop
        - UpdateType update
        + Driver()
        + Driver(UpdateType, T, T, T, T, T, T, T, T)
        + getCurrentScalarValue(T&): T
        + setConstantValue(T&)
        + phaseShift(T&)
    }

    class ScalarDriver {
        - T edgeTime
        - T steadyTime
        + ScalarDriver(UpdateType, T, T, T, T, T, T, T, T, T, T)
        + getCurrentScalarValue(T&): T
        + getConstantDriver(T): ScalarDriver
        + getPulseDriver(T, T, T, T): ScalarDriver
        + getSineDriver(T, T, T, T): ScalarDriver
        + getPosSineDriver(T, T, T, T): ScalarDriver
        + getHalfSineDriver(T, T, T, T): ScalarDriver
        + getStepDriver(T, T, T, T): ScalarDriver
        + getTrapezoidDriver(T, T, T, T, T): ScalarDriver
        + getGaussianImpulseDriver(T, T, T, T): ScalarDriver
        + getGaussianStepDriver(T, T, T, T): ScalarDriver
        + getUnitAxis(): CVector<T>
        + operator*(T): ScalarDriver
        + operator*=(T): ScalarDriver
        + operator+(T): ScalarDriver
        + operator+=(T): ScalarDriver
    }

    class AxialDriver {
        - std::vector<ScalarDriver<T>> drivers
        + AxialDriver()
        + AxialDriver(ScalarDriver<T>, ScalarDriver<T>, ScalarDriver<T>)
        + getVectorAxialDriver(T, T, T): AxialDriver
        + applyMask(std::vector<unsigned int>)
        + applyMask(CVector<T>)
        + getCurrentAxialDrivers(T): CVector<T>
        + getConstantValues(): CVector<T>
        + getUnitAxis(): CVector<T>
    }

    Driver <|-- ScalarDriver
    Driver <|-- AxialDriver
Loading

File-Level Changes

Change Details Files
Added support for HDMI and IDMI (Interlayer Dzyaloshinskii-Moriya Interaction) drivers
  • Added new HdmiDriver field to Layer class
  • Implemented IDMI driver functionality for layer interactions
  • Added methods to set and handle HDMI and IDMI drivers
  • Added new interaction field calculations in effective field computation
core/junction.hpp
core/stack.hpp
Enhanced coupling mechanisms in Stack implementation
  • Added support for phase offsets in coupling calculations
  • Implemented vector-based coupling strength
  • Added methods for effective coupling strength calculation
  • Improved coupling current density computations
core/stack.hpp
Improved code organization and modernization
  • Reorganized header includes for better dependency management
  • Added explicit type conversions to avoid implicit conversions
  • Improved const correctness throughout the codebase
  • Enhanced error handling and validation
core/junction.hpp
core/drivers.hpp
core/noise.hpp
Enhanced code quality and development tools
  • Updated pre-commit configuration with new hooks
  • Added clang-format and clang-tidy checks
  • Added Ruff for Python code formatting and linting
  • Updated code formatting rules and exclusions
.pre-commit-config.yaml

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

@LemurPwned LemurPwned linked an issue Jun 15, 2024 that may be closed by this pull request
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 @LemurPwned - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 12 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 5 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

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 to tell me if it was helpful.

cmtj/__init__.pyi Outdated Show resolved Hide resolved
cmtj/__init__.pyi Outdated Show resolved Hide resolved
cmtj/__init__.pyi Outdated Show resolved Hide resolved
cmtj/__init__.pyi Outdated Show resolved Hide resolved
core/stack.hpp Outdated Show resolved Hide resolved
tests/test_drivers.py Show resolved Hide resolved
tests/test_drivers.py Outdated Show resolved Hide resolved
docs/index.md Show resolved Hide resolved
tests/test_models.py Outdated Show resolved Hide resolved
tests/test_models.py Outdated Show resolved Hide resolved
LemurPwned and others added 4 commits June 15, 2024 14:07
@LemurPwned LemurPwned linked an issue Jul 22, 2024 that may be closed by this pull request
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@LemurPwned
Copy link
Owner Author

@sourcery-ai review

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 @LemurPwned - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding more unit tests to cover the new HDMI and phase offset functionality
Here's what I looked at during the review
  • 🟡 General issues: 7 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 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.

core/llgb.hpp Show resolved Hide resolved
elementIndx % this->cols);
const tensor getDipoleTensorFromRelPositions(const CVector<double> &r1,
const CVector<double> &r2) {
const CVector<double> rij = r1 - r2; // 1-2 distance vector
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Add check for zero distance between points to avoid numerical instability

When points are very close, the dipole tensor calculation can become numerically unstable. Consider adding a minimum distance check.

Suggested change
const CVector<double> rij = r1 - r2; // 1-2 distance vector
const CVector<double> rij = r1 - r2;
if (rij.length() < 1e-10) {
throw std::runtime_error("Points are too close for stable dipole calculation");
}

// }
return dipoleTensor;
public:
GroupInteraction(std::vector<CVector<double>> coordinateMatrix,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Move coordinate vector validation earlier in constructor

Validate coordinate vectors before copying to avoid unnecessary operations when validation fails.

Suggested change
GroupInteraction(std::vector<CVector<double>> coordinateMatrix,
GroupInteraction(const std::vector<CVector<double>>& coordinateMatrix,

return *this;
}

CVector operator/(T val) {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Add zero division check in operator/= to match operator/ implementation

The operator/= member function should include the same zero division check that exists in operator/ to maintain consistency and prevent potential crashes.

Copy link
Owner Author

Choose a reason for hiding this comment

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

There is a check for that

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your feedback, we will generate fewer comments like this in the future according to the following instructions:

- Ensure the comment addresses a specific issue or improvement in the code.
- Verify that the comment provides a clear explanation of the problem and suggests a solution.
- Check if the comment is relevant to the current code changes and not redundant with existing checks or logic.
- Confirm that the comment maintains consistency with the overall codebase practices.

python/cmtj.cpp Show resolved Hide resolved
core/compute.hpp Show resolved Hide resolved
Comment on lines +49 to +57
def test_driver_ops():
driver = sineDriver(10, 20, 1, 0)
assert driver.getCurrentScalarValue(1 / 4) == 30
driver *= 2
assert driver.getCurrentScalarValue(1 / 4) == 60

driver = sineDriver(10, 20, 1, 0)
driver += 2
assert driver.getCurrentScalarValue(1 / 4) == 34
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Test case should verify error handling for driver operations

The test verifies basic arithmetic operations but doesn't check error cases. Consider adding tests for invalid operations (e.g. multiplying by zero, negative values) and edge cases.

def test_driver_ops():
    driver = sineDriver(10, 20, 1, 0)
    assert driver.getCurrentScalarValue(1 / 4) == 30
    driver *= 2
    assert driver.getCurrentScalarValue(1 / 4) == 60

    with pytest.raises(ValueError):
        driver *= 0
    with pytest.raises(ValueError):
        driver *= -1

    driver = sineDriver(10, 20, 1, 0)
    driver += 2
    assert driver.getCurrentScalarValue(1 / 4) == 34

tests/test_models.py Show resolved Hide resolved
cmtj/utils/resistance.py Show resolved Hide resolved
cmtj/models/oersted.py Show resolved Hide resolved
@LemurPwned LemurPwned merged commit cdc2cfb into master Dec 6, 2024
0 of 6 checks passed
@LemurPwned LemurPwned deleted the feat/coupling-expansion branch December 6, 2024 19:47
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.

Custom Scalar Driver Add DMI interaction
1 participant