Skip to content
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

Release v0.1.0 #6

Merged
merged 15 commits into from
Oct 28, 2024
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion engforge.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: engforge
Version: 0.0.9
Version: 0.1.0
Summary: The Engineer's Framework
Home-page: https://github.com/SoundsSerious/engforge
Author: Kevin russell
Expand Down
4 changes: 3 additions & 1 deletion engforge/_testing_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ def calculate_production(self, parent, term):

@forge
class FanSystem(System, CostModel):
base = Slot.define(Component)
base = Slot.define(
Component
) # FIXME: not showing in "econ" (due to base default cost?)
fan = Slot.define(Fan)
motor = Slot.define(Motor)

Expand Down
3 changes: 3 additions & 0 deletions engforge/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,14 @@ def define(cls, **kwargs):
def _setup_cls(cls, name, new_dict, **kwargs):
# randomize name for specifics reasons
uid = str(uuid.uuid4())
# base info
name = name + "_" + uid.replace("-", "")[0:16]
new_dict["uuid"] = uid
new_dict["default_options"] = cls.default_options.copy()
new_dict["template_class"] = False
new_dict["name"] = name

# create a new type of attribute
new_slot = type(name, (cls,), new_dict)
new_slot.default_options["default"] = new_slot.make_factory()
new_slot.default_options["validator"] = new_slot.configure_instance
Expand Down
15 changes: 11 additions & 4 deletions engforge/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,22 @@ def property_changed(instance, variable, value):
# elif session:
# notify session that this variable has changed
# log.info(f'property changed {variable.name} {value}')

# TODO: notify change input system here, perhaps with & without a session
# session.change_sys_var(variable,value,doset=False)

attrs = attr.fields(instance.__class__) # check identity of variable
cur = getattr(instance, variable.name)
is_different = value != cur
is_different = value != cur if isinstance(value, (int, float, str)) else True
is_var = variable in attrs
chgnw = instance._anything_changed

if log.log_level <= 6:
log.debug(
f"checking property changed {instance}{variable.name} {value}|invar: {is_var}| nteqval: {is_different}"
)
print(
f"checking property changed {instance}{variable.name} {value}|invar: {is_var}| nteqval: {is_different}"
)

# Check if should be updated
if not chgnw and is_var and is_different:
Expand Down Expand Up @@ -317,6 +320,7 @@ def signals_slots_handler(
cls_properties = cls.system_properties_classdef(True)
else:
cls_properties = {}

cls_dict = cls.__dict__.copy()
cls.__anony_store = {}
# print(f'tab found!! {cls_properties.keys()}')
Expand Down Expand Up @@ -460,6 +464,7 @@ def copy_config_at_state(
new_sys.system_references(recache=True)

# update the parents
# TODO: use pyee to broadcast change
if hasattr(self, "parent"):
if self.parent in changed:
new_sys.parent = changed[self.parent]
Expand All @@ -481,6 +486,8 @@ def go_through_configurations(
:return: level,config"""
from engforge.configuration import Configuration

# TODO: instead of a recursive loop a global map per problem context should be used, with a static map of slots, updating with every change per note in system_references. This function could be a part of that but each system shouldn't be responsible for it.

should_yield_level = lambda level: all(
[
level >= parent_level,
Expand Down Expand Up @@ -546,9 +553,9 @@ def __attrs_post_init__(self):
# TODO: allow multiple parents
if (hasattr(comp, "parent")) and (comp.parent is not None):
self.warning(
f"Component {compnm} already has a parent {comp.parent} copying, and assigning to {self}"
f"Component {compnm} already has a parent {comp.parent} #copying, and assigning to {self}"
)
setattr(self, compnm, attrs.evolve(comp, parent=self))
# setattr(self, compnm, attrs.evolve(comp, parent=self))
else:
comp.parent = self

Expand Down
13 changes: 7 additions & 6 deletions engforge/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class DataFrameLog(LoggingMixin):
# Dataframe interrogation functions
def is_uniform(s: pandas.Series):
a = s.to_numpy() # s.values (pandas<0.24)
if (a[0] == a).all():

if numpy.all(a == a[0]):
return True
try:
#
if not numpy.isfinite(a).any():
return True
except:
Expand Down Expand Up @@ -107,8 +109,8 @@ def split_dataframe(df: pandas.DataFrame) -> tuple:
class DataframeMixin:
dataframe: pandas.DataFrame

_split_dataframe_func = split_dataframe
_determine_split_func = determine_split
_split_dataframe_func = staticmethod(split_dataframe)
_determine_split_func = staticmethod(determine_split)

def smart_split_dataframe(self, df=None, split_groups=0, key_f=key_func):
"""splits dataframe between constant values and variants"""
Expand Down Expand Up @@ -166,9 +168,8 @@ def dataframe_variants(self):
return o

def format_columns(self, dataframe: pandas.DataFrame):
dataframe.rename(
lambda x: x.replace(".", "_").lower(), axis="columns", inplace=True
)
# replace(".", "_")
dataframe.rename(lambda x: x.lower(), axis="columns", inplace=True)

# Plotting Interface
@property
Expand Down
26 changes: 21 additions & 5 deletions engforge/datastores/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,40 @@ class DiskCacheStore(LoggingMixin, metaclass=SingletonMeta):
_current_keys = None
expire_threshold = 60.0

retries = 3
retries = 1
sleep_time = 0.1

def __init__(self, **kwargs):
proj_dir: str = None # avoid using implicit determinination
cache_path: str = None # override for implicit path, a recommended practice

def __init__(self, root_path=None, **kwargs):
if root_path is not None:
self.cache_path = root_path

if kwargs:
self.cache_init_kwargs = kwargs
else:
self.cache_init_kwargs = {}
self.info(f"Created DiskCacheStore In {self.cache_root}")
self.cache

@property
def proj_root(self):
if self.proj_dir is not None:
return self.proj_dir
return client_path(skip_wsl=False)

@property
def cache_root(self):
# TODO: CHECK CACHE IS NOT SYNCED TO DROPBOX
if self.cache_path is not None:
return self.cache_path

if self.alt_path is not None:
return os.path.join(client_path(skip_wsl=False), "cache", self.alt_path)
return os.path.join(self.proj_root, "cache", self.alt_path)

return os.path.join(
client_path(skip_wsl=False),
self.proj_root,
"cache",
"{}".format(type(self).__name__).lower(),
)
Expand Down Expand Up @@ -247,7 +263,7 @@ def set(self, key=None, data=None, retry=True, ttl=None, **kwargs):
time.sleep(self.sleep_time * (self.retries - ttl))
return self.set(key=key, data=data, retry=True, ttl=ttl)
else:
self.error(e, "Issue Getting Item From Cache")
self.error(e, "Issue Setting Item In Cache")

# @ray_cache
def get(self, key=None, on_missing=None, retry=True, ttl=None):
Expand Down
2 changes: 1 addition & 1 deletion engforge/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def remap_indexes_to(self, new_index, *args, invert=False, old_data=None):
old_data = self.data
opt1 = {arg: self.indify(old_data, arg)[0] for arg in args}
opt2 = {
arg: self.indify(old_data, val)[0] if (not isinstance(val, str)) else val
arg: (self.indify(old_data, val)[0] if (not isinstance(val, str)) else val)
for arg, val in opt1.items()
}
oop1 = {arg: self.indify(new_index, val)[0] for arg, val in opt2.items()}
Expand Down
Loading
Loading