PaNOSC-ViNYL / McStasScript

McStas API for creating and running McStas instruments from python scripting
BSD 3-Clause "New" or "Revised" License
9 stars 12 forks source link

Dumping error with pint quantities #48

Open shervin86 opened 2 years ago

shervin86 commented 2 years ago

The following error raises when trying to dump a McStas instrument with some parameters defined as pint.Quantity:

_pickle.PicklingError: Can't pickle <class 'pint.quantity.build_quantity_class.<locals>.Quantity'>: it's not found as pint.quantity.build_quantity_class.<locals>.Quantity

How to reproduce the issue:

git clone -b thales git@github.com:PaNOSC-ViNYL/instrument_database.git
git checkout 3f11a9f48e0247b514d16bc3ee7eb937a638d741
cd instrument_database/
pip install -e instrumentDataBaseAPI/

from instrumentdatabaseapi import instrumentdatabaseapi as API

repo = API.Repository(local_repo=".")
myinstrument = repo.load("ILL", "ThALES", "HEAD", "mcstas", dep=False)

import pint
ureg = pint.get_application_registry()

a2 = myinstrument.parameters["ThALES"]["a2"]
energy = 4.48
dE = 0.05
a2.energy = energy * ureg.meV
myinstrument.run()
myThALES = myinstrument.calculators["ThALES"]
myThALES.dump("/tmp/myThALES.py")
shervin86 commented 2 years ago

I think it is a libpyvinyl bug and not of McStasscript.