Skip to content

New job #5

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

Merged
merged 18 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/easyscience/Datasets/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,13 @@ def postcompute_func(self, new_computational_fn: Callable):

def fit_prep(self, func_in: Callable, bdims=None, dask_chunks=None) -> Tuple[xr.DataArray, Callable]:
"""
Generate boradcasted coordinates for fitting and reform the fitting function into one which can handle xarrays
Generate broadcasted coordinates for fitting and reform the fitting function into one which can handle xarrays.

:param func_in: Function to be wrapped and made xarray fitting compatable.
:param func_in: Function to be wrapped and made xarray fitting compatible.
:type func_in: Callable
:param bdims: Optional precomputed broadcasted dimensions.
:type bdims: xarray.DataArray
:param dask_chunks: How to split to broadcasted dimensions for dask.
:param dask_chunks: How to split the broadcasted dimensions for dask.
:type dask_chunks: Tuple[int..]
:return: Tuple of broadcasted fit arrays and wrapped fit function.
:rtype: xarray.DataArray, Callable
Expand Down
21 changes: 0 additions & 21 deletions src/easyscience/Objects/Job/Analysis.py

This file was deleted.

64 changes: 64 additions & 0 deletions src/easyscience/Objects/job/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SPDX-FileCopyrightText: 2023 EasyScience contributors <core@easyscience.software>
# SPDX-License-Identifier: BSD-3-Clause
# © 2021-2023 Contributors to the EasyScience project <https://github.com/easyScience/EasyScience
from abc import ABCMeta
from abc import abstractmethod
from typing import Union

import numpy as np

from easyscience.Datasets.xarray import xr # type: ignore
from easyscience.fitting.minimizers import MinimizerBase
from easyscience.Objects.ObjectClasses import BaseObj


class AnalysisBase(BaseObj, metaclass=ABCMeta):
"""
This virtual class allows for the creation of technique-specific Analysis objects.
"""
def __init__(self, name: str, interface=None, *args, **kwargs):
super(AnalysisBase, self).__init__(name, *args, **kwargs)
self.name = name
self._calculator = None
self._minimizer = None
self._fitter = None
self.interface = interface

@abstractmethod
def calculate_theory(self,
x: Union[xr.DataArray, np.ndarray],
**kwargs) -> np.ndarray:
raise NotImplementedError("calculate_theory not implemented")

@abstractmethod
def fit(self,
x: Union[xr.DataArray, np.ndarray],
y: Union[xr.DataArray, np.ndarray],
e: Union[xr.DataArray, np.ndarray],
**kwargs) -> None:
raise NotImplementedError("fit not implemented")

@property
def calculator(self) -> str:
if self._calculator is None:
self._calculator = self.interface.current_interface_name
return self._calculator

@calculator.setter
def calculator(self, value) -> None:
# TODO: check if the calculator is available for the given JobType
self.interface.switch(value, fitter=self._fitter)

@property
def minimizer(self) -> MinimizerBase:
return self._minimizer

@minimizer.setter
def minimizer(self, minimizer: MinimizerBase) -> None:
self._minimizer = minimizer

# required dunder methods
def __str__(self):
return f"Analysis: {self.name}"


Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from abc import ABCMeta
from abc import abstractmethod

from easyscience.Objects.Job.Analysis import AnalysisBase
from easyscience.Objects.Job.Experiment import ExperimentBase
from easyscience.Objects.Job.Theory import TheoryBase
from easyscience.Objects.job.analysis import AnalysisBase
from easyscience.Objects.job.experiment import ExperimentBase
from easyscience.Objects.job.theoreticalmodel import TheoreticalModelBase
from easyscience.Objects.ObjectClasses import BaseObj


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

@theory.setter
@theorerical_model.setter
@abstractmethod
def theory(self, theory: TheoryBase):
def theoretical_model(self, theory: TheoreticalModelBase):
raise NotImplementedError("theory setter not implemented")

@property
Expand Down Expand Up @@ -77,10 +77,8 @@ def analysis(self, analysis: AnalysisBase):
@abstractmethod
def calculate_theory(self, *args, **kwargs):
raise NotImplementedError("calculate_theory not implemented")
#pass

@abstractmethod
def fit(self, *args, **kwargs):
raise NotImplementedError("fit not implemented")
#pass

Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
from easyscience.Objects.ObjectClasses import BaseObj


class TheoryBase(BaseObj):
class TheoreticalModelBase(BaseObj):
"""
This virtual class allows for the creation of technique-specific Theory objects.
"""
def __init__(self, name: str, *args, **kwargs):
self._name = name
super(TheoryBase, self).__init__(name, *args, **kwargs)
super().__init__(name, *args, **kwargs)

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

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

Loading