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

PySpinW implementation #143

Merged
merged 40 commits into from
May 17, 2023
Merged

PySpinW implementation #143

merged 40 commits into from
May 17, 2023

Conversation

wardsimon
Copy link

This pull request deals with the creation of a python wheel.

A wheel is created in the following steps:

  • Windows/Linux/OSX, R2023a - Compile MEX functions
  • OSX, R2021a-R2023a - Compile SpinW m-files and mex files to MATLAB version dependent CTF files
  • Linux, ALL - Build wheel from all CTF's

At the moment a release will be created on the SpinW repo if there is a tag.

In order to run the code a version of MATLAB (R2021a-R2023a) or corresponding runtime must be installed.

Please install with

pip install pyspinw*.whl

This package can now be used in python if you have a version of MATLAB or MCR available on the machine.
The package will try to automatically detect your installation, however if it is in a non-standard location, the path and version will have to be especified.

m = Matlab(matlab_version='R2023a', matlab_path='/usr/local/MATLAB/R2023a/')

Example

An example would be:

import numpy as np
from pyspinw import Matlab

m = Matlab()

# Create a spinw model, in this case a triangular antiferromagnet
s = m.sw_model('triAF', 1)

# Specify the start and end points of the q grid and the number of points
q_start = [0, 0, 0]
q_end = [1, 1, 0]
pts = 501

# Calculate the spin wave spectrum
spec = m.spinwave(s, [q_start, q_end, pts])

Known limitations

At the moment graphics will not work on macOS systems and is disabled.

@wardsimon wardsimon requested a review from mducle May 16, 2023 13:53
@wardsimon wardsimon added the enhancement New feature or request label May 16, 2023
@github-actions
Copy link

github-actions bot commented May 16, 2023

Test Results

       4 files  ±0       98 suites  ±0   18m 20s ⏱️ +14s
   583 tests ±0     583 ✔️ ±0  0 💤 ±0  0 ±0 
1 622 runs  ±0  1 622 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 0c0de97. ± Comparison against base commit 4ede5fa.

♻️ This comment has been updated with latest results.

@codecov-commenter
Copy link

codecov-commenter commented May 16, 2023

Codecov Report

Merging #143 (5479cbf) into master (9c71313) will decrease coverage by 0.06%.
The diff coverage is 42.59%.

@@            Coverage Diff             @@
##           master     #143      +/-   ##
==========================================
- Coverage   38.73%   38.67%   -0.06%     
==========================================
  Files         239      239              
  Lines       15795    15829      +34     
==========================================
+ Hits         6118     6122       +4     
- Misses       9677     9707      +30     
Impacted Files Coverage Δ
swfiles/@spinw/spinwave.m 98.32% <ø> (+1.19%) ⬆️
swfiles/@swpref/private/datastruct.m 80.19% <ø> (+4.95%) ⬆️
swfiles/sw_mex.m 0.00% <0.00%> (ø)
swfiles/sw_timeit.m 8.97% <33.33%> (-50.49%) ⬇️
external/mmat.m 67.34% <57.14%> (-13.61%) ⬇️
swfiles/@spinw/genmagstr.m 100.00% <100.00%> (ø)
swfiles/sw_cartesian.m 65.51% <100.00%> (ø)

... and 10 files with indirect coverage changes

Copy link
Member

@mducle mducle left a comment

Choose a reason for hiding this comment

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

Looks good. A couple of typos in the code, and some comments regarding versions and the actions yml file...

At the moment a release will be created on the SpinW repo if there is a tag.

So to create a release you would do git tag v0.0.3 && git push origin v0.0.3? (But you have to manually change the version number in the toml file?

.github/workflows/build_pyspinw.yml Show resolved Hide resolved
python/pyproject.toml Show resolved Hide resolved
python/pyspinw/__init__.py Show resolved Hide resolved
python/release_notes.md Outdated Show resolved Hide resolved
python/release_notes.md Outdated Show resolved Hide resolved
.github/workflows/build_pyspinw.yml Show resolved Hide resolved
.github/workflows/build_pyspinw.yml Show resolved Hide resolved
.github/workflows/build_pyspinw.yml Show resolved Hide resolved
.github/workflows/build_pyspinw.yml Outdated Show resolved Hide resolved
python/pyproject.toml Show resolved Hide resolved
@wardsimon
Copy link
Author

Can @mducle or @RichardWaiteSTFC have a look at the failed test. It is probably a tolerance issue, but I do not know if it is known to be temperamental.

@mducle
Copy link
Member

mducle commented May 17, 2023

@wardsimon Yes, it's a flaky test of optmagk due to the RNG starting point where it doesn't quite converge. It's the first time we've seen this particular test failing but other tests in that suite had failed similarly before. Can you add this diff to try to fix it:

diff --git a/+sw_tests/+unit_tests/unittest_spinw_optmagk.m b/+sw_tests/+unit_tests/unittest_spinw_optmagk.m
index 4d184cf..2d04862 100644
--- a/+sw_tests/+unit_tests/unittest_spinw_optmagk.m
+++ b/+sw_tests/+unit_tests/unittest_spinw_optmagk.m
@@ -55,7 +55,7 @@ classdef unittest_spinw_optmagk < sw_tests.unit_tests.unittest_super
         function test_fm_chain_optk(testCase)
             testCase.swobj.addmatrix('label', 'J1', 'value', -1);
             testCase.swobj.addcoupling('mat', 'J1', 'bond', 1);
-            out = testCase.swobj.optmagk;
+            out = testCase.swobj.optmagk('seed', 1);
             out.stat = rmfield(out.stat, 'nFunEvals');

             expected_mag_str = testCase.default_mag_str;

@mducle mducle merged commit 80d30ff into master May 17, 2023
15 checks passed
@mducle mducle deleted the pyspinw branch July 23, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants