RealTime.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Realtime Simulation &mdash; CBD Simulation Development Kit documentation</title>
  8. <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  9. <!-- <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> -->
  10. <link rel="stylesheet" href="../_static/style.css" type="text/css" />
  11. <link rel="index" title="Index" href="../genindex.html" />
  12. <link rel="search" title="Search" href="../search.html" />
  13. <link rel="next" title="Live Plotting of Data During the Simulation" href="LivePlot.html" />
  14. <link rel="prev" title="Linear Congruential Generator" href="LCG.html" />
  15. <script async src="https://www.googletagmanager.com/gtag/js?id=UA-167094275-1"></script>
  16. <script src="../_static/js/googleanalytics.min.js"></script>
  17. <script src="../_static/js/modernizr.min.js"></script>
  18. <!-- Preload the theme fonts -->
  19. <link rel="preload" href="../_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  20. <link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  21. <link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  22. <link rel="preload" href="../_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  23. <link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  24. <link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  25. <!-- Preload the katex fonts -->
  26. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  27. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  28. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  29. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  30. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  31. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  32. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  33. <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  34. </head>
  35. <div class="container-fluid header-holder tutorials-header" id="header-holder">
  36. <div class="container">
  37. <div class="header-container">
  38. <a class="header-logo" href="https://catalyst-team.com/" aria-label="Catalyst"></a>
  39. <div class="main-menu">
  40. <ul>
  41. <li>
  42. <div class="ecosystem-dropdown">
  43. <a id="dropdownMenuButtonEcosystem" data-toggle="ecosystem-dropdown">
  44. Ecosystem
  45. </a>
  46. <div class="ecosystem-dropdown-menu">
  47. <a class="nav-dropdown-item" href="https://alchemy.host">
  48. <span class=dropdown-title>Alchemy</span>
  49. <p>Experiments logging & visualization</p>
  50. </a>
  51. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/catalyst">
  52. <span class=dropdown-title>Catalyst</span>
  53. <p>Accelerated deep learning R&D</p>
  54. </a>
  55. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/reaction">
  56. <span class=dropdown-title>Reaction</span>
  57. <p>Convenient deep learning models serving</p>
  58. </a>
  59. </div>
  60. </div>
  61. </li>
  62. <li>
  63. <div class="projects-dropdown">
  64. <a id="dropdownMenuButtonProjects" data-toggle="projects-dropdown">
  65. Projects
  66. </a>
  67. <div class="projects-dropdown-menu">
  68. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/codestyle">
  69. <span class=dropdown-title>Codestyle</span>
  70. <p>Joint R&D codestyle</p>
  71. </a>
  72. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/neuro">
  73. <span class=dropdown-title>Catalyst.Neuro</span>
  74. <p>Catalyst.Team and TReNDS collaborative project</p>
  75. </a>
  76. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/classification">
  77. <span class=dropdown-title>Classification</span>
  78. <p>Image classification pipeline with transfer learning</p>
  79. </a>
  80. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/detection">
  81. <span class=dropdown-title>Detection</span>
  82. <p>Object detection pipeline</p>
  83. </a>
  84. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/segmentation">
  85. <span class=dropdown-title>Segmentation</span>
  86. <p>Image semantic segmentation pipeline</p>
  87. </a>
  88. <a class="nav-dropdown-item" href="https://github.com/catalyst-team/gan">
  89. <span class=dropdown-title>Catalyst.GAN</span>
  90. <p>GAN pipelines</p>
  91. </a>
  92. </div>
  93. </div>
  94. </li>
  95. <li>
  96. <a href="https://github.com/catalyst-team/dl-course">Deep learning course</a>
  97. </li>
  98. </ul>
  99. </div>
  100. <a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a>
  101. </div>
  102. </div>
  103. </div>
  104. <body class="catalyst-body">
  105. <div class="table-of-contents-link-wrapper">
  106. <span>Table of Contents</span>
  107. <a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
  108. </div>
  109. <nav data-toggle="wy-nav-shift" class="catalyst-left-menu" id="catalyst-left-menu">
  110. <div class="catalyst-side-scroll">
  111. <div class="catalyst-menu catalyst-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  112. <div class="catalyst-left-menu-search">
  113. <div role="search">
  114. <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
  115. <input type="text" name="q" placeholder="Search Docs" />
  116. <input type="hidden" name="check_keywords" value="yes" />
  117. <input type="hidden" name="area" value="default" />
  118. </form>
  119. </div>
  120. </div>
  121. <p class="caption"><span class="caption-text">Setup</span></p>
  122. <ul>
  123. <li class="toctree-l1"><a class="reference internal" href="../install.html">How to install the CBD framework?</a></li>
  124. <li class="toctree-l1"><a class="reference internal" href="../running.html">How to run a CBD simulation?</a></li>
  125. <li class="toctree-l1"><a class="reference internal" href="../changelog.html">Changelog</a></li>
  126. </ul>
  127. <p class="caption"><span class="caption-text">Simple Examples</span></p>
  128. <ul>
  129. <li class="toctree-l1"><a class="reference internal" href="SinGen.html">Sine Generator</a></li>
  130. <li class="toctree-l1"><a class="reference internal" href="EvenNumberGen.html">Hierarchical Even Number Generator</a></li>
  131. <li class="toctree-l1"><a class="reference internal" href="Fibonacci.html">Fibonacci Sequence Generator</a></li>
  132. <li class="toctree-l1"><a class="reference internal" href="LCG.html">Linear Congruential Generator</a></li>
  133. </ul>
  134. <p class="caption"><span class="caption-text">Advanced Examples</span></p>
  135. <ul class="current">
  136. <li class="toctree-l1 current"><a class="current reference internal" href="#">Realtime Simulation</a></li>
  137. <li class="toctree-l1"><a class="reference internal" href="LivePlot.html">Live Plotting of Data During the Simulation</a></li>
  138. </ul>
  139. <p class="caption"><span class="caption-text">Internal Documentation</span></p>
  140. <ul>
  141. <li class="toctree-l1"><a class="reference internal" href="../CBD.html">CBD package</a></li>
  142. </ul>
  143. </div>
  144. </div>
  145. </nav>
  146. <div class="catalyst-container">
  147. <div class="catalyst-page-level-bar" id="catalyst-page-level-bar">
  148. <div class="catalyst-breadcrumbs-wrapper">
  149. <div role="navigation" aria-label="breadcrumbs navigation">
  150. <ul class="catalyst-breadcrumbs">
  151. <li>
  152. <a href="../index.html">
  153. Docs
  154. </a> &gt;
  155. </li>
  156. <li>Realtime Simulation</li>
  157. <li class="catalyst-breadcrumbs-aside">
  158. </li>
  159. </ul>
  160. </div>
  161. </div>
  162. <div class="catalyst-shortcuts-wrapper" id="catalyst-shortcuts-wrapper">
  163. Shortcuts
  164. </div>
  165. </div>
  166. <section data-toggle="wy-nav-shift" id="catalyst-content-wrap" class="catalyst-content-wrap">
  167. <div class="catalyst-content-left">
  168. <div class="rst-content">
  169. <div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
  170. <article itemprop="articleBody" id="catalyst-article" class="catalyst-article">
  171. <div class="section" id="realtime-simulation">
  172. <h1>Realtime Simulation<a class="headerlink" href="#realtime-simulation" title="Permalink to this headline">¶</a></h1>
  173. <p>Besides normal (as-fast-as-possible) simulation, it is also possible to simulate CBD models in realtime. Here, the
  174. time (and therefore <cite>delta t</cite> as well) will be interpreted as seconds and the simulator will wait <strong>non-blocking</strong>
  175. until the required time has passed. There are several supported backend that provide this functionality. These
  176. backends are based on the backends provided by <a class="reference external" href="https://msdl.uantwerpen.be/documentation/PythonPDEVS/realtime.html">PyPDEVS</a>.</p>
  177. <p>While there doesn’t have to be feedback duing a simulation, the <a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setProgressBar" title="CBD.simulator.Simulator.setProgressBar"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setProgressBar()</span></code></a>
  178. function provides a <a class="reference external" href="https://tqdm.github.io/">tqdm progress bar</a>. When running long simulations, this might
  179. be a useful feature. Note that, when combined with a termination condition, the progress bar may yield inaccurate
  180. values.</p>
  181. <div class="admonition seealso">
  182. <p class="first admonition-title">See also</p>
  183. <ul class="last simple">
  184. <li>When using progress bars, <a class="reference external" href="https://tqdm.github.io/">tqdm</a> must be installed.</li>
  185. <li>In <a class="reference internal" href="LivePlot.html"><span class="doc">Live Plotting of Data During the Simulation</span></a>, realtime simulation is used together with a variation of the <a class="reference internal" href="SinGen.html"><span class="doc">Sine Generator</span></a> example.</li>
  186. </ul>
  187. </div>
  188. <div class="admonition attention">
  189. <p class="first admonition-title">Attention</p>
  190. <p class="last">In the future, there will be possibilities for interrupt events, similar to <a class="reference external" href="https://msdl.uantwerpen.be/documentation/PythonPDEVS/realtime.html">PyPDEVS</a>.</p>
  191. </div>
  192. <div class="section" id="example-model">
  193. <h2>Example Model<a class="headerlink" href="#example-model" title="Permalink to this headline">¶</a></h2>
  194. <p>To simplify the explanations of the following sections, we will be using the <a class="reference internal" href="SinGen.html"><span class="doc">Sine Generator</span></a> as a basis model.
  195. To recap:</p>
  196. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">CBD.CBD</span> <span class="kn">import</span> <span class="n">CBD</span>
  197. <span class="kn">from</span> <span class="nn">CBD.simulator</span> <span class="kn">import</span> <span class="n">Simulator</span>
  198. <span class="kn">from</span> <span class="nn">CBD.lib.std</span> <span class="kn">import</span> <span class="n">TimeBlock</span><span class="p">,</span> <span class="n">GenericBlock</span>
  199. <span class="kn">from</span> <span class="nn">CBD.lib.endpoints</span> <span class="kn">import</span> <span class="n">SignalCollectorBlock</span>
  200. <span class="k">class</span> <span class="nc">SinGen</span><span class="p">(</span><span class="n">CBD</span><span class="p">):</span>
  201. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;SinGen&quot;</span><span class="p">):</span>
  202. <span class="n">CBD</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">input_ports</span><span class="o">=</span><span class="p">[],</span> <span class="n">output_ports</span><span class="o">=</span><span class="p">[])</span>
  203. <span class="c1"># Create the blocks</span>
  204. <span class="bp">self</span><span class="o">.</span><span class="n">addBlock</span><span class="p">(</span><span class="n">TimeBlock</span><span class="p">(</span><span class="s2">&quot;time&quot;</span><span class="p">))</span>
  205. <span class="bp">self</span><span class="o">.</span><span class="n">addBlock</span><span class="p">(</span><span class="n">GenericBlock</span><span class="p">(</span><span class="s2">&quot;sin&quot;</span><span class="p">,</span> <span class="n">block_operator</span><span class="o">=</span><span class="s2">&quot;sin&quot;</span><span class="p">))</span>
  206. <span class="bp">self</span><span class="o">.</span><span class="n">addBlock</span><span class="p">(</span><span class="n">SignalCollectorBlock</span><span class="p">(</span><span class="s2">&quot;collector&quot;</span><span class="p">))</span>
  207. <span class="c1"># Connect the blocks</span>
  208. <span class="bp">self</span><span class="o">.</span><span class="n">addConnection</span><span class="p">(</span><span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="s2">&quot;sin&quot;</span><span class="p">)</span>
  209. <span class="bp">self</span><span class="o">.</span><span class="n">addConnection</span><span class="p">(</span><span class="s2">&quot;sin&quot;</span><span class="p">,</span> <span class="s2">&quot;collector&quot;</span><span class="p">)</span>
  210. <span class="n">sinGen</span> <span class="o">=</span> <span class="n">SinGen</span><span class="p">(</span><span class="s2">&quot;SinGen&quot;</span><span class="p">)</span>
  211. <span class="n">sim</span> <span class="o">=</span> <span class="n">Simulator</span><span class="p">(</span><span class="n">sinGen</span><span class="p">)</span>
  212. <span class="n">sim</span><span class="o">.</span><span class="n">setRealTime</span><span class="p">()</span>
  213. </pre></div>
  214. </div>
  215. <div class="admonition note">
  216. <p class="first admonition-title">Note</p>
  217. <p>Realtime simulation happens non-blocking. This means the <a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.run" title="CBD.simulator.Simulator.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.run()</span></code></a> method will be called
  218. asynchronously. Additionally, simulation runs as a daemon thread, so exiting the main thread will automatically
  219. terminate the simulation. To keep the script alive until after the simulation, you can use:</p>
  220. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">while</span> <span class="n">sim</span><span class="o">.</span><span class="n">is_running</span><span class="p">():</span>
  221. <span class="k">pass</span>
  222. </pre></div>
  223. </div>
  224. <div class="last line-block">
  225. <div class="line"><br /></div>
  226. </div>
  227. </div>
  228. </div>
  229. <div class="section" id="python-threading-backend">
  230. <h2>Python Threading Backend<a class="headerlink" href="#python-threading-backend" title="Permalink to this headline">¶</a></h2>
  231. <p>The threading (or Python) backend/platform will use the <code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code> module for delaying the simulation steps.
  232. This is the default simulation backend.</p>
  233. <div class="admonition warning">
  234. <p class="first admonition-title">Warning</p>
  235. <p class="last">Python threads can sometimes have a rather low granularity in CPython 2. So while we are simulating in soft
  236. realtime anyway, it is important to note that delays could potentially become significant.</p>
  237. </div>
  238. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">sim</span><span class="o">.</span><span class="n">setRealTimePlatformThreading</span><span class="p">()</span>
  239. <span class="n">sim</span><span class="o">.</span><span class="n">setDeltaT</span><span class="p">(</span><span class="mf">0.3</span><span class="p">)</span>
  240. <span class="n">sim</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="mf">100.0</span><span class="p">)</span>
  241. <span class="c1"># Keep it alive</span>
  242. <span class="k">while</span> <span class="n">sim</span><span class="o">.</span><span class="n">is_running</span><span class="p">():</span> <span class="k">pass</span>
  243. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FINISHED!&quot;</span><span class="p">)</span>
  244. </pre></div>
  245. </div>
  246. <div class="admonition seealso">
  247. <p class="first admonition-title">See also</p>
  248. <ul class="last simple">
  249. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setRealTimePlatform" title="CBD.simulator.Simulator.setRealTimePlatform"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setRealTimePlatform()</span></code></a></li>
  250. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setRealTimePlatformThreading" title="CBD.simulator.Simulator.setRealTimePlatformThreading"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setRealTimePlatformThreading()</span></code></a></li>
  251. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.is_running" title="CBD.simulator.Simulator.is_running"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.is_running()</span></code></a></li>
  252. </ul>
  253. </div>
  254. </div>
  255. <div class="section" id="tkinter-backend">
  256. <h2>TkInter Backend<a class="headerlink" href="#tkinter-backend" title="Permalink to this headline">¶</a></h2>
  257. <p>The <a class="reference external" href="https://docs.python.org/3/library/tkinter.html">TkInter</a> event loop can become quite complex, as it is
  258. required to interface to the GUI as wel as to the simulation. Luckily, this backend will wrap all the complexity
  259. into a white box. It is, however, required to define the GUI application and start the mainloop, but afterwards,
  260. all will be handled for you.</p>
  261. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">tkinter</span> <span class="k">as</span> <span class="nn">tk</span>
  262. <span class="n">root</span> <span class="o">=</span> <span class="n">tk</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
  263. <span class="n">sim</span><span class="o">.</span><span class="n">setRealTimePlatformTk</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
  264. <span class="n">sim</span><span class="o">.</span><span class="n">setDeltaT</span><span class="p">(</span><span class="mf">0.3</span><span class="p">)</span>
  265. <span class="n">sim</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="mf">100.0</span><span class="p">)</span>
  266. <span class="n">root</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>
  267. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FINISHED!&quot;</span><span class="p">)</span>
  268. </pre></div>
  269. </div>
  270. <div class="admonition seealso">
  271. <p class="first admonition-title">See also</p>
  272. <ul class="last simple">
  273. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setRealTimePlatform" title="CBD.simulator.Simulator.setRealTimePlatform"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setRealTimePlatform()</span></code></a></li>
  274. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setRealTimePlatformTk" title="CBD.simulator.Simulator.setRealTimePlatformTk"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setRealTimePlatformTk()</span></code></a></li>
  275. </ul>
  276. </div>
  277. </div>
  278. <div class="section" id="gameloop-backend">
  279. <h2>GameLoop Backend<a class="headerlink" href="#gameloop-backend" title="Permalink to this headline">¶</a></h2>
  280. <p>Whenever it is required to control the invocation of delays from another execution loop, like e.g. a gameloop,
  281. it is pertinent to make use of the <cite>GameLoop</cite> backend. Delays won’t happen internally anymore, as they should be
  282. handled by the execution loop. By making use of the <a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.realtime_gameloop_call" title="CBD.simulator.Simulator.realtime_gameloop_call"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.realtime_gameloop_call()</span></code></a>, the
  283. simulation can advance to the next timestep.</p>
  284. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">sim</span><span class="o">.</span><span class="n">setRealTimePlatformGameLoop</span><span class="p">()</span>
  285. <span class="n">sim</span><span class="o">.</span><span class="n">setDeltaT</span><span class="p">(</span><span class="mf">0.3</span><span class="p">)</span>
  286. <span class="n">sim</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="mf">100.0</span><span class="p">)</span>
  287. <span class="k">while</span> <span class="n">sim</span><span class="o">.</span><span class="n">is_running</span><span class="p">():</span>
  288. <span class="c1"># do some fancy computations</span>
  289. <span class="o">...</span>
  290. <span class="c1"># do some rendering</span>
  291. <span class="o">...</span>
  292. <span class="c1"># advance the model&#39;s state</span>
  293. <span class="n">sim</span><span class="o">.</span><span class="n">realtime_gameloop_call</span><span class="p">()</span>
  294. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;FINISHED!&quot;</span><span class="p">)</span>
  295. </pre></div>
  296. </div>
  297. <div class="admonition seealso">
  298. <p class="first admonition-title">See also</p>
  299. <ul class="last simple">
  300. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setRealTimePlatform" title="CBD.simulator.Simulator.setRealTimePlatform"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setRealTimePlatform()</span></code></a></li>
  301. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.setRealTimePlatformGameLoop" title="CBD.simulator.Simulator.setRealTimePlatformGameLoop"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.setRealTimePlatformGameLoop()</span></code></a></li>
  302. <li><a class="reference internal" href="../CBD.simulator.html#CBD.simulator.Simulator.realtime_gameloop_call" title="CBD.simulator.Simulator.realtime_gameloop_call"><code class="xref py py-func docutils literal notranslate"><span class="pre">CBD.simulator.Simulator.realtime_gameloop_call()</span></code></a></li>
  303. </ul>
  304. </div>
  305. </div>
  306. </div>
  307. </article>
  308. </div>
  309. <footer>
  310. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  311. <a href="LivePlot.html" class="btn btn-neutral float-right" title="Live Plotting of Data During the Simulation" accesskey="n" rel="next">Next <img src="../_static/images/chevron-right-orange.svg" class="next-page"></a>
  312. <a href="LCG.html" class="btn btn-neutral" title="Linear Congruential Generator" accesskey="p" rel="prev"><img src="../_static/images/chevron-right-orange.svg" class="previous-page"> Previous</a>
  313. </div>
  314. <hr>
  315. <div role="contentinfo">
  316. <p>
  317. &copy; Copyright 2020, Randy Paredis.
  318. </p>
  319. </div>
  320. <div>
  321. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  322. </div>
  323. </footer>
  324. </div>
  325. </div>
  326. <div class="catalyst-content-right" id="catalyst-content-right">
  327. <div class="catalyst-right-menu" id="catalyst-right-menu">
  328. <div class="catalyst-side-scroll" id="catalyst-side-scroll-right">
  329. <ul>
  330. <li><a class="reference internal" href="#">Realtime Simulation</a><ul>
  331. <li><a class="reference internal" href="#example-model">Example Model</a></li>
  332. <li><a class="reference internal" href="#python-threading-backend">Python Threading Backend</a></li>
  333. <li><a class="reference internal" href="#tkinter-backend">TkInter Backend</a></li>
  334. <li><a class="reference internal" href="#gameloop-backend">GameLoop Backend</a></li>
  335. </ul>
  336. </li>
  337. </ul>
  338. </div>
  339. </div>
  340. </div>
  341. </section>
  342. </div>
  343. <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
  344. <script type="text/javascript" src="../_static/jquery.js"></script>
  345. <script type="text/javascript" src="../_static/underscore.js"></script>
  346. <script type="text/javascript" src="../_static/doctools.js"></script>
  347. <script type="text/javascript" src="../_static/language_data.js"></script>
  348. <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  349. <script type="text/javascript" src="../_static/js/vendor/popper.min.js"></script>
  350. <script type="text/javascript" src="../_static/js/vendor/bootstrap.min.js"></script>
  351. <script type="text/javascript" src="../_static/js/theme.js"></script>
  352. <script type="text/javascript">
  353. jQuery(function () {
  354. SphinxRtdTheme.Navigation.enable(true);
  355. });
  356. </script>
  357. <!-- Begin Footer -->
  358. <footer class="site-footer" id="site-footer">
  359. <div class="container footer-container">
  360. <div class="footer-logo-wrapper">
  361. <a href="https://catalyst-team.com/" class="footer-logo"></a>
  362. </div>
  363. <div class="footer-links-wrapper">
  364. <div class="footer-links-col">
  365. <ul>
  366. <li class="list-title"><a href="https://github.com/catalyst-team">Ecosystem</a></li>
  367. <li><a class="nav-dropdown-item" href="https://alchemy.host">Alchemy</a></li>
  368. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/catalyst">Catalyst</a></li>
  369. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/reaction">Reaction</a></li>
  370. </ul>
  371. </div>
  372. <div class="footer-links-col">
  373. <ul>
  374. <li class="list-title"><a href="https://github.com/catalyst-team">Projects</a></li>
  375. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/codestyle">Codestyle</a></li>
  376. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/neuro">Catalyst.Neuro</a></li>
  377. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/classification">Classification</a></li>
  378. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/detection">Detection</a></li>
  379. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/segmentation">Segmentation</a></li>
  380. <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/gan">Catalyst.GAN</a></li>
  381. </ul>
  382. </div>
  383. <div class="footer-links-col">
  384. <ul>
  385. <li class="list-title"><a href="https://catalyst-team.com/">Support</a></li>
  386. <li><a href="https://github.com/catalyst-team/catalyst/issues" target="_blank">Github Issues</a></li>
  387. <li><a href="https://github.com/catalyst-team/catalyst/blob/master/CONTRIBUTING.md" target="_blank">Contributing</a></li>
  388. <li><a href="https://www.patreon.com/catalyst_team" target="_blank">Patreon</a></li>
  389. </ul>
  390. </div>
  391. <div class="footer-links-col follow-us-col">
  392. <div class="footer-social-icons">
  393. <a href="https://t.me/catalyst_team" target="_blank" class="telegram"></a>
  394. <a href="https://twitter.com/catalyst_core" target="_blank" class="twitter"></a>
  395. <a href="https://join.slack.com/t/catalyst-team-core/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw" target="_blank" class="ods"></a>
  396. </div>
  397. </div>
  398. </div>
  399. </div>
  400. </footer>
  401. <!-- End Footer -->
  402. <!-- Begin Mobile Menu -->
  403. <div class="mobile-main-menu">
  404. <div class="container-fluid">
  405. <div class="container">
  406. <div class="mobile-main-menu-header-container">
  407. <a class="header-logo" href="https://catalyst-team.com/" aria-label="Catalyst"></a>
  408. <a class="main-menu-close-button" href="#" data-behavior="close-mobile-menu"></a>
  409. </div>
  410. </div>
  411. </div>
  412. <div class="mobile-main-menu-links-container">
  413. <div class="main-menu">
  414. <ul>
  415. <li>
  416. <a href="">Get Started</a>
  417. </li>
  418. <li>
  419. <a href="https://github.com/catalyst-team/catalyst">Github</a>
  420. </li>
  421. </ul>
  422. </div>
  423. </div>
  424. </div>
  425. <!-- End Mobile Menu -->
  426. <script type="text/javascript" src="../_static/js/vendor/anchor.min.js"></script>
  427. <script type="text/javascript">
  428. $(document).ready(function() {
  429. mobileMenu.bind();
  430. mobileTOC.bind();
  431. catalystAnchors.bind();
  432. sideMenus.bind();
  433. scrollToAnchor.bind();
  434. highlightNavigation.bind();
  435. mainMenuDropdown.bind();
  436. // Add class to links that have code blocks, since we cannot create links in code blocks
  437. $("article.catalyst-article a span.pre").each(function(e) {
  438. $(this).closest("a").addClass("has-code");
  439. });
  440. })
  441. </script>
  442. </body>
  443. </html>