Skip to content

Commit

Permalink
Sped up compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
willgebhardt committed Jul 15, 2024
1 parent b0d91b1 commit 087706e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ngcsimlib/compilers/command_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def compiled(compartment_values, **kwargs):
critical(f"Missing keyword argument \"{n}\" in compiled function."
f"\tExpected keyword arguments {needed_args}")

for exc, outs, name in exc_order:
_comps = {key: compartment_values[key] for key in needed_comps}
for exc, outs, name, comp_ids in exc_order:
_comps = {key: compartment_values[key] for key in comp_ids}
vals = exc(**kwargs, **_comps)
if len(outs) == 1:
compartment_values[outs[0]] = vals
Expand Down
6 changes: 4 additions & 2 deletions ngcsimlib/compilers/component_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ def compile(component, resolver):

funParams = {narg: component.__dict__[narg] for narg in params}

comp_key_key = [(narg.split('/')[-1], narg) for narg in comp_ids]

def compiled(**kwargs):
funArgs = {narg: kwargs.get(narg) for narg in _args}
funComps = {narg.split('/')[-1]: kwargs.get(narg) for narg in comp_ids}
funComps = {knarg: kwargs.get(narg) for knarg, narg in comp_key_key}

return pure_fn.__func__(**funParams, **funArgs, **funComps)

exc_order.append((compiled, out_ids, component.name))
exc_order.append((compiled, out_ids, component.name, comp_ids))
return exc_order
9 changes: 7 additions & 2 deletions ngcsimlib/compilers/op_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ def compile(op):
else:
iids.append(str(s.path))

additional_idds = []
for _, _, _, _iids in exc_order:
additional_idds.extend(_iids)

# print(additional_idds)
def _op_compiled(**kwargs):
computed_values = [cmd(**kwargs) for cmd, _, _ in exc_order]
computed_values = [cmd(**kwargs) for cmd, _, _, _ in exc_order]
compartment_args = [kwargs.get(narg) for narg in iids]

_val_loc = 0
Expand All @@ -103,4 +108,4 @@ def _op_compiled(**kwargs):

return op.operation(*_args)

return (_op_compiled, [str(output)], "op")
return (_op_compiled, [str(output)], op.__class__.__name__, iids + additional_idds)
9 changes: 8 additions & 1 deletion ngcsimlib/metaComponent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ngcsimlib.compartment import Compartment
from ngcsimlib.utils import get_current_context
from ngcsimlib.utils.help import Guides
from ngcsimlib.logger import debug
from ngcsimlib.logger import debug, warn


class MetaComponent(type):
Expand Down Expand Up @@ -82,7 +82,14 @@ def wrapped_init(self, *args, **kwargs):
else:
cls.pre_init(self, *args, **kwargs)
x._orig_init(self, *args, **kwargs)
args_count = self._orig_init.__code__.co_argcount
_kwargs = self._orig_init.__code__.co_varnames[:args_count]
for key, value in kwargs.items():
if key not in _kwargs:
debug(f"There is an extra param {key} in component constructor for {self.name}")
cls.post_init(self, *args, **kwargs)
if hasattr(self, "_setup"):
self._setup()

x.__init__ = wrapped_init

Expand Down

0 comments on commit 087706e

Please sign in to comment.