Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-style execution for Python-defined experiments #600

Merged
merged 17 commits into from
Oct 25, 2023

Conversation

apoorvkh
Copy link
Contributor

@apoorvkh apoorvkh commented Sep 9, 2023

Hey!

I think the Tango CLI is really nice and would really like if we could support Python-defined experiments with CLI-style execution. So I modularized the CLI run functions and decoupled them from __main__.py.

Now we can also run scripts like:

from tango import StepGraph
from tango.cli import tango_cli, execute_step_graph, prepare_workspace, prepare_executor

from examples.euler.complex_arithmetic import *
from tango.steps import PrintStep

i = [0.0, 1.0]
pi = [3.1415926535, 0.0]

i_times_pi = MultiplyStep(a=i, b=pi)
pow_e = ExponentiateStep(x=i_times_pi)
plus_one = AdditionStep(a=pow_e, b=[1,0])
print_step = PrintStep(input=plus_one)

step_graph = StepGraph({
    "i_times_pi": i_times_pi,
    "pow_e": pow_e,
    "plus_one": plus_one,
    "print": print_step
})

if __name__ == '__main__':
    with tango_cli():
        workspace = prepare_workspace()
        executor = prepare_executor(workspace)
        execute_step_graph(step_graph, workspace, executor)

This should be the same as tango run examples/euler/euler.jsonnet!

If we want to use the default TangoGlobalSettings, we can also shorten the block to

    with tango_cli():
        execute_step_graph(step_graph)

This includes the changes from (@BigRedT) Tanmay's PR #491. CLI functionality should be completely the same. I ran the tests in tests/main_test.py successfully. Formatted with isort and black and checked with ruff and mypy. Docs needed.

What do you think? Happy to make adjustments as you see fit!

@apoorvkh apoorvkh changed the title Decoupling CLI functions from __main__.py CLI-style execution for Python-defined experiments Sep 9, 2023
@apoorvkh
Copy link
Contributor Author

Seems like the lint and type check failed, but for reasons independent of this PR. Shall I resolve those anyway?

@AkshitaB AkshitaB self-assigned this Oct 11, 2023
Copy link
Contributor

@AkshitaB AkshitaB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apoorvkh Thank you for the PR! The changes look good to me.

Some of the CI tests don't run due to permissions errors, but I ran some of them locally.

@AkshitaB AkshitaB merged commit 4c8ae5a into allenai:main Oct 25, 2023
16 of 20 checks passed
@apoorvkh
Copy link
Contributor Author

That's great -- thanks a lot @AkshitaB!

@apoorvkh apoorvkh deleted the python-cli branch October 26, 2023 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants