-
Notifications
You must be signed in to change notification settings - Fork 5
Debugging ABM Python Code
Alex Bettinardi edited this page Dec 16, 2020
·
1 revision
This page describes multiple ways to interactively debug the ABM Python code.
- Setup
- Install Visual Studio Community Edition (version 2019). Make sure to install the Python development version/package.
- Open Visual Studio (initial setup might be required when opening the first time).
- Go to File + New + Project + and select Python Application (click Next). Save the project in a location for later use (Name and click Create).
- Go to View + Solution Explorer, then right click on Python Environments and select View all Python environments.
- Scroll to the bottom of the list of configured environments and click "Add Environment..." to create an environment for the ABM dependencies setup.
- Click on "Existing environment under the "Add environment" window. Choose "Custom" under the Environment drop-down menu. Under "Prefix path" browse to the "Python27" folder under the ABM "dependencies" folder on your machine. All of the remaining fields should auto populate once you browse and choose the ABM's Python27 folder. Click Add (might need to refresh the DB load by clicking the refresh arrow).
- The environment that was just added should show up in the Python Environments window as "Python27 Custom environment". Switch the drop down menu set to "Overview" to "Configure" or click "Configure or remove environment". The Change the Description to something more meaningful like "SOABM" and click Apply.
- Go to View + Solution Explorer, then right click on Python Environments and select "Add environments" and select PythonSOABM choose "Existing environment" and set "Environment" to the custom environment that was just created and named above. Click Add.
- Debugging
- Right click on the Python Project in the Solutions Explorer and select Add and then Existing Item. Browse to and select the Master_Runner.py script in order to add it to the project.
- Go to Project + Properties:
- Under General, set the working directory to the template folder (i.e. the same place as RunModel.bat) and ensure that Master_Runner.py is set as the startup script (it should appear bold in the Solution Explore window).
- Under Debug tab (still in the properties window), add a script arguments for the ABM runmode to debug. For example, type taz_initial in this setting in order to debug this step of the ABM Python program.
- Make sure to click save to save the updated project properties.
- Example
- Set a breakpoint for when you debug the program. Select a line in the source code and click on the grey area just left of the script to set a red breakpoint. The print line in the startVisum() method is a good starting point.
- Go to Debug + Start Debugging to start the program. The debugger should highlight the line with the breakpoint and print some info to the console.
- Go to Debug + Step Over to execute the next line, which is to load the version file.
- Next explore variables with the Locals Window or execute Python commands via Debug > Windows > Python Debug Interactive.
- If you need to start over, go to Debug + Stop Debugging.
- Further information on debugging Python with Visual Studio is here.
- Setup
- Install Anaconda Python to get the Spyder IDE.
- Open Spyder.
- If needed, make sure to create a Python 3.7 environment using Anaconda Navigator since ABM uses Python 3. The Python interpreter being used is set via Tools + Preferences + Python interpreter.
- Open the Master_Runner.py Python script for your scenario.
- Go to Run + Configuration Per File menu option:
- Set the working directory to the template folder (i.e. the same place as RunModel.bat).
- Add a command line option for the ABM runmode to debug. For example, type taz_initial in this setting in order to debug this step of the ABM Python program.
- Example
- Set a breakpoint for when you debug the program. Select a line in the source code to pause execution via Debug + Set/clear breakpoint (or F12). The print line in the startVisum() method is a good starting point.
- Click Debug + Debug to start the program.
- Click Debug + Continue to continue to your breakpoint. The debugger should highlight the line with the breakpoint and print some info to the console.
- Click Debug + Step return to execute the next line, which is to load the version file.
- Next explore the Variable explorer or execute Python commands via the console as needed to debug the issue.
- If you need to start over, restart the Python session via Consoles + Restart kernel.
- Further information on debugging with Spyder is here.
- Getting Started
- RunModel bat file
- Networks and Zone Data
- Auto Network Coding
- VDF Definition
- Transit Network Coding
- Non-motorized Network Coding
- Editing Land Use Data
- Running the Population Synthesizer
- Input Checker
- Analyzing Model Outputs
- Commercial Vehicle Model
- External Model
- Model Cost Inputs
- Value of Time
- Person Type Coding Logic
- MSA Feedback
- VMT Computation
- Shadow Pricing Mechanism
- Methodology for Developing TAZ Boundaries
- Methodology for Developing MAZ Boundaries
- Methodology for Developing TAPS
- Source of Land-Use Inputs
- Major University Model (Optional)
- Running Transit Everywhere Scenario
- Building the ABM Java Program
- Debugging ABM Python Code
- ABM Cleaning Protocol
- Updating to New Visum
- Troubleshooting and Debugging