How to get graph runtime in csp.graph? #489
-
Thank you for open-sourcing this excellent package. I want to ask what's the best practice for getting graph runtime in csp.graph? csp.engine_start_time() can directly return a datetime object. I want to access runtime timestamp as well. csp.times gives a csp.impl type but not datetime object. I can certainly add additional complexity to use csp.now in csp.node, but that won't be as convenient. Appreciate any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If I understand your question correctly, you would like to access the current time that the graph is executing at each cycle. To do this, you would use Here's a basic example: import csp
from datetime import datetime, timedelta
@csp.graph
def print_runtimes():
x = csp.timer(timedelta(seconds=1), value=42.0)
csp.print('val', csp.times(x))
csp.run(print_runtimes, starttime=datetime.utcnow(), endtime=timedelta(seconds=5), realtime=True) Gives:
|
Beta Was this translation helpful? Give feedback.
Ok, I see what your issue is. In
csp
(and a lot of other computation graph libraries) there is a key distinction between wiring time (graph-time) and runtime (node-time).Any code under
csp.graph
is graph-time code: this means that there are no values available yet, all that you are doing is describing your computation. This amounts to wiring the graph together, so when you callcsp.times(...)
in the graph it returns to you anEdge
object that you can connect to other nodes. This is an Edge of datetime values, not a datetime itself. The actual datetimes will only be available at runtime.Any code under
csp.node
is node-time code: the values accessed as inputs to a node and returned from a…