Debugging Guild Operations in PyCharm

To debug your Guild operations in PyCharm, set one or more breakpoints in PyCharm and use guild.ipy to run the appropriate function in your code:

# train.py

def main():
    data = _load_data()    # For example, set a breakpoint in PyCharm on this line
    model = _init_model()
    model.fit(data)

if __name__ == "__main__":
    from guild import ipy as guild
    guild.run(main)

In PyCharm, create a configuration that runs the applicable script or module. In the example above, the module is train.

To debug the module in a Guild run, use the configuration you created above. PyCharm will start a new Python session using the specified main module. The module uses the Guild Python API to run the main function.

You may want to parameterize the use of Guild to run the function so that it only applies under certain configuration. Use either environment variables or command line arguments as needed.

Example using an environment variable:

# train.py
import os

def main():
    data = _load_data()    # Set breakpoint in PyCharm on this line
    model = _init_model()
    model.fit(data)

if __name__ == "__main__":
    if os.getenv("GUILD_RUN") == "1":
        from guild import ipy as guild
        guild.run(main)
    else:
        main()

In your PyCharm configuration, specify GUILD_RUN=1 to indicate that Guild should run main.