Skip to content

Commit 0f372e5

Browse files
authored
Merge pull request #5 from EasyScience/new_job
New job
2 parents fd2218c + 2c07615 commit 0f372e5

File tree

7 files changed

+76
-35
lines changed

7 files changed

+76
-35
lines changed

src/easyscience/Datasets/xarray.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,13 @@ def postcompute_func(self, new_computational_fn: Callable):
612612

613613
def fit_prep(self, func_in: Callable, bdims=None, dask_chunks=None) -> Tuple[xr.DataArray, Callable]:
614614
"""
615-
Generate boradcasted coordinates for fitting and reform the fitting function into one which can handle xarrays
615+
Generate broadcasted coordinates for fitting and reform the fitting function into one which can handle xarrays.
616616
617-
:param func_in: Function to be wrapped and made xarray fitting compatable.
617+
:param func_in: Function to be wrapped and made xarray fitting compatible.
618618
:type func_in: Callable
619619
:param bdims: Optional precomputed broadcasted dimensions.
620620
:type bdims: xarray.DataArray
621-
:param dask_chunks: How to split to broadcasted dimensions for dask.
621+
:param dask_chunks: How to split the broadcasted dimensions for dask.
622622
:type dask_chunks: Tuple[int..]
623623
:return: Tuple of broadcasted fit arrays and wrapped fit function.
624624
:rtype: xarray.DataArray, Callable

src/easyscience/Objects/Job/Analysis.py

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-FileCopyrightText: 2023 EasyScience contributors <core@easyscience.software>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# © 2021-2023 Contributors to the EasyScience project <https://github.com/easyScience/EasyScience
4+
from abc import ABCMeta
5+
from abc import abstractmethod
6+
from typing import Union
7+
8+
import numpy as np
9+
10+
from easyscience.Datasets.xarray import xr # type: ignore
11+
from easyscience.fitting.minimizers import MinimizerBase
12+
from easyscience.Objects.ObjectClasses import BaseObj
13+
14+
15+
class AnalysisBase(BaseObj, metaclass=ABCMeta):
16+
"""
17+
This virtual class allows for the creation of technique-specific Analysis objects.
18+
"""
19+
def __init__(self, name: str, interface=None, *args, **kwargs):
20+
super(AnalysisBase, self).__init__(name, *args, **kwargs)
21+
self.name = name
22+
self._calculator = None
23+
self._minimizer = None
24+
self._fitter = None
25+
self.interface = interface
26+
27+
@abstractmethod
28+
def calculate_theory(self,
29+
x: Union[xr.DataArray, np.ndarray],
30+
**kwargs) -> np.ndarray:
31+
raise NotImplementedError("calculate_theory not implemented")
32+
33+
@abstractmethod
34+
def fit(self,
35+
x: Union[xr.DataArray, np.ndarray],
36+
y: Union[xr.DataArray, np.ndarray],
37+
e: Union[xr.DataArray, np.ndarray],
38+
**kwargs) -> None:
39+
raise NotImplementedError("fit not implemented")
40+
41+
@property
42+
def calculator(self) -> str:
43+
if self._calculator is None:
44+
self._calculator = self.interface.current_interface_name
45+
return self._calculator
46+
47+
@calculator.setter
48+
def calculator(self, value) -> None:
49+
# TODO: check if the calculator is available for the given JobType
50+
self.interface.switch(value, fitter=self._fitter)
51+
52+
@property
53+
def minimizer(self) -> MinimizerBase:
54+
return self._minimizer
55+
56+
@minimizer.setter
57+
def minimizer(self, minimizer: MinimizerBase) -> None:
58+
self._minimizer = minimizer
59+
60+
# required dunder methods
61+
def __str__(self):
62+
return f"Analysis: {self.name}"
63+
64+

src/easyscience/Objects/Job/Job.py renamed to src/easyscience/Objects/job/job.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from abc import ABCMeta
66
from abc import abstractmethod
77

8-
from easyscience.Objects.Job.Analysis import AnalysisBase
9-
from easyscience.Objects.Job.Experiment import ExperimentBase
10-
from easyscience.Objects.Job.Theory import TheoryBase
8+
from easyscience.Objects.job.analysis import AnalysisBase
9+
from easyscience.Objects.job.experiment import ExperimentBase
10+
from easyscience.Objects.job.theoreticalmodel import TheoreticalModelBase
1111
from easyscience.Objects.ObjectClasses import BaseObj
1212

1313

@@ -29,12 +29,12 @@ def __init__(self, name: str, *args, **kwargs):
2929
Summary and Info classes are included to store additional information.
3030
"""
3131
@property
32-
def theory(self):
32+
def theorerical_model(self):
3333
return self._theory
3434

35-
@theory.setter
35+
@theorerical_model.setter
3636
@abstractmethod
37-
def theory(self, theory: TheoryBase):
37+
def theoretical_model(self, theory: TheoreticalModelBase):
3838
raise NotImplementedError("theory setter not implemented")
3939

4040
@property
@@ -77,10 +77,8 @@ def analysis(self, analysis: AnalysisBase):
7777
@abstractmethod
7878
def calculate_theory(self, *args, **kwargs):
7979
raise NotImplementedError("calculate_theory not implemented")
80-
#pass
8180

8281
@abstractmethod
8382
def fit(self, *args, **kwargs):
8483
raise NotImplementedError("fit not implemented")
85-
#pass
8684

src/easyscience/Objects/Job/Theory.py renamed to src/easyscience/Objects/job/theoreticalmodel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
from easyscience.Objects.ObjectClasses import BaseObj
77

88

9-
class TheoryBase(BaseObj):
9+
class TheoreticalModelBase(BaseObj):
1010
"""
1111
This virtual class allows for the creation of technique-specific Theory objects.
1212
"""
1313
def __init__(self, name: str, *args, **kwargs):
1414
self._name = name
15-
super(TheoryBase, self).__init__(name, *args, **kwargs)
15+
super().__init__(name, *args, **kwargs)
1616

1717
# required dunder methods
1818
def __str__(self):
1919
raise NotImplementedError("Copy not implemented")
2020

2121
def as_dict(self, skip: list = []) -> dict:
22-
this_dict = super(TheoryBase, self).as_dict(skip=skip)
22+
this_dict = super().as_dict(skip=skip)
2323
return this_dict
2424

0 commit comments

Comments
 (0)