SpinW / spinw

SpinW Matlab library for spin wave calculation
http://www.spinw.org
GNU General Public License v3.0
35 stars 15 forks source link

Unable to change some of the parameters in py #171

Closed Artemkth closed 4 months ago

Artemkth commented 5 months ago

It is unclear how to set parameters like 'rdip' in python. Trying to change the element of a dictionary doesn't propagate into backend:

nips.coupling['rdip'] = 10.
print('Dipolar coupling current max distance: ', nips.coupling['rdip'])

this example outputs '[[0.]]' instead of expected '[[10.]]'.

The standard way of accessing it like examples do

nips.coupling.rdip = 10.

isn't available either.

mducle commented 5 months ago

This is because the .coupling property is converted to a Python dict with no way for Matlab to register any changes.

Ideally we should change the code so that the nips.coupling.rdip = 10 syntax works but this either requires:

  1. A wrapper Python class to handle all the non-object properties.
  2. Refactoring the Matlab code to avoid exposing non-object properties to uses, only objects (at least for properties which should be settable).

@RichardWaiteSTFC - I'm inclined towards option 1, but what do you think?


@Artemkth for now you can use this very clunky work-around, which sets the properties in Matlab, and then re-exports the class back to Python.

coupling = nips.coupling
coupling['rdip'] = 10
m.assignin('base', 'nips', nips)
m.assignin('base', 'coupling', coupling)
nips = m.evalin('base', "subsasgn(nips, struct('type','.','subs','coupling'), coupling')")
nips.coupling['rdip']

The final line should print array([[10.]]).