# Using Pycharm with cnvrg

Pycharm is a very powerful IDE that many data scientists love to work with. Luckily, cnvrg is designed to be incredibly flexible, so you can very easily leverage all of cnvrg's powerful ML tracking and monitoring tools right from within Pycharm.

This tutorial will explain how to get set up with cnvrg and Pycharm as well as present some example code.

# Prerequisites

# Connect to a cnvrg Project using the CLI

For you to be able to communicate from Pycharm to cnvrg, you will need to ensure the code you are working on is stored in directory that is linked with a cnvrg project. You can either create a fresh cnvrg project or clone from an existing one.

# Fresh cnvrg project

To create a new cnvrg project based on a directory in your local machine, run the link command in the parent directory that will serve as the basis for your new cnvrg project:

$ cnvrg link

This will create a new project inside cnvrg with the same name as the folder you ran it in. To optionally sync and upload your existing local files to cnvrg, use the sync command:

$ cnvrg sync

The folder will be linked to cnvrg and ready to be used with the SDK.

# Existing cnvrg project (not git)

To clone to your local machine an existing cnvrg project, use the clone command:

$ cnvrg clone 'project_url'

This will create a new directory with all of your project's files, ready to be used with the python SDK.

# Existing cnvrg project (git)

To connect your local copy of your git repository with a cnvrg project that is also connected to git, use the link_git command inside the git repository's folder:

$ cnvrg link_git 'project_url`

The folder will be linked to cnvrg and ready to be used with the SDK.

# Start Using the SDK

Now that you have connected your development directory to cnvrg, you can use all of the cnvrg SDK methods from within your code that you are developing in Pycharm. Open up your linked folder in Pycharm and you will be good to go!

If you're familiar with the SDK, feel free to start developing, otherwise, the rest of this tutorial will explain more specifically how to use the SDK in conjunction with Pycharm more precisely.


Remember to import the cnvrg packages you want to use at the top of your file!

# Running Your Code as a cnvrg Experiment

To run your code as a cnvrg experiment, use the SDK method Experiment.run. The simplest way to accomplish this, is by using the Experiment.run method to call the rest of your code. This could be by calling main or any other function of your choice:

if __name__ == '__main__':
	e = Experiment.run(main, title="name_of_experiment")

When you click the play button in Pycharm (or execute the code in general), it will run the code you call locally, while also tracking it with the full suite of cnvrg's tracking features including saving of logs produced by your code.

# Custom Tracking and Visualizing

You can also use the cnvrg SDK to add and track custom graphs, visualizations and tags. Your code can access the current cnvrg Experiment object by simply using the following line:

e = Experiment()

When your experiment is running, your code can always find the Experiment object as above without handling it manually between functions and modules.

Now, use any of the cnrvg SDK methods to track your experiment:

            Ys=[0.1, 0.2, 0.3],
e.log_param("tag_key", "tag_value")
e.log("Experiment log")

The documentation on how to use the SDK's methods can be found here.

# Experiment Artifacts

By default, when the experiment finishes, any artifacts produced by your code will by synced to cnvrg. You can change this behavior by adding the sync_after parameter to Experiment.run() and setting it as false. Then you can sync specific artifacts using the log_artifacts() method:

e = Experiment.run(main, title='custom artifacts', sync_after=false)


e = Experiment()
e.log_artifacts(["output1.h5", "output2.h5"])

# Running the Experiment on Remote Compute

When you are ready to run your experiment on any remote compute connected to cnvrg, add the compute parameter to Experiment.run():

e = Experiment.run(main, title='remote experiment', compute='medium')

The code will be synced with cnvrg, and the experiment will start running on the remote compute that you indicated. There are many options for customizing the experiment with the different parameters of the Experiment.run() method, all of which can be found here.

# Summary

It is extremely easy to use cnvrg in conjunction with Pycharm. Just make sure you follow these simple guidelines:

  • Link your local development directory to cnvrg.
  • Use e = Experiment.run() to call the code you are executing.
  • Access the Experiment() object and then call the cnvrg SDK methods to add any additional tracking.
  • Run your code on remote compute by using the compute flag.
Last Updated: 6/11/2020, 6:51:13 AM