easyscience 1.2.0__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {easyscience-1.2.0 → easyscience-1.3.0}/PKG-INFO +5 -5
- {easyscience-1.2.0 → easyscience-1.3.0}/pyproject.toml +6 -6
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Constraints.py +7 -37
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Datasets/xarray.py +1 -1
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/Groups.py +9 -9
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/Inferface.py +5 -5
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/ObjectClasses.py +14 -22
- {easyscience-1.2.0/src/easyscience/Objects/new_variable → easyscience-1.3.0/src/easyscience/Objects/variable}/__init__.py +4 -0
- easyscience-1.3.0/src/easyscience/Objects/variable/descriptor_any_type.py +93 -0
- easyscience-1.3.0/src/easyscience/Objects/variable/descriptor_array.py +793 -0
- {easyscience-1.2.0/src/easyscience/Objects/new_variable → easyscience-1.3.0/src/easyscience/Objects/variable}/descriptor_base.py +1 -1
- {easyscience-1.2.0/src/easyscience/Objects/new_variable → easyscience-1.3.0/src/easyscience/Objects/variable}/descriptor_number.py +30 -8
- {easyscience-1.2.0/src/easyscience/Objects/new_variable → easyscience-1.3.0/src/easyscience/Objects/variable}/parameter.py +22 -7
- easyscience-1.3.0/src/easyscience/__version__.py +1 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/minimizer_base.py +5 -19
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/minimizer_bumps.py +4 -16
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/minimizer_dfo.py +6 -26
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/minimizer_lmfit.py +3 -11
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/models/polynomial.py +7 -7
- easyscience-1.2.0/src/easyscience/Objects/Variable.py +0 -889
- easyscience-1.2.0/src/easyscience/Objects/virtual.py +0 -193
- easyscience-1.2.0/src/easyscience/__version__.py +0 -1
- {easyscience-1.2.0 → easyscience-1.3.0}/.gitignore +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/LICENSE +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/README.md +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Datasets/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/core.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/job/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/job/analysis.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/job/experiment.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/job/job.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Objects/job/theoreticalmodel.py +0 -0
- {easyscience-1.2.0/src/easyscience/Objects/new_variable → easyscience-1.3.0/src/easyscience/Objects/variable}/descriptor_bool.py +0 -0
- {easyscience-1.2.0/src/easyscience/Objects/new_variable → easyscience-1.3.0/src/easyscience/Objects/variable}/descriptor_str.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/REDIRECT.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/Exceptions.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/classTools.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/classUtils.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/decorators.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/io/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/io/dict.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/io/json.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/io/template.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/io/xml.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/Utils/string.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/available_minimizers.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/fitter.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/factory.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/minimizers/utils.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/fitting/multi_fitter.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/global_object.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/hugger/__init__.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/hugger/hugger.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/hugger/property.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/logger.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/map.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/global_object/undo_redo.py +0 -0
- {easyscience-1.2.0 → easyscience-1.3.0}/src/easyscience/models/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: easyscience
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Generic logic for easyScience libraries
|
|
5
5
|
Project-URL: homepage, https://github.com/EasyScience/EasyScience
|
|
6
6
|
Project-URL: documentation, https://easyscience.github.io/EasyScience/
|
|
@@ -40,18 +40,18 @@ Classifier: License :: OSI Approved :: BSD License
|
|
|
40
40
|
Classifier: Operating System :: OS Independent
|
|
41
41
|
Classifier: Programming Language :: Python :: 3
|
|
42
42
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
43
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
44
43
|
Classifier: Programming Language :: Python :: 3.10
|
|
45
44
|
Classifier: Programming Language :: Python :: 3.11
|
|
46
45
|
Classifier: Programming Language :: Python :: 3.12
|
|
46
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
47
47
|
Classifier: Topic :: Scientific/Engineering
|
|
48
|
-
Requires-Python:
|
|
48
|
+
Requires-Python: >=3.10
|
|
49
49
|
Requires-Dist: asteval
|
|
50
50
|
Requires-Dist: bumps
|
|
51
51
|
Requires-Dist: dfo-ls
|
|
52
52
|
Requires-Dist: lmfit
|
|
53
|
-
Requires-Dist: numpy
|
|
54
|
-
Requires-Dist: pint
|
|
53
|
+
Requires-Dist: numpy
|
|
54
|
+
Requires-Dist: pint
|
|
55
55
|
Requires-Dist: scipp
|
|
56
56
|
Requires-Dist: uncertainties
|
|
57
57
|
Requires-Dist: xarray
|
|
@@ -21,22 +21,22 @@ classifiers = [
|
|
|
21
21
|
"Topic :: Scientific/Engineering",
|
|
22
22
|
"Programming Language :: Python :: 3",
|
|
23
23
|
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
-
"Programming Language :: Python :: 3.9",
|
|
25
24
|
"Programming Language :: Python :: 3.10",
|
|
26
25
|
"Programming Language :: Python :: 3.11",
|
|
27
26
|
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
28
|
"Development Status :: 3 - Alpha"
|
|
29
29
|
]
|
|
30
|
-
requires-python = ">=3.
|
|
30
|
+
requires-python = ">=3.10"
|
|
31
31
|
dependencies = [
|
|
32
32
|
"asteval",
|
|
33
33
|
"bumps",
|
|
34
34
|
"DFO-LS",
|
|
35
35
|
"lmfit",
|
|
36
|
-
"numpy
|
|
36
|
+
"numpy",
|
|
37
37
|
"uncertainties",
|
|
38
38
|
"xarray",
|
|
39
|
-
"pint
|
|
39
|
+
"pint", # Only to ensure that unit is reported as dimensionless rather than empty string
|
|
40
40
|
"scipp"
|
|
41
41
|
]
|
|
42
42
|
|
|
@@ -128,13 +128,13 @@ force-single-line = true
|
|
|
128
128
|
legacy_tox_ini = """
|
|
129
129
|
[tox]
|
|
130
130
|
isolated_build = True
|
|
131
|
-
envlist = py{3.
|
|
131
|
+
envlist = py{3.10,3.11,3.12,3.13}
|
|
132
132
|
[gh-actions]
|
|
133
133
|
python =
|
|
134
|
-
3.9: py39
|
|
135
134
|
3.10: py310
|
|
136
135
|
3.11: py311
|
|
137
136
|
3.12: py312
|
|
137
|
+
3.13: py313
|
|
138
138
|
[gh-actions:env]
|
|
139
139
|
PLATFORM =
|
|
140
140
|
ubuntu-latest: linux
|
|
@@ -194,13 +194,9 @@ class NumericConstraint(ConstraintBase):
|
|
|
194
194
|
super(NumericConstraint, self).__init__(dependent_obj, operator=operator, value=value)
|
|
195
195
|
|
|
196
196
|
def _parse_operator(self, obj: V, *args, **kwargs) -> Number:
|
|
197
|
-
## TODO
|
|
198
|
-
import easyscience.Objects.new_variable.parameter
|
|
197
|
+
## TODO Probably needs to be updated when DescriptorArray is implemented
|
|
199
198
|
|
|
200
|
-
|
|
201
|
-
value = obj.value_no_call_back
|
|
202
|
-
else:
|
|
203
|
-
value = obj.raw_value
|
|
199
|
+
value = obj.value_no_call_back
|
|
204
200
|
|
|
205
201
|
if isinstance(value, list):
|
|
206
202
|
value = np.array(value)
|
|
@@ -258,13 +254,7 @@ class SelfConstraint(ConstraintBase):
|
|
|
258
254
|
super(SelfConstraint, self).__init__(dependent_obj, operator=operator, value=value)
|
|
259
255
|
|
|
260
256
|
def _parse_operator(self, obj: V, *args, **kwargs) -> Number:
|
|
261
|
-
|
|
262
|
-
import easyscience.Objects.new_variable.parameter
|
|
263
|
-
|
|
264
|
-
if isinstance(obj, easyscience.Objects.new_variable.parameter.Parameter):
|
|
265
|
-
value = obj.value_no_call_back
|
|
266
|
-
else:
|
|
267
|
-
value = obj.raw_value
|
|
257
|
+
value = obj.value_no_call_back
|
|
268
258
|
|
|
269
259
|
self.aeval.symtable['value1'] = value
|
|
270
260
|
self.aeval.symtable['value2'] = getattr(obj, self.value)
|
|
@@ -322,13 +312,7 @@ class ObjConstraint(ConstraintBase):
|
|
|
322
312
|
self.external = True
|
|
323
313
|
|
|
324
314
|
def _parse_operator(self, obj: V, *args, **kwargs) -> Number:
|
|
325
|
-
|
|
326
|
-
import easyscience.Objects.new_variable.parameter
|
|
327
|
-
|
|
328
|
-
if isinstance(obj, easyscience.Objects.new_variable.parameter.Parameter):
|
|
329
|
-
value = obj.value_no_call_back
|
|
330
|
-
else:
|
|
331
|
-
value = obj.raw_value
|
|
315
|
+
value = obj.value_no_call_back
|
|
332
316
|
|
|
333
317
|
self.aeval.symtable['value1'] = value
|
|
334
318
|
try:
|
|
@@ -417,16 +401,11 @@ class MultiObjConstraint(ConstraintBase):
|
|
|
417
401
|
self.external = True
|
|
418
402
|
|
|
419
403
|
def _parse_operator(self, independent_objs: List[V], *args, **kwargs) -> Number:
|
|
420
|
-
import easyscience.Objects.new_variable.parameter
|
|
421
404
|
|
|
422
405
|
in_str = ''
|
|
423
406
|
value = None
|
|
424
407
|
for idx, obj in enumerate(independent_objs):
|
|
425
|
-
|
|
426
|
-
if isinstance(obj, easyscience.Objects.new_variable.parameter.Parameter):
|
|
427
|
-
self.aeval.symtable['p' + str(self.independent_obj_ids[idx])] = obj.value_no_call_back
|
|
428
|
-
else:
|
|
429
|
-
self.aeval.symtable['p' + str(self.independent_obj_ids[idx])] = obj.raw_value
|
|
408
|
+
self.aeval.symtable['p' + str(self.independent_obj_ids[idx])] = obj.value_no_call_back
|
|
430
409
|
|
|
431
410
|
in_str += ' p' + str(self.independent_obj_ids[idx])
|
|
432
411
|
if idx < len(self.operator):
|
|
@@ -485,25 +464,16 @@ class FunctionalConstraint(ConstraintBase):
|
|
|
485
464
|
self.external = True
|
|
486
465
|
|
|
487
466
|
def _parse_operator(self, obj: V, *args, **kwargs) -> Number:
|
|
488
|
-
import easyscience.Objects.new_variable.parameter
|
|
489
467
|
|
|
490
468
|
self.aeval.symtable[f'f{id(self.function)}'] = self.function
|
|
491
469
|
value_str = f'r_value = f{id(self.function)}('
|
|
492
470
|
if isinstance(obj, list):
|
|
493
471
|
for o in obj:
|
|
494
|
-
|
|
495
|
-
if isinstance(o, easyscience.Objects.new_variable.parameter.Parameter):
|
|
496
|
-
value_str += f'{o.value_no_call_back},'
|
|
497
|
-
else:
|
|
498
|
-
value_str += f'{o.raw_value},'
|
|
472
|
+
value_str += f'{o.value_no_call_back},'
|
|
499
473
|
|
|
500
474
|
value_str = value_str[:-1]
|
|
501
475
|
else:
|
|
502
|
-
|
|
503
|
-
if isinstance(obj, easyscience.Objects.new_variable.parameter.Parameter):
|
|
504
|
-
value_str += f'{obj.value_no_call_back}'
|
|
505
|
-
else:
|
|
506
|
-
value_str += f'{obj.raw_value}'
|
|
476
|
+
value_str += f'{obj.value_no_call_back}'
|
|
507
477
|
|
|
508
478
|
value_str += ')'
|
|
509
479
|
try:
|
|
@@ -281,7 +281,7 @@ class EasyScienceDatasetAccessor:
|
|
|
281
281
|
|
|
282
282
|
:param variable_label: Name of the DataArray to perform the calculation on
|
|
283
283
|
:type variable_label: str
|
|
284
|
-
:param sigma_func: Function to generate the sigmas. Must be of the form f(x) and return an array of the same shape as the input. Default sqrt(
|
|
284
|
+
:param sigma_func: Function to generate the sigmas. Must be of the form f(x) and return an array of the same shape as the input. Default sqrt(\\|x\\|)
|
|
285
285
|
:type sigma_func: Callable
|
|
286
286
|
:param label_prefix: What prefix should be used to designate a sigma DataArray from a data DataArray
|
|
287
287
|
:type label_prefix: str
|
|
@@ -15,17 +15,17 @@ from typing import Callable
|
|
|
15
15
|
from typing import List
|
|
16
16
|
from typing import Optional
|
|
17
17
|
from typing import Tuple
|
|
18
|
+
from typing import TypeVar
|
|
18
19
|
from typing import Union
|
|
19
20
|
|
|
20
21
|
from easyscience.global_object.undo_redo import NotarizedDict
|
|
21
|
-
from easyscience.Objects.new_variable.descriptor_base import DescriptorBase
|
|
22
22
|
from easyscience.Objects.ObjectClasses import BasedBase
|
|
23
|
-
from easyscience.Objects.
|
|
23
|
+
from easyscience.Objects.variable.descriptor_base import DescriptorBase
|
|
24
24
|
|
|
25
25
|
if TYPE_CHECKING:
|
|
26
26
|
from easyscience.Objects.Inferface import iF
|
|
27
27
|
from easyscience.Objects.ObjectClasses import B
|
|
28
|
-
|
|
28
|
+
V = TypeVar('V', bound=DescriptorBase)
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class BaseCollection(BasedBase, MutableSequence):
|
|
@@ -69,7 +69,7 @@ class BaseCollection(BasedBase, MutableSequence):
|
|
|
69
69
|
_kwargs[key] = item
|
|
70
70
|
kwargs = _kwargs
|
|
71
71
|
for item in list(kwargs.values()) + _args:
|
|
72
|
-
if not issubclass(type(item), (
|
|
72
|
+
if not issubclass(type(item), (DescriptorBase, BasedBase)):
|
|
73
73
|
raise AttributeError('A collection can only be formed from easyscience objects.')
|
|
74
74
|
args = _args
|
|
75
75
|
_kwargs = {}
|
|
@@ -102,12 +102,12 @@ class BaseCollection(BasedBase, MutableSequence):
|
|
|
102
102
|
:param index: Index for EasyScience object to be inserted.
|
|
103
103
|
:type index: int
|
|
104
104
|
:param value: Object to be inserted.
|
|
105
|
-
:type value: Union[BasedBase,
|
|
105
|
+
:type value: Union[BasedBase, DescriptorBase]
|
|
106
106
|
:return: None
|
|
107
107
|
:rtype: None
|
|
108
108
|
"""
|
|
109
109
|
t_ = type(value)
|
|
110
|
-
if issubclass(t_, (BasedBase,
|
|
110
|
+
if issubclass(t_, (BasedBase, DescriptorBase)):
|
|
111
111
|
update_key = list(self._kwargs.keys())
|
|
112
112
|
values = list(self._kwargs.values())
|
|
113
113
|
# Update the internal dict
|
|
@@ -124,7 +124,7 @@ class BaseCollection(BasedBase, MutableSequence):
|
|
|
124
124
|
|
|
125
125
|
def __getitem__(self, idx: Union[int, slice]) -> Union[V, B]:
|
|
126
126
|
"""
|
|
127
|
-
Get an item in the collection based on
|
|
127
|
+
Get an item in the collection based on its index.
|
|
128
128
|
|
|
129
129
|
:param idx: index or slice of the collection.
|
|
130
130
|
:type idx: Union[int, slice]
|
|
@@ -168,7 +168,7 @@ class BaseCollection(BasedBase, MutableSequence):
|
|
|
168
168
|
if isinstance(value, Number): # noqa: S3827
|
|
169
169
|
item = self.__getitem__(key)
|
|
170
170
|
item.value = value
|
|
171
|
-
elif issubclass(type(value), (BasedBase,
|
|
171
|
+
elif issubclass(type(value), (BasedBase, DescriptorBase)):
|
|
172
172
|
update_key = list(self._kwargs.keys())
|
|
173
173
|
values = list(self._kwargs.values())
|
|
174
174
|
old_item = values[key]
|
|
@@ -242,7 +242,7 @@ class BaseCollection(BasedBase, MutableSequence):
|
|
|
242
242
|
"""
|
|
243
243
|
Sort the collection according to the given mapping.
|
|
244
244
|
|
|
245
|
-
:param mapping: mapping function to sort the collection. i.e. lambda parameter: parameter.
|
|
245
|
+
:param mapping: mapping function to sort the collection. i.e. lambda parameter: parameter.value
|
|
246
246
|
:type mapping: Callable
|
|
247
247
|
:param reverse: Reverse the sorting.
|
|
248
248
|
:type reverse: bool
|
|
@@ -152,7 +152,6 @@ class InterfaceFactoryTemplate:
|
|
|
152
152
|
:return: binding property
|
|
153
153
|
:rtype: property
|
|
154
154
|
"""
|
|
155
|
-
import easyscience.Objects.new_variable.parameter
|
|
156
155
|
|
|
157
156
|
class_links = self.__interface_obj.create(model)
|
|
158
157
|
props = model._get_linkable_attributes()
|
|
@@ -164,12 +163,13 @@ class InterfaceFactoryTemplate:
|
|
|
164
163
|
idx = props_names.index(item_key)
|
|
165
164
|
prop = props[idx]
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
if
|
|
169
|
-
#
|
|
166
|
+
# Should be fetched this way to ensure we don't get value from callback
|
|
167
|
+
if hasattr(prop, 'value_no_call_back'):
|
|
168
|
+
# Property object
|
|
170
169
|
prop_value = prop.value_no_call_back
|
|
171
170
|
else:
|
|
172
|
-
|
|
171
|
+
# Descriptor object
|
|
172
|
+
prop_value = prop.value
|
|
173
173
|
|
|
174
174
|
prop._callback = item.make_prop(item_key)
|
|
175
175
|
prop._callback.fset(prop_value)
|
|
@@ -16,21 +16,18 @@ from typing import List
|
|
|
16
16
|
from typing import Optional
|
|
17
17
|
from typing import Set
|
|
18
18
|
from typing import TypeVar
|
|
19
|
-
from typing import Union
|
|
20
19
|
|
|
21
20
|
from easyscience import global_object
|
|
22
21
|
from easyscience.Utils.classTools import addLoggedProp
|
|
23
22
|
|
|
24
23
|
from .core import ComponentSerializer
|
|
25
|
-
from .
|
|
26
|
-
from .
|
|
27
|
-
from .Variable import Descriptor
|
|
28
|
-
from .Variable import Parameter
|
|
24
|
+
from .variable import Parameter
|
|
25
|
+
from .variable.descriptor_base import DescriptorBase
|
|
29
26
|
|
|
30
27
|
if TYPE_CHECKING:
|
|
31
28
|
from easyscience.Constraints import C
|
|
32
29
|
from easyscience.Objects.Inferface import iF
|
|
33
|
-
|
|
30
|
+
V = TypeVar('V', bound=DescriptorBase)
|
|
34
31
|
|
|
35
32
|
|
|
36
33
|
class BasedBase(ComponentSerializer):
|
|
@@ -160,8 +157,7 @@ class BasedBase(ComponentSerializer):
|
|
|
160
157
|
constraints.append(con[key])
|
|
161
158
|
return constraints
|
|
162
159
|
|
|
163
|
-
|
|
164
|
-
def get_parameters(self) -> Union[List[Parameter], List[NewParameter]]:
|
|
160
|
+
def get_parameters(self) -> List[Parameter]:
|
|
165
161
|
"""
|
|
166
162
|
Get all parameter objects as a list.
|
|
167
163
|
|
|
@@ -171,11 +167,10 @@ class BasedBase(ComponentSerializer):
|
|
|
171
167
|
for key, item in self._kwargs.items():
|
|
172
168
|
if hasattr(item, 'get_parameters'):
|
|
173
169
|
par_list = [*par_list, *item.get_parameters()]
|
|
174
|
-
elif isinstance(item, Parameter)
|
|
170
|
+
elif isinstance(item, Parameter):
|
|
175
171
|
par_list.append(item)
|
|
176
172
|
return par_list
|
|
177
173
|
|
|
178
|
-
## TODO clean when full move to new_variable
|
|
179
174
|
def _get_linkable_attributes(self) -> List[V]:
|
|
180
175
|
"""
|
|
181
176
|
Get all objects which can be linked against as a list.
|
|
@@ -186,12 +181,11 @@ class BasedBase(ComponentSerializer):
|
|
|
186
181
|
for key, item in self._kwargs.items():
|
|
187
182
|
if hasattr(item, '_get_linkable_attributes'):
|
|
188
183
|
item_list = [*item_list, *item._get_linkable_attributes()]
|
|
189
|
-
elif issubclass(type(item), (
|
|
184
|
+
elif issubclass(type(item), (DescriptorBase)):
|
|
190
185
|
item_list.append(item)
|
|
191
186
|
return item_list
|
|
192
187
|
|
|
193
|
-
|
|
194
|
-
def get_fit_parameters(self) -> Union[List[Parameter], List[NewParameter]]:
|
|
188
|
+
def get_fit_parameters(self) -> List[Parameter]:
|
|
195
189
|
"""
|
|
196
190
|
Get all objects which can be fitted (and are not fixed) as a list.
|
|
197
191
|
|
|
@@ -201,7 +195,7 @@ class BasedBase(ComponentSerializer):
|
|
|
201
195
|
for key, item in self._kwargs.items():
|
|
202
196
|
if hasattr(item, 'get_fit_parameters'):
|
|
203
197
|
fit_list = [*fit_list, *item.get_fit_parameters()]
|
|
204
|
-
elif isinstance(item, Parameter)
|
|
198
|
+
elif isinstance(item, Parameter):
|
|
205
199
|
if item.enabled and not item.fixed:
|
|
206
200
|
fit_list.append(item)
|
|
207
201
|
return fit_list
|
|
@@ -235,7 +229,6 @@ class BaseObj(BasedBase):
|
|
|
235
229
|
cheat with `BaseObj(*[Descriptor(...), Parameter(...), ...])`.
|
|
236
230
|
"""
|
|
237
231
|
|
|
238
|
-
## TODO clean when full move to new_variable
|
|
239
232
|
def __init__(
|
|
240
233
|
self,
|
|
241
234
|
name: str,
|
|
@@ -253,7 +246,7 @@ class BaseObj(BasedBase):
|
|
|
253
246
|
super(BaseObj, self).__init__(name=name, unique_name=unique_name)
|
|
254
247
|
# If Parameter or Descriptor is given as arguments...
|
|
255
248
|
for arg in args:
|
|
256
|
-
if issubclass(type(arg), (BaseObj,
|
|
249
|
+
if issubclass(type(arg), (BaseObj, DescriptorBase)):
|
|
257
250
|
kwargs[getattr(arg, 'name')] = arg
|
|
258
251
|
# Set kwargs, also useful for serialization
|
|
259
252
|
known_keys = self.__dict__.keys()
|
|
@@ -261,7 +254,7 @@ class BaseObj(BasedBase):
|
|
|
261
254
|
for key in kwargs.keys():
|
|
262
255
|
if key in known_keys:
|
|
263
256
|
raise AttributeError('Kwargs cannot overwrite class attributes in BaseObj.')
|
|
264
|
-
if issubclass(type(kwargs[key]), (BasedBase,
|
|
257
|
+
if issubclass(type(kwargs[key]), (BasedBase, DescriptorBase)) or 'BaseCollection' in [
|
|
265
258
|
c.__name__ for c in type(kwargs[key]).__bases__
|
|
266
259
|
]:
|
|
267
260
|
self._global_object.map.add_edge(self, kwargs[key])
|
|
@@ -310,7 +303,6 @@ class BaseObj(BasedBase):
|
|
|
310
303
|
test_class=BaseObj,
|
|
311
304
|
)
|
|
312
305
|
|
|
313
|
-
## TODO clean when full move to new_variable
|
|
314
306
|
def __setattr__(self, key: str, value: BV) -> None:
|
|
315
307
|
# Assume that the annotation is a ClassVar
|
|
316
308
|
old_obj = None
|
|
@@ -323,12 +315,12 @@ class BaseObj(BasedBase):
|
|
|
323
315
|
self.__class__.__annotations__[key].__args__,
|
|
324
316
|
)
|
|
325
317
|
):
|
|
326
|
-
if issubclass(type(getattr(self, key, None)), (BasedBase,
|
|
318
|
+
if issubclass(type(getattr(self, key, None)), (BasedBase, DescriptorBase)):
|
|
327
319
|
old_obj = self.__getattribute__(key)
|
|
328
320
|
self._global_object.map.prune_vertex_from_edge(self, old_obj)
|
|
329
321
|
self._add_component(key, value)
|
|
330
322
|
else:
|
|
331
|
-
if hasattr(self, key) and issubclass(type(value), (BasedBase,
|
|
323
|
+
if hasattr(self, key) and issubclass(type(value), (BasedBase, DescriptorBase)):
|
|
332
324
|
old_obj = self.__getattribute__(key)
|
|
333
325
|
self._global_object.map.prune_vertex_from_edge(self, old_obj)
|
|
334
326
|
self._global_object.map.add_edge(self, value)
|
|
@@ -352,8 +344,8 @@ class BaseObj(BasedBase):
|
|
|
352
344
|
@staticmethod
|
|
353
345
|
def __setter(key: str) -> Callable[[BV], None]:
|
|
354
346
|
def setter(obj: BV, value: float) -> None:
|
|
355
|
-
if issubclass(obj._kwargs[key].__class__, (
|
|
356
|
-
value.__class__, (
|
|
347
|
+
if issubclass(obj._kwargs[key].__class__, (DescriptorBase)) and not issubclass(
|
|
348
|
+
value.__class__, (DescriptorBase)
|
|
357
349
|
):
|
|
358
350
|
obj._kwargs[key].value = value
|
|
359
351
|
else:
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
from .descriptor_any_type import DescriptorAnyType
|
|
2
|
+
from .descriptor_array import DescriptorArray
|
|
1
3
|
from .descriptor_bool import DescriptorBool
|
|
2
4
|
from .descriptor_number import DescriptorNumber
|
|
3
5
|
from .descriptor_str import DescriptorStr
|
|
4
6
|
from .parameter import Parameter
|
|
5
7
|
|
|
6
8
|
__all__ = [
|
|
9
|
+
DescriptorAnyType,
|
|
10
|
+
DescriptorArray,
|
|
7
11
|
DescriptorBool,
|
|
8
12
|
DescriptorNumber,
|
|
9
13
|
DescriptorStr,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import numbers
|
|
4
|
+
from typing import Any
|
|
5
|
+
from typing import Dict
|
|
6
|
+
from typing import List
|
|
7
|
+
from typing import Optional
|
|
8
|
+
from typing import Union
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from easyscience.global_object.undo_redo import property_stack_deco
|
|
13
|
+
|
|
14
|
+
from .descriptor_base import DescriptorBase
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DescriptorAnyType(DescriptorBase):
|
|
18
|
+
"""
|
|
19
|
+
A `Descriptor` for any type that does not fit the other Descriptors. Should be avoided when possible.
|
|
20
|
+
It was created to hold the symmetry operations used in the SpaceGroup class of EasyCrystallography.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
name: str,
|
|
26
|
+
value: Any,
|
|
27
|
+
unique_name: Optional[str] = None,
|
|
28
|
+
description: Optional[str] = None,
|
|
29
|
+
url: Optional[str] = None,
|
|
30
|
+
display_name: Optional[str] = None,
|
|
31
|
+
parent: Optional[Any] = None,
|
|
32
|
+
):
|
|
33
|
+
"""Constructor for the DescriptorAnyType class
|
|
34
|
+
|
|
35
|
+
param name: Name of the descriptor
|
|
36
|
+
param value: Value of the descriptor
|
|
37
|
+
param description: Description of the descriptor
|
|
38
|
+
param url: URL of the descriptor
|
|
39
|
+
param display_name: Display name of the descriptor
|
|
40
|
+
param parent: Parent of the descriptor
|
|
41
|
+
.. note:: Undo/Redo functionality is implemented for the attributes `variance`, `error`, `unit` and `value`.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
self._value=value
|
|
45
|
+
|
|
46
|
+
super().__init__(
|
|
47
|
+
name=name,
|
|
48
|
+
unique_name=unique_name,
|
|
49
|
+
description=description,
|
|
50
|
+
url=url,
|
|
51
|
+
display_name=display_name,
|
|
52
|
+
parent=parent,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def value(self) -> numbers.Number:
|
|
57
|
+
"""
|
|
58
|
+
Get the value.
|
|
59
|
+
|
|
60
|
+
:return: Value of self.
|
|
61
|
+
"""
|
|
62
|
+
return self._value
|
|
63
|
+
|
|
64
|
+
@value.setter
|
|
65
|
+
@property_stack_deco
|
|
66
|
+
def value(self, value: Union[list, np.ndarray]) -> None:
|
|
67
|
+
"""
|
|
68
|
+
Set the value of self.
|
|
69
|
+
|
|
70
|
+
:param value: New value for the DescriptorAnyType.
|
|
71
|
+
"""
|
|
72
|
+
self._value = value
|
|
73
|
+
|
|
74
|
+
def __copy__(self) -> DescriptorAnyType:
|
|
75
|
+
return super().__copy__()
|
|
76
|
+
|
|
77
|
+
def __repr__(self) -> str:
|
|
78
|
+
"""
|
|
79
|
+
Return a string representation of the DescriptorAnyType, showing its name and value.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
if hasattr(self._value, '__repr__'):
|
|
83
|
+
value_repr = repr(self._value)
|
|
84
|
+
else:
|
|
85
|
+
value_repr = type(self._value)
|
|
86
|
+
|
|
87
|
+
return f"<{self.__class__.__name__} '{self._name}': {value_repr}>"
|
|
88
|
+
|
|
89
|
+
def as_dict(self, skip: Optional[List[str]] = None) -> Dict[str, Any]:
|
|
90
|
+
raw_dict = super().as_dict(skip=skip)
|
|
91
|
+
raw_dict['value'] = self._value
|
|
92
|
+
return raw_dict
|
|
93
|
+
|