{"id":2704,"date":"2026-04-16T08:06:33","date_gmt":"2026-04-16T08:06:33","guid":{"rendered":"https:\/\/blogs.mathworks.com\/finance\/?p=2704"},"modified":"2026-04-16T08:08:08","modified_gmt":"2026-04-16T08:08:08","slug":"run-dynare-at-scale-on-databricks-with-interactive-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/finance\/2026\/04\/16\/run-dynare-at-scale-on-databricks-with-interactive-matlab\/","title":{"rendered":"Run Dynare at Scale on Databricks with Interactive MATLAB"},"content":{"rendered":"<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/p>\n<div>\n<table style=\"background-color: #e2f0ff;\">\n<tbody>\n<tr>\n<td style=\"width: 120px; padding: 3px; vertical-align: middle;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-19243\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/04\/Untitled-2-2.png\" alt=\"\" width=\"100\" height=\"100\" \/><\/td>\n<td style=\"vertical-align: middle; padding: 3px;\"><strong>Expert Contributor: <a href=\"https:\/\/www.linkedin.com\/in\/eduard-benet\/\" target=\"_blank\" rel=\"noopener\">Dr. Eduard Benet Cerd&agrave;<\/a><\/strong><\/p>\n<h6><\/h6>\n<p><strong>Edu<\/strong> is a Senior Application Engineer at MathWorks advising customers in the development and deployment of financial applications. His focus areas are large scale applications leveraging cloud technologies for data storage, computational speed, or production and development environments, as well as the development and distribution of macroeconomic models. Eduard joined MathWorks in 2018 after finishing a PhD at the University of Colorado in computational mechanics. <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>Dynare is a go-to framework for dynamic stochastic general equilibrium (DSGE) and macro-finance modeling.<\/p>\n<p>This post walks through a practical workflow to:<\/p>\n<ol type=\"1\" start=\"1\">\n<li><strong>Build a custom Databricks compute resource to run MATLAB and Dynare<\/strong><\/li>\n<li><strong>Develop a Dynare model sourcing the data from Databricks<\/strong><\/li>\n<li><strong>Schedule and run that model as a Databricks job or pipeline<\/strong><\/li>\n<\/ol>\n<p><strong>Why it matters<\/strong>: This workflow gives you a consistent, version\u2011locked MATLAB environment, flexible Dynare configuration, and orchestration for routine or large\u2011scale model execution.<\/p>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h1><strong>What You\u2019ll Build<\/strong><\/h1>\n<p>With a few configuration files and scripts, you will:<\/p>\n<ul>\n<li>Launch Databricks compute using your <strong>own Docker image<\/strong> via Databricks Container Services<\/li>\n<li>Run <strong>MATLAB<\/strong> through your web browser with access to Unity Catalog for debugging and exploration<\/li>\n<li>Submit a <strong>Dynare job<\/strong> as a non-interactive batch run that writes outputs to a durable location and interactively displays them in a notebook<\/li>\n<\/ul>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h1><strong>Step 0 \u2014 Prerequisites<\/strong><\/h1>\n<ul>\n<li>A Databricks workspace<\/li>\n<li>A container registry to host your image (ideally on the same region as your Databricks workspace)<\/li>\n<li>The MATLAB-Databricks support package<\/li>\n<\/ul>\n<p>A license manager accessible from Databricks with access to R2022b or newer (R2026a recommended)<\/p>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h1><strong>Step 1 \u2014 Build a custom Databricks image to run MATLAB and Dynare<\/strong><\/h1>\n<p>The MathWorks reference architecture provides <a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-on-databricks\/tree\/main\/resources\/dockerfiles\/matlab\">a Dockerfile<\/a> to get a full MATLAB desktop running on Databricks. You can use it as-is or customize it, but ultimately, you must build an image that starts from a Databricks base image and adds MATLAB and its toolboxes.<\/p>\n<p>Example build using <strong>Azure Container Registry<\/strong>:<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<pre class=\"wp-block-preformatted\"> az acr build \\\n  --registry &lt;registry&gt; \\\n  --image databricks\/matlab:R2026a-17.4 \\\n  --build-arg MATLAB_PRODUCT_LIST=\"MATLAB_Compiler_SDK Database_Toolbox Econometrics_Toolbox\" \\\n  --build-arg INCLUDE_JRE=0 \\\n  --build-arg LICENSE_SERVER=&lt;licenseServer&gt; \\\n  --file resources\/dockerfiles\/matlab\/Dockerfile \\\n  https:\/\/github.com\/mathworks-ref-arch\/matlab-on-databricks.git\n<\/pre>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>Consider keeping Dynare outside the container. Instead, add only optional libraries (e.g., to run TeX) tht some workflows migh require. This lets you test different Dynare versions without rebuilding the container. <\/p>\n<p>Once the image is ready, the next step is to start with a compute resource. Databricks Container Services lets you specify a Docker image when you create compute. From the UI, you can see this in &#8220;Create Compute &gt; Advanced &gt; Docker&#8221; <em>fig 1<\/em><\/p>\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/UI.png\" alt=\"Screenshot of the Databricks \u201cCreate Compute\u201d interface showing the Advanced &gt; Docker configuration section where a custom Docker image can be specified for a cluster.\" class=\"wp-image-2766\" width=\"642\" height=\"235\"\/><figcaption class=\"wp-element-caption\"><em>Fig 1. UI location to enter the Docker details<\/em><\/figcaption><\/figure>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>However, configuring these settings through the UI can be tedious and error\u2011prone. Two approaches work better in practice:<\/p>\n<\/p>\n<h2>(A) Use a Databricks Policy<\/h2>\n<p>This is the recommended approach. A Databricks admin can create a policy that pins the MATLAB version, grant Unity Catalog access, and allow controlled user choices (e.g. instance size and idle timeout). Anyone with access can go into the portal and start a cluster.<\/p>\n<p><strong>To start a MATLAB session, <\/strong>&nbsp;launch it from a notebook, which serves as the entry point in Databricks. The notebook in Fig. 2 (Dockerfiles, available in the same GitHub repository as the Dockerfiles) starts MATLAB sessions, adds toolboxes at runtime, and configures the environment.<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/notebook-to-manage-MATLAB-sessions-in-Databricks.png\" alt=\"Screenshot of a Databricks notebook that initializes a MATLAB session, adds required toolboxes at runtime, and configures the environment for interactive MATLAB use on Databricks.\" class=\"wp-image-2768\" width=\"662\" height=\"396\"\/><figcaption class=\"wp-element-caption\"><em>Fig 2. Notebook to manage MATLAB sessions in Databricks<\/em><\/figcaption><\/figure>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h2>(B) Use the REST API<\/h2>\n<p>You can also create, start, and stop a cluster using the Databricks REST API. MATLAB Interface for Databricks includes a function that creates a cluster and returns the URL of the running MATLAB instance.<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<pre class=\"wp-block-preformatted\">cdt = createMATLABDesktopCluster( ... \n        dockerAuthFile    = 'credentials.json', ...\n        name              = \"matlab26a\");\n<\/pre>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>The notebook in Fig. 2 can also manage sessions.<\/p>\n<p>Consider including MATLAB Interface for Databricks in the environment. If it is not included in the Dockerfile, both the notebook and the function above will install it from Unity Catalog.<\/p>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h1><strong>Step 2 \u2014 Develop a custom Dynare model sourcing the data from Databricks<\/strong><\/h1>\n<p>With MATLAB running inside Databricks (Figure 3) and MATLAB Interface for Databricks active, you can develop your Dynare model as usual<strong>Unity Catalog <\/strong>(Fig 3). To develop our DSGE model, we only need Dynare itself. You can source it in different ways, but because the base image runs in Ubuntu 24.04, you can install the .mltbx package provided for use with MATLAB by the Dynare team:<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<pre class=\"wp-block-preformatted\">&gt;&gt; websave('dynare.mltbx', 'https:\/\/www.dynare.org\/release\/matlab-online\/dynare-6.5.mltbx');\n&gt;&gt; matlab.addons.install('dynare.mltbx');<\/pre>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/IMage-for-step-2-1024x721.png\" alt=\"Screenshot of MATLAB running inside a Databricks compute instance, displaying the execution of a Dynare model and sample output from the fs2000.mod example.\" class=\"wp-image-2770\" width=\"725\" height=\"510\"\/><figcaption class=\"wp-element-caption\"><em>Fig 3. Snapshot of a Dynare model running in MATLAB within Databricks<\/em><\/figcaption><\/figure>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>To showcase the Databricks interactions, this post uses a bundled Dynare example, (<strong>fs2000.mod<\/strong>) Frank Schorfheide (2000): &#8220;Loss function-based evaluation of DSGE models&#8221;. This model requires a datafile, entered via the estimation command below:<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<pre class=\"wp-block-preformatted\">estimation(order=1, datafile=fs2000_data,<\/pre>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>The example data is not big and could simply be read as a file from Unity Catalog:<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<pre class=\"wp-block-preformatted\">readtable('\/Volumes\/..\/mydata.mat')\".<\/pre>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>However, to demonstrate Databricks integration, the data is sourced using Spark, function as shown in Fig. 4.<\/p>\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/data-provisioning-function.png\" alt=\"Code snippet showing a data\u2011loading function that uses Spark within Databricks to feed data into a MATLAB Dynare workflow.\" class=\"wp-image-2771\" width=\"494\" height=\"277\"\/><figcaption class=\"wp-element-caption\"><em>Fig 4. Data provisioning function<\/em><\/figcaption><\/figure>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>Our model is now fully integrated with Databricks and is simply run as any standard Dynare MOD file (see Fig 3 for sample output):<\/p>\n<pre class=\"wp-block-preformatted\">&gt;&gt; dynare fs2000.mod<\/pre>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h1><strong>Step 3\u2014 Schedule and run that model as a Databricks job or pipeline<\/strong><\/h1>\n<p>To operationalize this model, start by placing the model assets in a Unity Catalog Volume using MATLAB Interface for Databricks:<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<pre class=\"wp-block-preformatted\">&gt;&gt; f = databricks.Files\n&gt;&gt; f.upload('fs2000_data.m', '\/Volumes\/main\/default\/models\/fs2000\/fs2000_data.m')\n&gt;&gt; f.upload(\u2018fs2000.mod\u2019, '\/Volumes\/main\/default\/models\/fs2000\/fs2000.mod')\n<\/pre>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>Next, I had to create a <strong>Databricks Job<\/strong>. For convenience, I used the <strong>MATLABBatchTask<\/strong> function from the support package. This function generates the Python notebook used to drive the job, supports pre\u2011 and postexecution Python steps for managing inputs and outputs, provisions the compute cluster, and runs the MATLAB workload end\u2011to\u2011end.<\/p>\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"521\" height=\"288\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/Job-scheduling.png\" alt=\"Screenshot of a Databricks job configuration generated by MATLABBatchTask, showing the notebook, cluster setup, and execution flow for running a Dynare model as a batch job.\" class=\"wp-image-2772\"\/><figcaption class=\"wp-element-caption\"><em>Fig 5. Job scheduling<\/em><\/figcaption><\/figure>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>With a little customizations, the output notebook runs our Dynare model and displays the full output on screen: <\/p>\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/batch-job-running-in-Dynare.png\" alt=\"Screenshot of a Databricks notebook executing a Dynare model in batch mode and displaying console output and figures produced by MATLAB.\" class=\"wp-image-2773\" width=\"426\" height=\"486\"\/><figcaption class=\"wp-element-caption\"><em>Fig 6. Batch job running in Dynare<\/em><\/figcaption><\/figure>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<p>This example uses <strong>R2026a<\/strong>, a postexecution script that displays MATLAB figures directly inside the notebook. R2026a supports exporting plots as <strong>interactive HTML canvases<\/strong>\u2014a format well suited to Databricks notebooks.<\/p>\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/Results-displayed-within-the-databricks-notebook.png\" alt=\"Screenshot showing MATLAB figures rendered inside a Databricks notebook using R2026a\u2019s interactive HTML canvas export.\" class=\"wp-image-2774\" width=\"585\" height=\"425\"\/><figcaption class=\"wp-element-caption\"><em>Fig 7. Results displayed within the Databricks notebook<\/em><\/figcaption><\/figure>\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<h1><strong>References<\/strong><\/h1>\n<ul>\n<li>Databricks: <em><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.databricks.com\/aws\/en\/compute\/custom-containers\" target=\"_blank\">Customize containers with Databricks Container Service<\/a><\/em> (custom Docker images on compute, requirements\/limitations, CLI examples).<\/li>\n<li>MathWorks: <em><a rel=\"noreferrer noopener\" href=\"https:\/\/uk.mathworks.com\/help\/cloudcenter\/ug\/matlab-container-on-docker-hub.html?requestedDomain=\" target=\"_blank\">MATLAB Container on Docker Hub<\/a><\/em> (interactive browser and VNC modes, licensing notes). <\/li>\n<li>MathWorks: <a rel=\"noreferrer noopener\" href=\"http:\/\/mathworks.com\/solutions\/partners\/databricks.html\" target=\"_blank\"><em>Databricks \u2013 MATLAB and Simulink \/ MATLAB Interface for Databricks<\/em> <\/a>(support package capabilities and workflows).<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/finance\/files\/2026\/02\/UI.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Expert Contributor: Dr. Eduard Benet Cerd&agrave;<\/p>\n<p>Edu is a Senior Application Engineer at MathWorks advising customers in the development and deployment of financial applications. His focus&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/finance\/2026\/04\/16\/run-dynare-at-scale-on-databricks-with-interactive-matlab\/\">read more >><\/a><\/p>\n","protected":false},"author":233,"featured_media":2766,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,16,4],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts\/2704"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/users\/233"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/comments?post=2704"}],"version-history":[{"count":54,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts\/2704\/revisions"}],"predecessor-version":[{"id":2849,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts\/2704\/revisions\/2849"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/media\/2766"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/media?parent=2704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/categories?post=2704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/tags?post=2704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}