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

Fix the creation of .mat files #627

Merged
merged 1 commit into from
Jul 13, 2023
Merged

Fix the creation of .mat files #627

merged 1 commit into from
Jul 13, 2023

Conversation

lfarv
Copy link
Contributor

@lfarv lfarv commented Jul 12, 2023

This fixes a bug reported by @oscarxblanco here.

The following sequence:

  1. Saving a .mat file in PyAT
  2. reading the file in Matlab
  3. saving as a .m file in Matlab
  4. Reading the ,m fill-in python

throws an Exception when reading sextuples.

Explanation: The attribute H (sextuple strength) exists as a property in python, but does not exist in Matlab. It is not present in .mat files created in Matlab, but does exist in .mat files created in python. When reading such a file in Matlab, the sextupoles get an unexpected H attribute, which has no detrimental effect, However when saving in a .m file, H is printed as a "exotic" attribute, which is wrongly interpreted.

In this PR, H does not appear in .mat files created in python.

@lfarv lfarv added Python For python AT code bug fix labels Jul 12, 2023
@lfarv lfarv requested a review from oscarxblanco July 12, 2023 19:40
Copy link
Contributor

@oscarxblanco oscarxblanco left a comment

Choose a reason for hiding this comment

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

I have made a simplified test using a lattice with a single sextupole and it executes w/o errors.
(NOTE : here I use a custom script called setatversion that sets the AT matlab version under test)

python -c "import at; s1 = at.Sextupole('S6',0.4,-3.6); ring = at.Lattice([s1],energy='1'); at.save_mat(ring,'pyatsaveSext.mat');"
matlab -nosplash -nodisplay -r "clear all; setatversion;load('pyatsaveSext.mat'); atwritem(RING,'matlabwriteSext.m');exit;"
python -c "import at; ring=at.load_m('matlabwriteSext.m')"

Additionally, I did a test with a more general lattice and it also executes w/o issues.

I think this could be safely merged.

@lfarv lfarv merged commit e2ab70c into master Jul 13, 2023
31 checks passed
@lfarv lfarv deleted the fix_save_mat branch July 13, 2023 11:08
lnadolski added a commit that referenced this pull request Oct 25, 2023
…into include_soleil_changes

* 'EnergyLossRadPass' of https://github.com/atcollab/at.git:
  fixed ringpara and atsummary
  Update atenable_6d.m
  Update atdisable_6d.m
  Update atenergyloss.m
  Remove the Energy field in python
  Computation of energy loss with 'integral' method working
  Handled enable/disable_6d, element constructors in python and Matlab, load and save .m and .mat files
  Update EnergyLossRadPass.c
  Added EnergyLossRadPass
  Added EnergyLossRadPass
  Fix the creation of .mat files (#627)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Python For python AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants