Euler#
This is a toy example that proves Eulerβs identity using Tango. You can use this to play with the concept of a
Step
and see how Tango runs things without getting distracted by the details of what youβre running.
Running the experiment#
If you havenβt already, clone the tango repository and then
change directories into examples/euler
.
You can then run the experiment with:
tango run euler_general.jsonnet -i complex_arithmetic -w workspace
This will leave its results in a subdirectory of workspace/runs/
corresponding to the name of the run.
The output it prints should look something like this:
Starting new run comic-heron
Server started at http://localhost:8080/run/comic-heron
[step i_times_pi] β Starting step "i_times_pi"...
[step i_times_pi] β Finished step "i_times_pi"
[step cos] β Starting step "cos"...
[step cos] β Finished step "cos"
[step sin] β Starting step "sin"...
[step sin] β Finished step "sin"
[step pow_e] β Found output for step "i_times_pi" in cache (needed by "pow_e")...
[step pow_e] β Starting step "pow_e"...
[step pow_e] β Finished step "pow_e"
[step i_times_sin] β Found output for step "sin" in cache (needed by "i_times_sin")...
[step i_times_sin] β Starting step "i_times_sin"...
[step i_times_sin] β Finished step "i_times_sin"
[step sum] β Found output for step "cos" in cache (needed by "sum")...
[step sum] β Found output for step "i_times_sin" in cache (needed by "sum")...
[step sum] β Starting step "sum"...
[step sum] β Finished step "sum"
[step sub] β Found output for step "sum" in cache (needed by "sub")...
[step sub] β Found output for step "pow_e" in cache (needed by "sub")...
[step sub] β Starting step "sub"...
[step sub] β Finished step "sub"
[step print] β Found output for step "sub" in cache (needed by "print")...
[step print] β Starting step "print"...
[step print] 0j
[step print] β Finished step "print"
β Finished run comic-heron
βββββββββββββββ³ββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Step Name β Status β Cached Result β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β cos β β succeeded β workspace/cache/CosineStep-5aes9CUTRmkz5gJ5J6JSRbJZ4qkFu4kk β
β i_times_pi β β succeeded β workspace/cache/MultiplyStep-4SRzHCCqYGs2PLeT8LeL5ukrCWGJoiae β
β i_times_sin β β succeeded β workspace/cache/MultiplyStep-2ZG7wPj9WLn5PgpYyPVHw9Qg7VM1mhwf β
β pow_e β β succeeded β workspace/cache/ExponentiateStep-1swPpNipP6HBSP5rKdNjEqbYAWNf4CdG β
β print β β succeeded β N/A β
β sin β β succeeded β workspace/cache/SineStep-5aes9CUTRmkz5gJ5J6JSRbJZ4qkFu4kk β
β sub β β succeeded β workspace/cache/SubtractionStep-4ygj1UyLk6TCVBxN7DWTCccbMa7M1C5v β
β sum β β succeeded β workspace/cache/AdditionStep-34AiXoyiPKADMUnhcBzFYd6JeMcgx4DP β
βββββββββββββββ΄ββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 8 succeeded
Use your workspace to get the cached result of a step, e.g.
>>> from tango import Workspace
>>> workspace = Workspace.from_url(...)
>>> workspace.step_result_for_run("comic-heron", "sum")
A few things are of note here:
Tango assigns a name to your run. In this case, the name is βcomic-heronβ.
In this configuration, the βprintβ step prints the output (β
0j
β). Most of the time though, you will look for the output in the output directories that are given in the table.You might notice that the βprintβ step produces no output. Thatβs because it is uncacheable, and thus writes out nothing.
Change a step#
Letβs make an update to a step! Open complex_arithmetic.py
and change AdditionStep
. The actual change you make
in the run()
method does not matter, but the important thing is to update the VERSION
member of the
AdditionStep
class. AdditionStep
does not yet have a VERSION
, so we will give it one:
@Step.register("cadd")
class AdditionStep(Step):
VERSION = "002" # This is the important change.
def run(self, a: ComplexOrTuple, b: ComplexOrTuple) -> complex: # type: ignore
return make_complex(a) + make_complex(b)
Now run the config again with
tango run euler_general.jsonnet -i complex_arithmetic -w workspace
This time, the output will look like this:
Starting new run right-amoeba
Server started at http://localhost:8080/run/right-amoeba
[step sum] β Found output for step "cos" in cache (needed by "sum")...
[step sum] β Found output for step "i_times_sin" in cache (needed by "sum")...
[step sum] β Starting step "sum"...
[step sum] β Finished step "sum"
[step sub] β Found output for step "sum" in cache (needed by "sub")...
[step sub] β Found output for step "pow_e" in cache (needed by "sub")...
[step sub] β Starting step "sub"...
[step sub] β Finished step "sub"
[step print] β Found output for step "sub" in cache (needed by "print")...
[step print] β Starting step "print"...
[step print] 0j
[step print] β Finished step "print"
β Finished run right-amoeba
βββββββββββββββ³ββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Step Name β Status β Cached Result β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β cos β - not run β workspace/cache/CosineStep-5aes9CUTRmkz5gJ5J6JSRbJZ4qkFu4kk β
β i_times_pi β - not run β workspace/cache/MultiplyStep-4SRzHCCqYGs2PLeT8LeL5ukrCWGJoiae β
β i_times_sin β - not run β workspace/cache/MultiplyStep-2ZG7wPj9WLn5PgpYyPVHw9Qg7VM1mhwf β
β pow_e β - not run β workspace/cache/ExponentiateStep-1swPpNipP6HBSP5rKdNjEqbYAWNf4CdG β
β print β β succeeded β N/A β
β sin β - not run β workspace/cache/SineStep-5aes9CUTRmkz5gJ5J6JSRbJZ4qkFu4kk β
β sub β β succeeded β workspace/cache/SubtractionStep-42mdcQBtrNAYvxYhmzdd1vj2uCG8N5Yf β
β sum β β succeeded β workspace/cache/AdditionStep-002-34AiXoyiPKADMUnhcBzFYd6JeMcgx4DP β
βββββββββββββββ΄ββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3 succeeded, 5 not run
Use your workspace to get the cached result of a step, e.g.
>>> from tango import Workspace
>>> workspace = Workspace.from_url(...)
>>> workspace.step_result_for_run("right-amoeba", "sum")
As you can see, it re-used the cached results for several of the steps, and only ran three steps anew.
tango.step.Step.VERSION
is just one of the ways in which you can change the behavior of a step. Head over to the
documentation of the tango.step.Step
class to see the others.