You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way default logging object works, and the way get_default_rng in #2021 2021, reminds me of the API of Pennylane, a Python library for quantum machine learning.
If you define this decorator
# Decorator to inject 'self' into functionsdefinject_self(func):
@wraps(func)defwrapper(self, *args, **kwargs):
# Inspect the local variables of the functionlocal_vars=inspect.currentframe().f_back.f_locals# Find all callables in the scope of the functionfunctions= {k: vfork, vinlocal_vars.items() ifcallable(v)}
# Wrap each function so it accepts 'self'forname, functioninfunctions.items():
local_vars[name] =partial(function, self)
# Call the original functionreturnfunc(self, *args, **kwargs)
returnwrapper
It allows you to do this in a model step (note: I just tried, I didn't even have to modify the source code of the method do in AgentSet. I just need to move it up to be a global function)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The way default
logging
object works, and the wayget_default_rng
in #2021 2021, reminds me of the API of Pennylane, a Python library for quantum machine learning.If you define this decorator
It allows you to do this in a model step (note: I just tried, I didn't even have to modify the source code of the method do in AgentSet. I just need to move it up to be a global function)
This is similar to Solara
@solara.component
injector works, in that it injects parent context into the child subcomponents.You could possibly go further, and specify your model in a way similar to AgentPy, but briefer (cc: @jofmi)
If there is a consensus that this is worth experimenting, I could build it and have it in
mesa.experimental
.For reference, here is how a quantum circuit is specified in Pennylane:
where each of the function calls is injected with the
@qml.qnode
's arguments.Beta Was this translation helpful? Give feedback.
All reactions