generated from ssec-jhu/base-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71c18d8
commit 785a2a8
Showing
11 changed files
with
147 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +0,0 @@ | ||
from abc import ABC, abstractmethod | ||
from pydantic import BaseModel | ||
|
||
|
||
class Adapter(ABC): | ||
class Config(BaseModel): | ||
pass | ||
|
||
def __init__(self, evolver, config: Config = None): | ||
self.config = config or self.Config() | ||
|
||
@abstractmethod | ||
def react(self): | ||
pass | ||
|
||
|
||
class NoOpAdapter(Adapter): | ||
ncalls = 0 | ||
|
||
def react(self): | ||
self.ncalls += 1 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from evolver.adapter.interface import Adapter | ||
|
||
|
||
class NoOpAdapter(Adapter): | ||
ncalls = 0 | ||
|
||
def react(self): | ||
self.ncalls += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pydantic | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Adapter(ABC): | ||
class Config(pydantic.BaseModel): | ||
pass | ||
|
||
def __init__(self, evolver, config: Config = None): | ||
self.config = config or self.Config() | ||
|
||
@abstractmethod | ||
def react(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +0,0 @@ | ||
from abc import ABC, abstractmethod | ||
from copy import copy | ||
from pydantic import BaseModel | ||
|
||
|
||
class VialConfigBaseModel(BaseModel): | ||
vials: list[int] | None = None | ||
|
||
|
||
class VialBaseModel(BaseModel): | ||
vial: int | ||
|
||
|
||
class BaseCalibrator(ABC): | ||
class Config(BaseModel): | ||
calibfile: str = None | ||
|
||
def __init__(self, evovler = None, config: Config = Config()): | ||
self.config = config | ||
|
||
@property | ||
@abstractmethod | ||
def status(self): | ||
pass | ||
|
||
|
||
class NoOpCalibrator(BaseCalibrator): | ||
@property | ||
def status(self): | ||
return True | ||
|
||
|
||
class HardwareDriver(ABC): | ||
class Config(BaseModel): | ||
pass | ||
calibrator = NoOpCalibrator() | ||
|
||
def __init__(self, evolver, config = None, calibrator = None): | ||
self.evolver = evolver | ||
self.reconfigure(config or self.Config()) | ||
if calibrator: | ||
self.calibrator = calibrator | ||
|
||
def reconfigure(self, config): | ||
self.config = config | ||
|
||
|
||
class VialHardwareDriver(HardwareDriver): | ||
def reconfigure(self, config): | ||
super().reconfigure(config) | ||
if config.vials is None: | ||
config.vials = self.evolver.config.vials | ||
else: | ||
if not set(config.vials).issubset(self.evolver.all_vials): | ||
raise ValueError('invalid vials found in config') | ||
|
||
|
||
class SensorDriver(VialHardwareDriver): | ||
class Config(VialConfigBaseModel): | ||
pass | ||
class Output(VialBaseModel): | ||
raw: int | ||
value: float | ||
outputs: dict[int, Output] = {} | ||
|
||
def get(self) -> list[Output]: | ||
return self.outputs | ||
|
||
@abstractmethod | ||
def read(self): | ||
pass | ||
|
||
|
||
class EffectorDriver(VialHardwareDriver): | ||
class Config(VialConfigBaseModel): | ||
pass | ||
class Input(VialBaseModel): | ||
value: float | ||
proposal: dict[int, Input] = {} | ||
committed: dict[int, Input] = {} | ||
|
||
def set(self, input: Input): | ||
self.proposal[input.vial] = input | ||
|
||
@abstractmethod | ||
def commit(self): | ||
pass | ||
|
||
|
||
class NoOpSensorDriver(SensorDriver): | ||
class Config(VialConfigBaseModel): | ||
echo_raw: int = 1 | ||
echo_val: int = 2 | ||
|
||
def read(self): | ||
self.outputs = { | ||
i: self.Output(vial=i, raw=self.config.echo_raw, value=self.config.echo_val) | ||
for i in self.config.vials | ||
} | ||
|
||
def get(self): | ||
return self.outputs | ||
|
||
|
||
class NoOpEffectorDriver(EffectorDriver): | ||
def commit(self): | ||
self.comitted = copy(self.proposal) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from copy import copy | ||
from evolver.hardware.interface import SensorDriver, EffectorDriver, VialConfigBaseModel, BaseCalibrator | ||
|
||
|
||
class NoOpSensorDriver(SensorDriver): | ||
class Config(VialConfigBaseModel): | ||
echo_raw: int = 1 | ||
echo_val: int = 2 | ||
|
||
def read(self): | ||
self.outputs = { | ||
i: self.Output(vial=i, raw=self.config.echo_raw, value=self.config.echo_val) | ||
for i in self.config.vials | ||
} | ||
|
||
def get(self): | ||
return self.outputs | ||
|
||
|
||
class NoOpEffectorDriver(EffectorDriver): | ||
def commit(self): | ||
self.comitted = copy(self.proposal) | ||
|
||
|
||
class NoOpCalibrator(BaseCalibrator): | ||
@property | ||
def status(self): | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pydantic | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class VialConfigBaseModel(pydantic.BaseModel): | ||
vials: list[int] | None = None | ||
|
||
|
||
class VialBaseModel(pydantic.BaseModel): | ||
vial: int | ||
|
||
|
||
class BaseCalibrator(ABC): | ||
class Config(pydantic.BaseModel): | ||
calibfile: str = None | ||
|
||
def __init__(self, evovler = None, config: Config = Config()): | ||
self.config = config | ||
|
||
@property | ||
@abstractmethod | ||
def status(self): | ||
pass | ||
|
||
|
||
class HardwareDriver(ABC): | ||
class Config(pydantic.BaseModel): | ||
pass | ||
calibrator = None | ||
|
||
def __init__(self, evolver, config = None, calibrator = None): | ||
self.evolver = evolver | ||
self.reconfigure(config or self.Config()) | ||
if calibrator: | ||
self.calibrator = calibrator | ||
|
||
def reconfigure(self, config): | ||
self.config = config | ||
|
||
|
||
class VialHardwareDriver(HardwareDriver): | ||
def reconfigure(self, config): | ||
super().reconfigure(config) | ||
if config.vials is None: | ||
config.vials = self.evolver.config.vials | ||
else: | ||
if not set(config.vials).issubset(self.evolver.all_vials): | ||
raise ValueError('invalid vials found in config') | ||
|
||
|
||
class SensorDriver(VialHardwareDriver): | ||
class Config(VialConfigBaseModel): | ||
pass | ||
class Output(VialBaseModel): | ||
raw: int | ||
value: float | ||
outputs: dict[int, Output] = {} | ||
|
||
def get(self) -> list[Output]: | ||
return self.outputs | ||
|
||
@abstractmethod | ||
def read(self): | ||
pass | ||
|
||
|
||
class EffectorDriver(VialHardwareDriver): | ||
class Config(VialConfigBaseModel): | ||
pass | ||
class Input(VialBaseModel): | ||
value: float | ||
proposal: dict[int, Input] = {} | ||
committed: dict[int, Input] = {} | ||
|
||
def set(self, input: Input): | ||
self.proposal[input.vial] = input | ||
|
||
@abstractmethod | ||
def commit(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters