{"id":47070,"date":"2026-09-14T14:46:46","date_gmt":"2026-09-14T14:46:46","guid":{"rendered":"https:\/\/imperix.com\/doc\/?p=47070"},"modified":"2026-09-14T12:00:00","modified_gmt":"2026-09-14T12:00:00","slug":"automate-parameter-sweeps-in-python","status":"publish","type":"post","link":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python","title":{"rendered":"Automated parameter sweep using Python"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 ez-toc-wrap-right-text counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Building-the-automation-sequence-in-Python\" >Building the automation sequence in Python<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Creating-a-project-and-launching-the-user-code\" >Creating a project and launching the user code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Configuring-the-Scope-module-transient-generator\" >Configuring the Scope module transient generator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Automating-the-parameter-sweep-and-acquisition\" >Automating the parameter sweep and acquisition<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#The-complete-script\" >The complete script<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Experimental-results\" >Experimental results<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\/#Going-further\" >Going further<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">This application note shows how to use Python scripting to automate actions otherwise performed manually in <a href=\"\/software\/cockpit\/\">Cockpit<\/a>. Doing so, it also introduces a recommended workflow for working with the <a href=\"https:\/\/imperix.com\/doc\/python-library\/\">imperix Python library<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This example uses Python to automate a parameter sweep for the PI controller from <a href=\"https:\/\/imperix.com\/doc\/implementation\/pi-based-current-control\">TN109<\/a>, used for the current control of a buck converter. The script iterates through a predefined table of (\\(K_{p}\\), \\(K_{i}\\)) pairs. For each pair, it updates the parameters, applies a current reference step, captures the transient response using the Scope module, and exports the resulting data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While tuning a basic PI controller is a relatively straightforward task that may not require automation, this simple use case supports recommendations and guidelines on key concepts for automating tasks using the Python API.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"535\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/sweep_snippet-1.png\" alt=\"\" class=\"wp-image-50136\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/sweep_snippet-1.png 353w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/sweep_snippet-1-198x300.png 198w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><figcaption class=\"wp-element-caption\">Automated parameter sweep executed via Python script<\/figcaption><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"373\" height=\"415\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/image-7.png\" alt=\"\" class=\"wp-image-50128\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/image-7.png 373w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/image-7-270x300.png 270w\" sizes=\"auto, (max-width: 373px) 100vw, 373px\" \/><figcaption class=\"wp-element-caption\">Comparison of step responses using Cockpit <a href=\"https:\/\/imperix.com\/doc\/help\/cockpit-user-guide?currentThread=b-box-4#snapshots\">snapshots<\/a><\/figcaption><\/figure>\n<\/div><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-warning\" role=\"alert\">Always treat automated scripts with caution and anticipate unexpected behavior during initial tests. Set up proper hardware safety limits before execution. <a href=\"https:\/\/imperix.com\/doc\/help\/over-current-and-over-voltage-protection\">PN257<\/a> provides guidelines for setting <strong>over-current and over-voltage protections<\/strong>.<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ACG SDK or CPP SDK version 2026.3 or later (<a href=\"https:\/\/imperix.com\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">download<\/a>)<\/li>\n\n\n\n<li>A Python scripting environment with the imperix library (see <a href=\"https:\/\/imperix.com\/doc\/help\/getting-started-with-python-scripting\">Getting started with Python<\/a>)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Building-the-automation-sequence-in-Python\"><\/span>Building the automation sequence in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This section divides the workflow into three parts and maps the standard manual actions in the Cockpit graphical interface to their Python API equivalents. Then, it combines these building blocks into a complete automated script.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating-a-project-and-launching-the-user-code\"><\/span>Creating a project and launching the user code<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To run the code, the model must first be built and deployed. After initiating the build (<code>Ctrl<\/code> + <code>B<\/code> in Simulink, <code>Ctrl<\/code> + <code>Alt<\/code> + <code>B<\/code> in PLECS), Cockpit opens automatically and generates a new project. Click the <em>LINK TARGET<\/em> button to view available targets. Once a target is selected, the code will execute automatically. For more detailed instructions, refer to <a href=\"https:\/\/imperix.com\/doc\/help\/programming-imperix-controllers\" target=\"_blank\" rel=\"noopener\">PN138<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are two options available to manage projects using Python:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Option 1: Connect to an existing project (recommended)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This approach connects to an active Cockpit project. First, launch the code manually by following the steps above. Then, in the Python script, retrieve the running project by referencing its name.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>from imperix import Cockpit\n\nwith Cockpit() as cockpit:\n\n    # ========================================================================\n    # Retrieve an existing Cockpit project by name\n    # ========================================================================\n    project = cockpit.projects.get(\"TN109_PI_current_control\")\n\n    if project is None:\n        raise SystemExit(\"Project not found.\")\n        \n    # ...<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">from<\/span><span style=\"color: #24292E\"> imperix <\/span><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> Cockpit<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">with<\/span><span style=\"color: #24292E\"> Cockpit() <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> cockpit:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Retrieve an existing Cockpit project by name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    project <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> cockpit.projects.get(<\/span><span style=\"color: #032F62\">&quot;TN109_PI_current_control&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> project <\/span><span style=\"color: #D73A49\">is<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">None<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">raise<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">SystemExit<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;Project not found.&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ...<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Option 2: Re-create the project programmatically<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, a new Cockpit project can be created programmatically. While slightly more complex, this method ensures a clean workspace and prevents unintentional modifications to existing projects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When using this approach, working with a standalone copy of the compiled user code (the <code>.elf<\/code> file) is recommended to avoid file conflicts. The code snippet below assumes this <code>.elf<\/code> file is located in the same directory as the Python script.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>from imperix import Cockpit\nfrom pathlib import Path\n\n# The MAC address can be copy-pasted from Cockpit Target tab.\nTARGET_MAC = \"02:BB:62:75:88:2E\"\n\n# BASE_DIR is the directory containing this script.\nBASE_DIR: Path = Path(__file__).resolve().parent\nELF_PATH: Path = BASE_DIR \/ \"TN109_PI_current_control.elf\"\n\nwith Cockpit() as cockpit:\n\n    # ============================================================================\n    # Verify that the targetted controller is available\n    # ============================================================================\n\n    cockpit.targets.refresh()\n\n    target = cockpit.targets.get(TARGET_MAC)\n\n    if target is None:\n        raise SystemExit(\"Target not found.\")\n    \n    # ========================================================================\n    # Create a Cockpit project and launch the user code\n    # ========================================================================\n\n    project = cockpit.projects.create(\n        ELF_PATH,\n        name=\"PI controller sweep\",\n        overwrite=True,\n    )\n\n    project.link_target(TARGET_MAC)\n\n    project.connect(auto_start_code=True, bypass_warnings=True)\n    \n    # ...<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">from<\/span><span style=\"color: #24292E\"> imperix <\/span><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> Cockpit<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">from<\/span><span style=\"color: #24292E\"> pathlib <\/span><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> Path<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># The MAC address can be copy-pasted from Cockpit Target tab.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">TARGET_MAC<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;02:BB:62:75:88:2E&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># BASE_DIR is the directory containing this script.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">BASE_DIR<\/span><span style=\"color: #24292E\">: Path <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> Path(<\/span><span style=\"color: #005CC5\">__file__<\/span><span style=\"color: #24292E\">).resolve().parent<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">ELF_PATH<\/span><span style=\"color: #24292E\">: Path <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">BASE_DIR<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;TN109_PI_current_control.elf&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">with<\/span><span style=\"color: #24292E\"> Cockpit() <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> cockpit:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ============================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Verify that the targetted controller is available<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ============================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    cockpit.targets.refresh()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    target <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> cockpit.targets.get(<\/span><span style=\"color: #005CC5\">TARGET_MAC<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> target <\/span><span style=\"color: #D73A49\">is<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">None<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">raise<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">SystemExit<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;Target not found.&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Create a Cockpit project and launch the user code<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ========================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    project <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> cockpit.projects.create(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #005CC5\">ELF_PATH<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;PI controller sweep&quot;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">overwrite<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">True<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    )<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    project.link_target(<\/span><span style=\"color: #005CC5\">TARGET_MAC<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    project.connect(<\/span><span style=\"color: #E36209\">auto_start_code<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">True<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #E36209\">bypass_warnings<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">True<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ...<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Configuring-the-Scope-module-transient-generator\"><\/span>Configuring the Scope module transient generator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"224\" height=\"401\" src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/07\/image-33.png\" alt=\"\" class=\"wp-image-49885\" style=\"aspect-ratio:0.5586115903785649;width:186px;height:auto\" srcset=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/07\/image-33.png 224w, https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/07\/image-33-168x300.png 168w\" sizes=\"auto, (max-width: 224px) 100vw, 224px\" \/><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"wp-block-paragraph\">To capture the transient response to a reference current step, the <a href=\"https:\/\/imperix.com\/doc\/help\/scope-module\">Scope module<\/a> is configured to acquire <code>Iout_ref<\/code> and <code>Iout_meas<\/code> and the <a href=\"https:\/\/imperix.com\/doc\/help\/scope-module?currentThread=imperix-cockpit#Transient-generator\">transient generator<\/a> is used to apply the current reference step to <code>Iout_meas<\/code>, as illustrated on the left.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code snippet below shows the recommended approach for configuring a Scope module via the Python API: delete any existing Scope module in the project and create a new one. This ensures a completely clean configuration and guarantees reproducibility. Alternatively, the Scope module can be configured manually via the GUI and then retrieved using the Python script, as detailed in the Python API <a href=\"https:\/\/imperix.com\/doc\/python-library\/api\/module.html\">modules documentation<\/a>.<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly># Applied current-reference step (in Amperes).\nINITIAL_CURRENT_REF = 3.0\nFINAL_CURRENT_REF = 5.0\n\n# ...\n\nwith Cockpit() as cockpit:\n\n    # ...\n    \n    # =========================================================================\n    # Configure the scope module\n    # =========================================================================\n    \n    # Iterate through modules and delete any existing Scope module\n    for module in project.modules.list():\n        if module.type == ModuleType.SCOPE:\n            module.delete()\n\n    # Create a new Scope module\n    scope = project.modules.create(ModuleType.SCOPE)\n    scope.add_variables(&#091;\"Iout_ref\", \"Iout_meas\"&#093;)\n    scope.set_window(window_ms=15.0)\n    scope.set_transient(\n        variable=\"Iout_ref\",\n        positions_ms=&#091;2.0&#093;,\n        values=&#091;FINAL_CURRENT_REF&#093;,\n    )\n    \n    # ...<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\"># Applied current-reference step (in Amperes).<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">INITIAL_CURRENT_REF<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">3.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">FINAL_CURRENT_REF<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">5.0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># ...<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">with<\/span><span style=\"color: #24292E\"> Cockpit() <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> cockpit:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># =========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Configure the scope module<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># =========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Iterate through modules and delete any existing Scope module<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">for<\/span><span style=\"color: #24292E\"> module <\/span><span style=\"color: #D73A49\">in<\/span><span style=\"color: #24292E\"> project.modules.list():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> module.type <\/span><span style=\"color: #D73A49\">==<\/span><span style=\"color: #24292E\"> ModuleType.<\/span><span style=\"color: #005CC5\">SCOPE<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            module.delete()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Create a new Scope module<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> project.modules.create(ModuleType.<\/span><span style=\"color: #005CC5\">SCOPE<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope.add_variables(&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #032F62\">&quot;Iout_meas&quot;<\/span><span style=\"color: #24292E\">&#093;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope.set_window(<\/span><span style=\"color: #E36209\">window_ms<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">15.0<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope.set_transient(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">variable<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">positions_ms<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">&#091;<\/span><span style=\"color: #005CC5\">2.0<\/span><span style=\"color: #24292E\">&#093;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">values<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">&#091;<\/span><span style=\"color: #005CC5\">FINAL_CURRENT_REF<\/span><span style=\"color: #24292E\">&#093;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ...<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Automating-the-parameter-sweep-and-acquisition\"><\/span>Automating the parameter sweep and acquisition<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The following steps define the sequence for acquiring the current step response.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Enable the PWM outputs.<\/li>\n\n\n\n<li>Initialize the current reference (<code>Iout_ref<\/code>) to 3 A.<\/li>\n\n\n\n<li>For each <code>Kp<\/code> and <code>Ki<\/code> par:\n<ol class=\"wp-block-list\">\n<li>Change <code>Kp<\/code> and <code>Ki<\/code> values.<\/li>\n\n\n\n<li>Trigger &#8220;Fire transient&#8221; to apply the configured reference step and acquire the resulting data.<\/li>\n\n\n\n<li>(Optional) Click on the camera icon to take a snapshot of acquired data. Curves from different snapshots can be compared directly within Cockpit to evaluate results across different <code>Kp<\/code> and <code>Ki<\/code> values (see <a href=\"https:\/\/imperix.com\/doc\/help\/cockpit-user-guide#snapshots\">PN300<\/a>).<\/li>\n\n\n\n<li>Export the acquired plot data as a MAT file.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"790\" style=\"aspect-ratio: 1112 \/ 790;\" width=\"1112\" controls src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/07\/Python_manual_sweep.mp4\"><\/video><figcaption class=\"wp-element-caption\">Acquisition of current step responses in Cockpit for multiple Kp and Ki pairs<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The Python code required to automate these steps is shown below:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly># ...\n\n# The (Kp, Ki) pairs used in the sweep\nGAIN_PAIRS = &#091;\n    (1.0, 100.0),\n    (2.0, 200.0),\n    (3.0, 300.0),\n    # To be completed...\n&#093;\n\n# BASE_DIR is the directory containing this script\nBASE_DIR: Path = Path(__file__).resolve().parent\nOUTPUT_DIR: Path = BASE_DIR \/ \"output\"\nOUTPUT_DIR.mkdir(exist_ok=True)\n\n# ...\n\nwith Cockpit() as cockpit:\n\n    # ...\n    \n    # If an operation within 'try' fails, jumps to the 'finally' block. Used to\n    # safely power down the converter before the script exits due to an error.\n    try:\n\n        # =====================================================================\n        # Initialization\n        # =====================================================================\n\n        print(\"Enabling PWM outputs.\\n\")\n\n        project.enable_pwm()\n        project.variables&#091;\"Iout_ref\"&#093; = INITIAL_CURRENT_REF\n        project.clear_all_snapshots()\n\n        # =====================================================================\n        # Parameter sweep and data acquisition\n        # =====================================================================\n        for kp, ki in GAIN_PAIRS:\n            print(f\"Testing Kp={kp:g}, Ki={ki:g}\")\n\n            # Apply parameter values\n            project.variables&#091;\"Kp\"&#093; = kp\n            project.variables&#091;\"Ki\"&#093; = ki\n\n            # Apply transient sequence and start acquisition\n            scope.fire_transient()\n\n            # Wait for the acquisition to complete\n            cockpit.wait_until(scope.is_capture_done)\n\n            # (Optional) Take a snapshot\n            project.take_snapshot(\n                name=f\"kp_{kp:g}_ki_{ki:g}\",\n                comment=f\"Kp = {kp:g}, Ki = {ki:g}\")\n\n            # Export acquired data in a MAT file\n            scope.export(OUTPUT_DIR \/ f\"kp_{kp:g}_ki_{ki:g}.mat\")\n\n    finally:\n\n        # =====================================================================\n        # Reset current reference to zero and disable PWM outputs\n        # =====================================================================\n\n        print(f\"\\nDisabling PWM outputs.\\n\")\n\n        project.variables&#091;\"Iout_ref\"&#093; = 0.0\n        project.disable_pwm()<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\"># ...<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># The (Kp, Ki) pairs used in the sweep<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">GAIN_PAIRS<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> &#091;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">1.0<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #005CC5\">100.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">2.0<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #005CC5\">200.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">3.0<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #005CC5\">300.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># To be completed...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">&#093;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># BASE_DIR is the directory containing this script<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">BASE_DIR<\/span><span style=\"color: #24292E\">: Path <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> Path(<\/span><span style=\"color: #005CC5\">__file__<\/span><span style=\"color: #24292E\">).resolve().parent<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">OUTPUT_DIR<\/span><span style=\"color: #24292E\">: Path <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">BASE_DIR<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;output&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">OUTPUT_DIR<\/span><span style=\"color: #24292E\">.mkdir(<\/span><span style=\"color: #E36209\">exist_ok<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">True<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># ...<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">with<\/span><span style=\"color: #24292E\"> Cockpit() <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> cockpit:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># If an operation within &#39;try&#39; fails, jumps to the &#39;finally&#39; block. Used to<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># safely power down the converter before the script exits due to an error.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">try<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># Initialization<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;Enabling PWM outputs.<\/span><span style=\"color: #005CC5\">\\n<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.enable_pwm()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">INITIAL_CURRENT_REF<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.clear_all_snapshots()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># Parameter sweep and data acquisition<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">for<\/span><span style=\"color: #24292E\"> kp, ki <\/span><span style=\"color: #D73A49\">in<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">GAIN_PAIRS<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;Testing Kp=<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">, Ki=<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Apply parameter values<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Kp&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> kp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Ki&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> ki<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Apply transient sequence and start acquisition<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            scope.fire_transient()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Wait for the acquisition to complete<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            cockpit.wait_until(scope.is_capture_done)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># (Optional) Take a snapshot<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            project.take_snapshot(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #E36209\">name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;kp_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">_ki_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #E36209\">comment<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;Kp = <\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">, Ki = <\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Export acquired data in a MAT file<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            scope.export(<\/span><span style=\"color: #005CC5\">OUTPUT_DIR<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;kp_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">_ki_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">.mat&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">finally<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># Reset current reference to zero and disable PWM outputs<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #005CC5\">\\n<\/span><span style=\"color: #032F62\">Disabling PWM outputs.<\/span><span style=\"color: #005CC5\">\\n<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">0.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.disable_pwm()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-success\" role=\"alert\">The <code>finally<\/code> block is used as a safeguard to power down the converter before the script exits, even if an error occurs. The <code>finally<\/code> block will be executed regardless of whether the <code>try<\/code> block raises an error or not.<\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The-complete-script\"><\/span>The complete script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The complete script is shown below:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>from pathlib import Path\n\nfrom imperix import Cockpit, ModuleType\n\n# Cockpit project name to connect to\nPROJECT_NAME = \"TN109_PI_current_control\"\n\n# The (Kp, Ki) pairs used in the parameter sweep\nGAIN_PAIRS = &#091;\n    (3.0,  8000.0),\n    (3.0,  5000.0),\n    (3.0,  3000.0),\n    (3.0,  1500.0),\n    (3.0,  500.0),\n    (10.0, 500.0),\n    (20.0, 500.0),\n&#093;\n\n# Applied current-reference step (in Amperes)\nINITIAL_CURRENT_REF = 3.0\nFINAL_CURRENT_REF = 5.0\n\n# BASE_DIR is the directory containing this script\nBASE_DIR: Path = Path(__file__).resolve().parent\nOUTPUT_DIR: Path = BASE_DIR \/ \"output\"\nOUTPUT_DIR.mkdir(exist_ok=True)\n\nwith Cockpit() as cockpit:\n\n    # =========================================================================\n    # Retrieve an existing Cockpit project by name\n    # =========================================================================\n\n    project = cockpit.projects.get(PROJECT_NAME)\n\n    if project is None:\n        raise SystemExit(\"Project not found.\")\n\n    # =========================================================================\n    # Configure the scope module\n    # =========================================================================\n    \n    # Iterate through modules and delete any existing Scope module\n    for module in project.modules.list():\n        if module.type == ModuleType.SCOPE:\n            module.delete()\n\n    # Create a new Scope module\n    scope = project.modules.create(ModuleType.SCOPE)\n    scope.add_variables(&#091;\"Iout_ref\", \"Iout_meas\"&#093;)\n    scope.set_window(window_ms=15.0)\n    scope.set_transient(\n        variable=\"Iout_ref\",\n        positions_ms=&#091;2.0&#093;,\n        values=&#091;FINAL_CURRENT_REF&#093;,\n    )\n\n    # If an operation within 'try' fails, jumps to the 'finally' block. Used to\n    # safely power down the converter before the script exits due to an error.\n    try:\n\n        # =====================================================================\n        # Initialization\n        # =====================================================================\n\n        print(\"Enabling PWM outputs.\\n\")\n\n        project.enable_pwm()\n        project.variables&#091;\"Iout_ref\"&#093; = INITIAL_CURRENT_REF\n        project.clear_all_snapshots()\n\n        # =====================================================================\n        # Parameter sweep and data acquisition\n        # =====================================================================\n        for kp, ki in GAIN_PAIRS:\n            print(f\"Testing Kp={kp:g}, Ki={ki:g}\")\n\n            # Apply parameter values\n            project.variables&#091;\"Kp\"&#093; = kp\n            project.variables&#091;\"Ki\"&#093; = ki\n\n            # Apply transient sequence and start acquisition\n            scope.fire_transient()\n\n            # Wait for the acquisition to complete\n            cockpit.wait_until(scope.is_capture_done)\n\n            # (Optional) Take a snapshot\n            project.take_snapshot(\n                name=f\"kp_{kp:g}_ki_{ki:g}\",\n                comment=f\"Kp = {kp:g}, Ki = {ki:g}\")\n\n            # Export acquired data in a MAT file\n            scope.export(OUTPUT_DIR \/ f\"kp_{kp:g}_ki_{ki:g}.mat\")\n\n    finally:\n\n        # =====================================================================\n        # Reset current reference to zero and disable PWM outputs\n        # =====================================================================\n\n        print(f\"\\nDisabling PWM outputs.\\n\")\n\n        project.variables&#091;\"Iout_ref\"&#093; = 0.0\n        project.disable_pwm()<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">from<\/span><span style=\"color: #24292E\"> pathlib <\/span><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> Path<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">from<\/span><span style=\"color: #24292E\"> imperix <\/span><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> Cockpit, ModuleType<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># Cockpit project name to connect to<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">PROJECT_NAME<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;TN109_PI_current_control&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># The (Kp, Ki) pairs used in the parameter sweep<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">GAIN_PAIRS<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> &#091;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">3.0<\/span><span style=\"color: #24292E\">,  <\/span><span style=\"color: #005CC5\">8000.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">3.0<\/span><span style=\"color: #24292E\">,  <\/span><span style=\"color: #005CC5\">5000.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">3.0<\/span><span style=\"color: #24292E\">,  <\/span><span style=\"color: #005CC5\">3000.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">3.0<\/span><span style=\"color: #24292E\">,  <\/span><span style=\"color: #005CC5\">1500.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">3.0<\/span><span style=\"color: #24292E\">,  <\/span><span style=\"color: #005CC5\">500.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">10.0<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #005CC5\">500.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    (<\/span><span style=\"color: #005CC5\">20.0<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #005CC5\">500.0<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">&#093;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># Applied current-reference step (in Amperes)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">INITIAL_CURRENT_REF<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">3.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">FINAL_CURRENT_REF<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">5.0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># BASE_DIR is the directory containing this script<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">BASE_DIR<\/span><span style=\"color: #24292E\">: Path <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> Path(<\/span><span style=\"color: #005CC5\">__file__<\/span><span style=\"color: #24292E\">).resolve().parent<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">OUTPUT_DIR<\/span><span style=\"color: #24292E\">: Path <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">BASE_DIR<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;output&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">OUTPUT_DIR<\/span><span style=\"color: #24292E\">.mkdir(<\/span><span style=\"color: #E36209\">exist_ok<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">True<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">with<\/span><span style=\"color: #24292E\"> Cockpit() <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> cockpit:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># =========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Retrieve an existing Cockpit project by name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># =========================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    project <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> cockpit.projects.get(<\/span><span style=\"color: #005CC5\">PROJECT_NAME<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> project <\/span><span style=\"color: #D73A49\">is<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">None<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">raise<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">SystemExit<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;Project not found.&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># =========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Configure the scope module<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># =========================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Iterate through modules and delete any existing Scope module<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">for<\/span><span style=\"color: #24292E\"> module <\/span><span style=\"color: #D73A49\">in<\/span><span style=\"color: #24292E\"> project.modules.list():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> module.type <\/span><span style=\"color: #D73A49\">==<\/span><span style=\"color: #24292E\"> ModuleType.<\/span><span style=\"color: #005CC5\">SCOPE<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            module.delete()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Create a new Scope module<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> project.modules.create(ModuleType.<\/span><span style=\"color: #005CC5\">SCOPE<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope.add_variables(&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #032F62\">&quot;Iout_meas&quot;<\/span><span style=\"color: #24292E\">&#093;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope.set_window(<\/span><span style=\"color: #E36209\">window_ms<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">15.0<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    scope.set_transient(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">variable<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">positions_ms<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">&#091;<\/span><span style=\"color: #005CC5\">2.0<\/span><span style=\"color: #24292E\">&#093;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">values<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">&#091;<\/span><span style=\"color: #005CC5\">FINAL_CURRENT_REF<\/span><span style=\"color: #24292E\">&#093;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    )<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># If an operation within &#39;try&#39; fails, jumps to the &#39;finally&#39; block. Used to<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># safely power down the converter before the script exits due to an error.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">try<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># Initialization<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;Enabling PWM outputs.<\/span><span style=\"color: #005CC5\">\\n<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.enable_pwm()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">INITIAL_CURRENT_REF<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.clear_all_snapshots()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># Parameter sweep and data acquisition<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">for<\/span><span style=\"color: #24292E\"> kp, ki <\/span><span style=\"color: #D73A49\">in<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">GAIN_PAIRS<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;Testing Kp=<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">, Ki=<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Apply parameter values<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Kp&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> kp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Ki&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> ki<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Apply transient sequence and start acquisition<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            scope.fire_transient()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Wait for the acquisition to complete<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            cockpit.wait_until(scope.is_capture_done)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># (Optional) Take a snapshot<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            project.take_snapshot(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #E36209\">name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;kp_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">_ki_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #E36209\">comment<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;Kp = <\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">, Ki = <\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #6A737D\"># Export acquired data in a MAT file<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            scope.export(<\/span><span style=\"color: #005CC5\">OUTPUT_DIR<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;kp_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">kp<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">_ki_<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">ki<\/span><span style=\"color: #D73A49\">:g<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">.mat&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">finally<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># Reset current reference to zero and disable PWM outputs<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #6A737D\"># =====================================================================<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #005CC5\">\\n<\/span><span style=\"color: #032F62\">Disabling PWM outputs.<\/span><span style=\"color: #005CC5\">\\n<\/span><span style=\"color: #032F62\">&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.variables&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_ref&quot;<\/span><span style=\"color: #24292E\">&#093; <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">0.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        project.disable_pwm()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Experimental-results\"><\/span>Experimental results<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-warning\" role=\"alert\">Before running a Python script to control a converter during experimental tests, it is highly recommended to manually perform the script&#8217;s actions to verify that the system is correctly wired and operating smoothly.<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The video below demonstrates the execution of the automated parameter sweep script using the PI controller code from <a href=\"https:\/\/imperix.com\/doc\/implementation\/pi-based-current-control\">TN109<\/a> on the following buck converter setup:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One&nbsp;<a href=\"https:\/\/imperix.com\/products\/control\/rcp-controller\/\">B-Box 4<\/a>&nbsp;controller with&nbsp;<a href=\"https:\/\/imperix.com\/software\/acg-sdk\">ACG SDK<\/a>&nbsp;software<\/li>\n\n\n\n<li>1x&nbsp;<a href=\"https:\/\/imperix.com\/products\/power\/sic-mosfet-module\/\">PEB-800-40<\/a>&nbsp;half-bridge module (rated for 800V 40A)<\/li>\n\n\n\n<li>1x 2.2mH 32A inductor<\/li>\n\n\n\n<li>1x 8&nbsp;\u03a9 load resistor<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To replicate this example, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Build a buck converter following step-by-step instructions given in&nbsp;<a href=\"https:\/\/imperix.com\/doc\/help\/how-to-build-a-buck-converter\">PN119<\/a>.<\/li>\n\n\n\n<li>Download and run the code from <a href=\"https:\/\/imperix.com\/doc\/implementation\/pi-based-current-control\">TN109<\/a>.<\/li>\n\n\n\n<li>Copy the automated parameter sweep script provided above and save it as a Python file (e.g., <code>param_sweep.py<\/code>).<\/li>\n\n\n\n<li>In the Python script, update the <code>PROJECT_NAME<\/code> variable with the exact project name found in the Cockpit project settings to ensure a perfect match.<\/li>\n\n\n\n<li>Execute the newly created <code>.py<\/code> script using either Cockpit&#8217;s built-in launcher or a standalone Python environment.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1440\" style=\"aspect-ratio: 2560 \/ 1440;\" width=\"2560\" controls src=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/07\/Python_automated_sweep.mp4\"><\/video><figcaption class=\"wp-element-caption\">Automated parameter sweep and acquisition<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Going-further\"><\/span>Going further<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The generated files can be inspected directly in MATLAB or processed further in Python. The snippet below demonstrates how to read the exported MAT files in Python using the <a href=\"https:\/\/docs.h5py.org\/en\/stable\/\"><code>h5py<\/code><\/a> library and arrange the data into a <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.DataFrame.html\"><code>DataFrame<\/code><\/a> using the <code><a href=\"https:\/\/pandas.pydata.org\/docs\/\"><code>pandas<\/code><\/a><\/code> library. For more details on working with MAT files generated by Cockpit, refer to <a href=\"https:\/\/imperix.com\/doc\/help\/mat-files-cockpit\">PN141<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The data exported from the Scope module has the following internal structure:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>kp_3_ki_500.mat\n\u251c\u2500\u2500 General_Header\n\u2502   \u2514\u2500\u2500 ...                  (export metadata)\n\u251c\u2500\u2500 Variables_Header\n\u2502   \u2514\u2500\u2500 ...                  (variable metadata)\n\u251c\u2500\u2500 Iout_ref                 (N rows, 2 columns)\n\u2514\u2500\u2500 Iout_meas                (M rows, 2 columns)<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #24292e\">kp_3_ki_500.mat<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292e\">\u251c\u2500\u2500 General_Header<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292e\">\u2502   \u2514\u2500\u2500 ...                  (export metadata)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292e\">\u251c\u2500\u2500 Variables_Header<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292e\">\u2502   \u2514\u2500\u2500 ...                  (variable metadata)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292e\">\u251c\u2500\u2500 Iout_ref                 (N rows, 2 columns)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292e\">\u2514\u2500\u2500 Iout_meas                (M rows, 2 columns)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The following Python code provides an example of how to read this data:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>from pathlib import Path\n\nimport h5py\nimport pandas as pd\n\n# Replace this with the path to one MAT file exported by the Scope module.\nOUTPUT_PATH = Path(r\"C:\\imperix\\output\\kp_3_ki_500.mat\")\n\nwith h5py.File(OUTPUT_PATH, \"r\") as exported_file:\n    # Access the measured-current data saved by the Scope module.\n    iout_meas_data = exported_file&#091;\"Iout_meas\"&#093;\n\n    # Each exported variable is a 2 x N array in h5py.\n    # &#091;0, :&#093; means \"first row, all columns\": the time values for all N samples.\n    # &#091;1, :&#093; means \"second row, all columns\": the signal values for all N samples.\n    time = iout_meas_data&#091;0, :&#093;\n    iout_meas = iout_meas_data&#091;1, :&#093;\n\n    # Build a labelled table with one row per acquired sample.\n    exported_data = pd.DataFrame({\n        \"Time\": time,\n        \"Iout_meas\": iout_meas,\n    })\n\n# Display the first five rows of the table.\nprint(exported_data.head())\n\n# ...<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">from<\/span><span style=\"color: #24292E\"> pathlib <\/span><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> Path<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> h5py<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> pandas <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> pd<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># Replace this with the path to one MAT file exported by the Scope module.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">OUTPUT_PATH<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> Path(<\/span><span style=\"color: #D73A49\">r<\/span><span style=\"color: #032F62\">&quot;C:<\/span><span style=\"color: #22863A; font-weight: bold\">\\i<\/span><span style=\"color: #032F62\">mperix<\/span><span style=\"color: #22863A; font-weight: bold\">\\o<\/span><span style=\"color: #032F62\">utput<\/span><span style=\"color: #22863A; font-weight: bold\">\\k<\/span><span style=\"color: #032F62\">p_3_ki_500<\/span><span style=\"color: #005CC5\">.<\/span><span style=\"color: #032F62\">mat&quot;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">with<\/span><span style=\"color: #24292E\"> h5py.File(<\/span><span style=\"color: #005CC5\">OUTPUT_PATH<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #032F62\">&quot;r&quot;<\/span><span style=\"color: #24292E\">) <\/span><span style=\"color: #D73A49\">as<\/span><span style=\"color: #24292E\"> exported_file:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Access the measured-current data saved by the Scope module.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    iout_meas_data <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> exported_file&#091;<\/span><span style=\"color: #032F62\">&quot;Iout_meas&quot;<\/span><span style=\"color: #24292E\">&#093;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Each exported variable is a 2 x N array in h5py.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># &#091;0, :&#093; means &quot;first row, all columns&quot;: the time values for all N samples.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># &#091;1, :&#093; means &quot;second row, all columns&quot;: the signal values for all N samples.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    time <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> iout_meas_data&#091;<\/span><span style=\"color: #005CC5\">0<\/span><span style=\"color: #24292E\">, :&#093;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    iout_meas <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> iout_meas_data&#091;<\/span><span style=\"color: #005CC5\">1<\/span><span style=\"color: #24292E\">, :&#093;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #6A737D\"># Build a labelled table with one row per acquired sample.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    exported_data <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> pd.DataFrame({<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #032F62\">&quot;Time&quot;<\/span><span style=\"color: #24292E\">: time,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #032F62\">&quot;Iout_meas&quot;<\/span><span style=\"color: #24292E\">: iout_meas,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    })<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># Display the first five rows of the table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(exported_data.head())<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\"># ...<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This application note shows how to use Python scripting to automate actions otherwise performed manually in Cockpit. Doing so, it also introduces a recommended workflow&#8230;<\/p>\n","protected":false},"author":4,"featured_media":50118,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[3],"tags":[184],"software-environments":[],"provided-results":[108],"related-products":[],"guidedreadings":[],"tutorials":[],"user-manuals":[],"coauthors":[70,173],"class_list":["post-47070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-help","tag-python","provided-results-experimental"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Automated parameter sweep using Python - imperix<\/title>\n<meta name=\"description\" content=\"This example uses Python to automate a parameter sweep for the PI controller used for the current control of a buck converter.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automated parameter sweep using Python - imperix\" \/>\n<meta property=\"og:description\" content=\"This example uses Python to automate a parameter sweep for the PI controller used for the current control of a buck converter.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python\" \/>\n<meta property=\"og:site_name\" content=\"imperix\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-14T14:46:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/Feat_img_param_sweep_python_v2-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"630\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Beno\u00eet Steinmann, Jules Perrin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Beno\u00eet Steinmann, Jules Perrin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python\"},\"author\":{\"name\":\"Beno\u00eet Steinmann\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/person\\\/a69a3bda75b05d0923cc76d7268cc94f\"},\"headline\":\"Automated parameter sweep using Python\",\"datePublished\":\"2026-09-14T14:46:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python\"},\"wordCount\":946,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Feat_img_param_sweep_python_v2-1.png\",\"keywords\":[\"python\"],\"articleSection\":[\"Product notes\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python\",\"name\":\"Automated parameter sweep using Python - imperix\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Feat_img_param_sweep_python_v2-1.png\",\"datePublished\":\"2026-09-14T14:46:46+00:00\",\"description\":\"This example uses Python to automate a parameter sweep for the PI controller used for the current control of a buck converter.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#primaryimage\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Feat_img_param_sweep_python_v2-1.png\",\"contentUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Feat_img_param_sweep_python_v2-1.png\",\"width\":630,\"height\":420},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/help\\\/automate-parameter-sweeps-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Knowledge base\",\"item\":\"https:\\\/\\\/imperix.com\\\/doc\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Product notes\",\"item\":\"https:\\\/\\\/imperix.com\\\/doc\\\/category\\\/help\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Automated parameter sweep using Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#website\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/\",\"name\":\"imperix\",\"description\":\"power electronics\",\"publisher\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/imperix.com\\\/doc\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#organization\",\"name\":\"imperix\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/imperix_logo.png\",\"contentUrl\":\"https:\\\/\\\/imperix.com\\\/doc\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/imperix_logo.png\",\"width\":350,\"height\":120,\"caption\":\"imperix\"},\"image\":{\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/imperix.com\\\/doc\\\/#\\\/schema\\\/person\\\/a69a3bda75b05d0923cc76d7268cc94f\",\"name\":\"Beno\u00eet Steinmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/22a9252907f853f91d07b143dfcc84f6ec0cc31f6b72408b503a7026eed5b109?s=96&d=mm&r=g3b3f3d8e66019ebcb2848094940b98c0\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/22a9252907f853f91d07b143dfcc84f6ec0cc31f6b72408b503a7026eed5b109?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/22a9252907f853f91d07b143dfcc84f6ec0cc31f6b72408b503a7026eed5b109?s=96&d=mm&r=g\",\"caption\":\"Beno\u00eet Steinmann\"},\"description\":\"Benoit is an embedded systems expert and the leader of software and firmware developments at imperix. On the knowledge base, he is the author of numerous software reference documents.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/benoit-steinmann\\\/\"],\"url\":\"https:\\\/\\\/imperix.com\\\/doc\\\/author\\\/steinmann\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automated parameter sweep using Python - imperix","description":"This example uses Python to automate a parameter sweep for the PI controller used for the current control of a buck converter.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python","og_locale":"en_US","og_type":"article","og_title":"Automated parameter sweep using Python - imperix","og_description":"This example uses Python to automate a parameter sweep for the PI controller used for the current control of a buck converter.","og_url":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python","og_site_name":"imperix","article_published_time":"2026-09-14T14:46:46+00:00","og_image":[{"width":630,"height":420,"url":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/Feat_img_param_sweep_python_v2-1.png","type":"image\/png"}],"author":"Beno\u00eet Steinmann, Jules Perrin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Beno\u00eet Steinmann, Jules Perrin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#article","isPartOf":{"@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python"},"author":{"name":"Beno\u00eet Steinmann","@id":"https:\/\/imperix.com\/doc\/#\/schema\/person\/a69a3bda75b05d0923cc76d7268cc94f"},"headline":"Automated parameter sweep using Python","datePublished":"2026-09-14T14:46:46+00:00","mainEntityOfPage":{"@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python"},"wordCount":946,"commentCount":0,"publisher":{"@id":"https:\/\/imperix.com\/doc\/#organization"},"image":{"@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#primaryimage"},"thumbnailUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/Feat_img_param_sweep_python_v2-1.png","keywords":["python"],"articleSection":["Product notes"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#respond"]}]},{"@type":"WebPage","@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python","url":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python","name":"Automated parameter sweep using Python - imperix","isPartOf":{"@id":"https:\/\/imperix.com\/doc\/#website"},"primaryImageOfPage":{"@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#primaryimage"},"image":{"@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#primaryimage"},"thumbnailUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/Feat_img_param_sweep_python_v2-1.png","datePublished":"2026-09-14T14:46:46+00:00","description":"This example uses Python to automate a parameter sweep for the PI controller used for the current control of a buck converter.","breadcrumb":{"@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#primaryimage","url":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/Feat_img_param_sweep_python_v2-1.png","contentUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2026\/09\/Feat_img_param_sweep_python_v2-1.png","width":630,"height":420},{"@type":"BreadcrumbList","@id":"https:\/\/imperix.com\/doc\/help\/automate-parameter-sweeps-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Knowledge base","item":"https:\/\/imperix.com\/doc\/"},{"@type":"ListItem","position":2,"name":"Product notes","item":"https:\/\/imperix.com\/doc\/category\/help"},{"@type":"ListItem","position":3,"name":"Automated parameter sweep using Python"}]},{"@type":"WebSite","@id":"https:\/\/imperix.com\/doc\/#website","url":"https:\/\/imperix.com\/doc\/","name":"imperix","description":"power electronics","publisher":{"@id":"https:\/\/imperix.com\/doc\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imperix.com\/doc\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/imperix.com\/doc\/#organization","name":"imperix","url":"https:\/\/imperix.com\/doc\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imperix.com\/doc\/#\/schema\/logo\/image\/","url":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/imperix_logo.png","contentUrl":"https:\/\/imperix.com\/doc\/wp-content\/uploads\/2021\/03\/imperix_logo.png","width":350,"height":120,"caption":"imperix"},"image":{"@id":"https:\/\/imperix.com\/doc\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/imperix.com\/doc\/#\/schema\/person\/a69a3bda75b05d0923cc76d7268cc94f","name":"Beno\u00eet Steinmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/22a9252907f853f91d07b143dfcc84f6ec0cc31f6b72408b503a7026eed5b109?s=96&d=mm&r=g3b3f3d8e66019ebcb2848094940b98c0","url":"https:\/\/secure.gravatar.com\/avatar\/22a9252907f853f91d07b143dfcc84f6ec0cc31f6b72408b503a7026eed5b109?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/22a9252907f853f91d07b143dfcc84f6ec0cc31f6b72408b503a7026eed5b109?s=96&d=mm&r=g","caption":"Beno\u00eet Steinmann"},"description":"Benoit is an embedded systems expert and the leader of software and firmware developments at imperix. On the knowledge base, he is the author of numerous software reference documents.","sameAs":["https:\/\/www.linkedin.com\/in\/benoit-steinmann\/"],"url":"https:\/\/imperix.com\/doc\/author\/steinmann"}]}},"_links":{"self":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts\/47070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/comments?post=47070"}],"version-history":[{"count":170,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts\/47070\/revisions"}],"predecessor-version":[{"id":49277,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/posts\/47070\/revisions\/49277"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/media\/50118"}],"wp:attachment":[{"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/media?parent=47070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/categories?post=47070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/tags?post=47070"},{"taxonomy":"software-environments","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/software-environments?post=47070"},{"taxonomy":"provided-results","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/provided-results?post=47070"},{"taxonomy":"related-products","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/related-products?post=47070"},{"taxonomy":"guidedreadings","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/guidedreadings?post=47070"},{"taxonomy":"tutorials","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/tutorials?post=47070"},{"taxonomy":"user-manuals","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/user-manuals?post=47070"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/imperix.com\/doc\/wp-json\/wp\/v2\/coauthors?post=47070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}