Here's a minimal example that often gives the error, but usually not on the first call to copy.
If the class creates only one parameter, then I cannot reproduce the error.
from easyscience.variable import Parameter
from easyscience.base_classes.model_base import ModelBase
import scipp as sc
import numpy as np
class A(ModelBase):
def __init__(self, par1, par2,par3):
super().__init__()
A._par1=Parameter(name='name1',value=par1)
A._par2=Parameter(name='name2',value=par2)
A._par3=Parameter(name='name3',value=par3)
@property
def par1(self):
return self._par1
@par1.setter
def par1(self,value):
self._par1.value=value
@property
def par2(self):
return self._par2
@par2.setter
def par2(self,value):
self._par2.value=value
@property
def par3(self):
return self._par3
@par3.setter
def par3(self,value):
self._par3.value=value
# The serializer checks if @module starts with easy and raises if not.
def to_dict(self,skip):
dict=super().to_dict(skip=skip)
dict['@module']='easy'+dict['@module']
return dict
coords = {'Q': sc.array(dims=['Q'], values=[1, 2, 3,4,5,6,7,8,9,10], unit='K'),
'temperature': sc.array(dims=['temperature'], values=[10, 20, 30, 40, 50])}
shape = tuple(
coord.sizes[dim]
for dim, coord in coords.items()
)
values = np.empty(
shape,
dtype=object,
)
for idx in np.ndindex(shape):
values[idx] = A(par1=1, par2=2, par3=3)
sizes = {
dim: coord.sizes[dim]
for dim, coord in coords.items()
}
array = sc.array(dims=["flat"], values=values.flatten()).fold(
dim="flat", sizes=sizes
)
data_array = sc.DataArray(data=array, coords=coords)
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
data_array.copy()
shape=(20,15)
values = np.empty(
shape,
dtype=object,
)
for idx in np.ndindex(shape):
values[idx] = A(par1=1, par2=2, par3=3)
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
values.copy()
Here's a minimal example that often gives the error, but usually not on the first call to copy.
If the class creates only one parameter, then I cannot reproduce the error.
Interestingly, if I don't use scipp then I cannot reproduce the error
This works, even though it creates more parameters: