Skip to content

Latest commit

 

History

History
144 lines (76 loc) · 5.8 KB

readme.md

File metadata and controls

144 lines (76 loc) · 5.8 KB

Local Development & Docker Integration with Pycharm

This document contains information regarding ways to use Lean’s Docker image in conjunction with local development in Pycharm.


Getting Setup

Before anything we need to ensure a few things have been done:

  1. Get Pycharm Professional**

  2. Get Docker:

    • Follow the instructions for your Operating System
    • New to Docker? Try docker getting-started
  3. Pull Lean’s latest image from a terminal

    • docker pull quantconnect/lean
  4. Get Lean into Pycharm

**PyCharm’s remote debugger requires PyCharm Professional.


Develop Algorithms Locally, Run in Container

We have set up a relatively easy way to develop algorithms in your local IDE and push them into the container to be run and debugged.

Before we can use this method with Windows or Mac OS we need to share the Lean directory with Docker.


Activate File Sharing for Docker:

  • Windows:

  • Mac:

  • Linux:

    • (No setup required)

Lean Configuration

Next we need to be sure that our Lean configuration at .\Launcher\config.json is properly set. Just like running lean locally the config must reflect what we want Lean to run.

You configuration file should look something like this:

Python:

"algorithm-type-name": "**AlgorithmName**",

"algorithm-language": "Python",

"algorithm-location": "../../../Algorithm.Python/**AlgorithmName**.py",

Note About Python Algorithm Location

Our specific configuration binds the Algorithm.Python directory to the container by default so any algorithm you would like to run should be in that directory. Please ensure your algorithm location looks just the same as the example above. If you want to use a different location refer to the section bellow on setting that argument for the container and make sure your config.json also reflects this.


Running Lean in the Container

This section will cover how to actually launch Lean in the container with your desired configuration.

From a terminal; Pycharm has a built in terminal on the bottom taskbar labeled Terminal; launch the run_docker.bat/.sh script; there are a few choices on how to launch this:

  1. Launch with no parameters and answer the questions regarding configuration (Press enter for defaults)

    *   Enter docker image [default: quantconnect/lean:latest]:
    *   Enter absolute path to Lean config file [default: _~currentDir_\Launcher\config.json]:
    *   Enter absolute path to Data folder [default: ~_currentDir_\Data\]:
    *   Enter absolute path to store results [default: ~_currentDir_\]:
    *   Would you like to debug C#? (Requires mono debugger attachment) [default: N]:
    
  2. Using the run_docker.cfg to store args for repeated use; any blank entries will resort to default values! example: ./run_docker.bat run_docker.cfg

    IMAGE=quantconnect/lean:latest
    CONFIG_FILE=
    DATA_DIR=
    RESULTS_DIR=
    DEBUGGING=
    PYTHON_DIR=
    
  3. Inline arguments; anything you don't enter will use the default args! example: ./run_docker.bat DEBUGGING=y

    • Accepted args for inline include all listed in the file in #2; must follow the key=value format

Debugging Python

Debugging your Python algorithms requires an extra step within your configuration and inside of PyCharm. Thankfully we were able to configure the PyCharm launch configurations to take care of most of the work for you!


Modifying the Configuration

First in order to debug a Python algorithm in Pycharm we must make the following change to our configuration (Launcher\config.json) under the comment debugging configuration:

"debugging": true,
"debugging-method": "PyCharm",

In setting this we are telling Lean to reach out and create a debugger connection using PyCharm’s PyDevd debugger server. Once this is set Lean will always attempt to connect to a debugger server on launch. If you are no longer debugging set “debugging” to false.


Using PyCharm Launch Options

Now that Lean is configured for the debugger we can make use of the programmed launch options to connect.

Container (Recommended)

To debug inside of the container we must first start the debugger server in Pycharm, to do this use the drop down configuration “Debug in Container” and launch the debugger. Be sure to set some breakpoints in your algorithms!

Then we will need to launch the container, follow the steps described in the section “Running Lean in the Container”. After launching the container the debugging configuration will take effect and it will connect to the debug server where you can begin debugging your algorithm.

Local

To debug locally we must run the program locally. First, just as the container setup, start the PyCharm debugger server by running the “Debug Local” configuration.

Then start the program locally by whatever means you typically use, such as Mono, directly running the program at QuantConnect.Lean.Launcher.exe, etc. Once the program is running it will make the connection to your PyCharm debugger server where you can begin debugging your algorithm.