Skip to content

Commit 087706e

Browse files
committed
Sped up compiler
1 parent b0d91b1 commit 087706e

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

ngcsimlib/compilers/command_compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def compiled(compartment_values, **kwargs):
9292
critical(f"Missing keyword argument \"{n}\" in compiled function."
9393
f"\tExpected keyword arguments {needed_args}")
9494

95-
for exc, outs, name in exc_order:
96-
_comps = {key: compartment_values[key] for key in needed_comps}
95+
for exc, outs, name, comp_ids in exc_order:
96+
_comps = {key: compartment_values[key] for key in comp_ids}
9797
vals = exc(**kwargs, **_comps)
9898
if len(outs) == 1:
9999
compartment_values[outs[0]] = vals

ngcsimlib/compilers/component_compiler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ def compile(component, resolver):
102102

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

105+
comp_key_key = [(narg.split('/')[-1], narg) for narg in comp_ids]
106+
105107
def compiled(**kwargs):
106108
funArgs = {narg: kwargs.get(narg) for narg in _args}
107-
funComps = {narg.split('/')[-1]: kwargs.get(narg) for narg in comp_ids}
109+
funComps = {knarg: kwargs.get(narg) for knarg, narg in comp_key_key}
108110

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

111-
exc_order.append((compiled, out_ids, component.name))
113+
exc_order.append((compiled, out_ids, component.name, comp_ids))
112114
return exc_order

ngcsimlib/compilers/op_compiler.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ def compile(op):
8585
else:
8686
iids.append(str(s.path))
8787

88+
additional_idds = []
89+
for _, _, _, _iids in exc_order:
90+
additional_idds.extend(_iids)
91+
92+
# print(additional_idds)
8893
def _op_compiled(**kwargs):
89-
computed_values = [cmd(**kwargs) for cmd, _, _ in exc_order]
94+
computed_values = [cmd(**kwargs) for cmd, _, _, _ in exc_order]
9095
compartment_args = [kwargs.get(narg) for narg in iids]
9196

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

104109
return op.operation(*_args)
105110

106-
return (_op_compiled, [str(output)], "op")
111+
return (_op_compiled, [str(output)], op.__class__.__name__, iids + additional_idds)

ngcsimlib/metaComponent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ngcsimlib.compartment import Compartment
22
from ngcsimlib.utils import get_current_context
33
from ngcsimlib.utils.help import Guides
4-
from ngcsimlib.logger import debug
4+
from ngcsimlib.logger import debug, warn
55

66

77
class MetaComponent(type):
@@ -82,7 +82,14 @@ def wrapped_init(self, *args, **kwargs):
8282
else:
8383
cls.pre_init(self, *args, **kwargs)
8484
x._orig_init(self, *args, **kwargs)
85+
args_count = self._orig_init.__code__.co_argcount
86+
_kwargs = self._orig_init.__code__.co_varnames[:args_count]
87+
for key, value in kwargs.items():
88+
if key not in _kwargs:
89+
debug(f"There is an extra param {key} in component constructor for {self.name}")
8590
cls.post_init(self, *args, **kwargs)
91+
if hasattr(self, "_setup"):
92+
self._setup()
8693

8794
x.__init__ = wrapped_init
8895

0 commit comments

Comments
 (0)