{"data":{"markdownRemark":{"html":"<p>The CLI (command line interface) Runner allows users to run models for a specified duration with specified inputs from the command line. This could be useful for users who wish to run the model but do not need to run the server or view the output on the console.</p>\n<h2 id=\"preparing-the-model\"><a href=\"#preparing-the-model\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Preparing the model</h2>\n<p>To run a Model using the CLI, you first need to update your <code class=\"language-text\">Main.java</code> class so that it runs the server with the array of String arguments passed from the java main method. This allows you to pass your CLI parameters to the Simudyne SDK so the model can be run with your CLI parameters. </p>\n<p class=\"code-header\">Main.Java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Main</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> <span class=\"token keyword\">void</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span>String<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> args<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    Server<span class=\"token punctuation\">.</span><span class=\"token function\">register</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"My Model\"</span><span class=\"token punctuation\">,</span> MyModel<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Pass args as parameter to Server.run</span>\n    Server<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You then need to package, you will need to build a fat jar which will carry your model, the Simudyne SDK and all the necessary dependencies. In this example, we will use the <code class=\"language-text\">maven-shade-plugin</code> to build this fat jar. </p>\n<div class=\"ui segment info message\">\n  <h4>Choosing the maven fat jar plugin </h4>\nThe Simudyne SDK uses Akka HTTP to start the server, whose configuration approach requires all configuration files to be merged when creating fat jars. This is why the `maven-shade-plugin` is used over the `maven-assembly-plugin`. The `maven-shade-plugin` allows us to easily merge all reference.confs (Akka configuration files) on the build classpath so that Akka will use the correct configuration specified in the Simudyne SDK and additional configuration if overriden by the user.\n</div>\n<p>To do this, add the following code to the plugins section in the <code class=\"language-text\">pom.xml</code> file. </p>\n<p class=\"code-header\">pom.xml</p>\n<div class=\"gatsby-highlight\" data-language=\"xml\"><pre class=\"language-xml\"><code class=\"language-xml\"><span class=\"token prolog\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>project</span> <span class=\"token attr-name\">...</span><span class=\"token punctuation\">></span></span>\n    ... properties and dependencies ...\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>build</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>plugins</span><span class=\"token punctuation\">></span></span>\n            ... other plugins ...\n            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>plugin</span><span class=\"token punctuation\">></span></span>\n                <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>artifactId</span><span class=\"token punctuation\">></span></span>maven-shade-plugin<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>artifactId</span><span class=\"token punctuation\">></span></span>\n                <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>version</span><span class=\"token punctuation\">></span></span>3.1.0<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>version</span><span class=\"token punctuation\">></span></span>\n                <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>configuration</span><span class=\"token punctuation\">></span></span>\n                    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>transformers</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>transformer</span> <span class=\"token attr-name\">implementation</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>org.apache.maven.plugins.shade.resource.AppendingTransformer<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n                            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>resource</span><span class=\"token punctuation\">></span></span>reference.conf<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>resource</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>transformer</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>transformer</span>\n                                <span class=\"token attr-name\">implementation</span><span class=\"token attr-value\"><span class=\"token punctuation\">=</span><span class=\"token punctuation\">\"</span>org.apache.maven.plugins.shade.resource.ManifestResourceTransformer<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n                            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>mainClass</span><span class=\"token punctuation\">></span></span>Main<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>mainClass</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>transformer</span><span class=\"token punctuation\">></span></span>\n                    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>transformers</span><span class=\"token punctuation\">></span></span>\n                <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>configuration</span><span class=\"token punctuation\">></span></span>\n                <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>executions</span><span class=\"token punctuation\">></span></span>\n                    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>execution</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>phase</span><span class=\"token punctuation\">></span></span>package<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>phase</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>goals</span><span class=\"token punctuation\">></span></span>\n                            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>goal</span><span class=\"token punctuation\">></span></span>shade<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>goal</span><span class=\"token punctuation\">></span></span>\n                        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>goals</span><span class=\"token punctuation\">></span></span>\n                    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>execution</span><span class=\"token punctuation\">></span></span>\n                <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>executions</span><span class=\"token punctuation\">></span></span>\n            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>plugin</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>plugins</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>build</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>project</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>You can then run the maven command to create the fatJar:</p>\n<p class=\"code-header\">Maven</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">mvn -s settings.xml clean compile package</code></pre></div>\n<p>Maven will create the jar and place it in the target directory (unless you have specified otherwise in your pom settings). Unless you have given it a specific name, the generated jar will be named <code class=\"language-text\">&lt;some-artifact-id&gt;-&lt;some-version&gt;-jar</code>. </p>\n<h2 id=\"running-the-model\"><a href=\"#running-the-model\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Running the model</h2>\n<p>The CLI runner can be used to run any model that has been registerd using <code class=\"language-text\">Server.register(&quot;name&quot;, model)</code>. It is run by running the generated jar with arguments specifying which model to run and how to run the model. </p>\n<ul>\n<li><code class=\"language-text\">--help</code> This parameter can be used to list all the CLI options with an explaination of how they are used. </li>\n</ul>\n<p class=\"code-header\">Running the CLI help option</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">java -jar target/sample-artifact-1.1.0.jar --help</code></pre></div>\n<p class=\"code-header\">Expected output</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">Usage: <span class=\"token operator\">&lt;</span>main class<span class=\"token operator\">></span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span>\n  Options:\n    --model-class\n      Full canonical class name to run.\n<span class=\"token punctuation\">..</span>.      </code></pre></div>\n<h3 id=\"required-parameters\"><a href=\"#required-parameters\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Required parameters</h3>\n<ul>\n<li><code class=\"language-text\">--model-class</code> , <code class=\"language-text\">--model-name</code> -> One of these options must be passed with the full java class name to run, or the name the model was registed with respectively. </li>\n</ul>\n<p>Example:</p>\n<p class=\"code-header\">Model Registration</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\">    Server<span class=\"token punctuation\">.</span><span class=\"token function\">register</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Mortgage Tutorial\"</span><span class=\"token punctuation\">,</span> org<span class=\"token punctuation\">.</span>example<span class=\"token punctuation\">.</span>models<span class=\"token punctuation\">.</span>MortgageModel<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p class=\"code-header\">Running the model</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token comment\"># Running using the registered model name</span>\njava -jar target/simudyne-maven-java-2.1.0-SNAPSHOT.jar --model-name <span class=\"token string\">\"Morgage Tutorial\"</span> <span class=\"token punctuation\">..</span>.Additional parameters<span class=\"token punctuation\">..</span>.\n\n<span class=\"token comment\"># Running using the model class</span>\njava -jar target/simudyne-maven-java-2.1.0-SNAPSHOT.jar --model-class <span class=\"token string\">\"org.example.models.MortgageModel.class\"</span> <span class=\"token punctuation\">..</span>.Additional parameters<span class=\"token punctuation\">..</span>.   </code></pre></div>\n<ul>\n<li><code class=\"language-text\">--input-path</code> -> In order to run a CLI runner, a directory must be passed containing files which specify the input fields to be set for some or all ticks. Each file in the specified directory will be used to run the model according to its configuration. If the directory does not contain any input files, the model will not run. Input files can be either csv or json format, and have to follow a specified structure to be run. </li>\n</ul>\n<h4 id=\"json-input-files\"><a href=\"#json-input-files\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>JSON input files</h4>\n<table class=\"ui basic table\">\n<thead>\n<tr>\n<th>Parameter</th>\n<th>Type</th>\n<th>Required</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<tr>\n<td>runs</td>\n<td>integer</td>\n<td></td>\n<td>Number of times to run this scenario. If this is not specified, the scenario will not run.</td>\n</tr>\n<tr>\n<td>seeds</td>\n<td>[long]</td>\n<td></td>\n<td>A list of seeds to set for the runs of this simulation.</td>\n</tr>\n<tr>\n<td>scenarioData</td>\n<td>object</td>\n<td>true</td>\n<td>Key value pairs of ticks to the inputs to set for those ticks</td>\n</tr>\n<tr>\n</tbody>\n</table>\n<p class=\"code-header\">ExampleInput.json</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"runs\"</span><span class=\"token operator\">:</span> <span class=\"token number\">23</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"seeds\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">123</span><span class=\"token punctuation\">,</span><span class=\"token number\">234</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> // <span class=\"token number\">123</span> and <span class=\"token number\">234</span> will be used as the seeds for the first two runs\n  <span class=\"token property\">\"scenarioData\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"2\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"nbHouseholds\"</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span> // nbHouseholds will be set to <span class=\"token number\">50</span> at the second tick\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"100\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> // run <span class=\"token number\">100</span> ticks (without setting any inputs after the second tick<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4 id=\"csv-input-files\"><a href=\"#csv-input-files\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>CSV input files</h4>\n<p>CSV input files can only be used to run single runs. The first column in the csv can be used to specify ticks, and the subsequent columns are input fields, so the values in those columns are the values to set for input fields at specific ticks. </p>\n<p class=\"code-header\">ExampleInput.csv</p>\n<div class=\"gatsby-highlight\" data-language=\"csv\"><pre class=\"language-csv\"><code class=\"language-csv\">tick,nbHouseholds\n1,200 // nbHouseholds will be set to 200 at the first tick\n2,250 // nbHouseholds will be set to 250 at the second tick\n100 // run 100 ticks (without setting any inputs after the second tick)</code></pre></div>\n<h3 id=\"optional-parameters\"><a href=\"#optional-parameters\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Optional parameters</h3>\n<ul>\n<li><code class=\"language-text\">--run-ID</code> -> A unique ID to identify this run. This ID will be used as a directory for output data.</li>\n<li><code class=\"language-text\">--output-path</code> -> The directory that data generated by these runs should be written to. If not specified, this will be the current directory.</li>\n<li><code class=\"language-text\">--custom-export-metadata</code> -> Custom JSON object that will be included in the metadata.json file as part of the data output. If not specified, no custom metadata will be added.</li>\n</ul>","headings":[{"value":"Preparing the model","depth":2},{"value":"Running the model","depth":2},{"value":"Required parameters","depth":3},{"value":"JSON input files","depth":4},{"value":"CSV input files","depth":4},{"value":"Optional parameters","depth":3}],"frontmatter":{"title":"CLI Model Runner","toc":null,"experimental":null}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.4/reference/run_mode/cli_run.md","versioned":true,"version":"2.4","kind":"reference","pagePath":"/reference/run_mode/cli_run","chronology":{"prev":{"name":"Multirun Output","path":"/reference/run_mode/multirun_output"},"next":{"name":"Test Kit","path":"/reference/test_kit"}},"lastUpdated":"2026-04-21T13:56:54.853Z"}}