%% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[a4paper,11pt,english]{sphinxmanual}
\ifdefined\pdfpxdimen
   \let\sphinxpxdimen\pdfpxdimen\else\newdimen\sphinxpxdimen
\fi \sphinxpxdimen=.75bp\relax

\PassOptionsToPackage{warn}{textcomp}
\usepackage[utf8]{inputenc}
\ifdefined\DeclareUnicodeCharacter
% support both utf8 and utf8x syntaxes
  \ifdefined\DeclareUnicodeCharacterAsOptional
    \def\sphinxDUC#1{\DeclareUnicodeCharacter{"#1}}
  \else
    \let\sphinxDUC\DeclareUnicodeCharacter
  \fi
  \sphinxDUC{00A0}{\nobreakspace}
  \sphinxDUC{2500}{\sphinxunichar{2500}}
  \sphinxDUC{2502}{\sphinxunichar{2502}}
  \sphinxDUC{2514}{\sphinxunichar{2514}}
  \sphinxDUC{251C}{\sphinxunichar{251C}}
  \sphinxDUC{2572}{\textbackslash}
\fi
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amstext}
\usepackage{babel}



\usepackage{times}
\expandafter\ifx\csname T@LGR\endcsname\relax
\else
% LGR was declared as font encoding
  \substitutefont{LGR}{\rmdefault}{cmr}
  \substitutefont{LGR}{\sfdefault}{cmss}
  \substitutefont{LGR}{\ttdefault}{cmtt}
\fi
\expandafter\ifx\csname T@X2\endcsname\relax
  \expandafter\ifx\csname T@T2A\endcsname\relax
  \else
  % T2A was declared as font encoding
    \substitutefont{T2A}{\rmdefault}{cmr}
    \substitutefont{T2A}{\sfdefault}{cmss}
    \substitutefont{T2A}{\ttdefault}{cmtt}
  \fi
\else
% X2 was declared as font encoding
  \substitutefont{X2}{\rmdefault}{cmr}
  \substitutefont{X2}{\sfdefault}{cmss}
  \substitutefont{X2}{\ttdefault}{cmtt}
\fi


\usepackage[Bjornstrup]{fncychap}
\usepackage{sphinx}

\fvset{fontsize=\small}
\usepackage{geometry}


% Include hyperref last.
\usepackage{hyperref}
% Fix anchor placement for figures with captions.
\usepackage{hypcap}% it must be loaded after hyperref.
% Set up styles of URL: it should be placed after hyperref.
\urlstyle{same}

\addto\captionsenglish{\renewcommand{\contentsname}{Introduction}}

\usepackage{sphinxmessages}
\setcounter{tocdepth}{2}


% Jupyter Notebook code cell colors
\definecolor{nbsphinxin}{HTML}{307FC1}
\definecolor{nbsphinxout}{HTML}{BF5B3D}
\definecolor{nbsphinx-code-bg}{HTML}{F5F5F5}
\definecolor{nbsphinx-code-border}{HTML}{E0E0E0}
\definecolor{nbsphinx-stderr}{HTML}{FFDDDD}
% ANSI colors for output streams and traceback highlighting
\definecolor{ansi-black}{HTML}{3E424D}
\definecolor{ansi-black-intense}{HTML}{282C36}
\definecolor{ansi-red}{HTML}{E75C58}
\definecolor{ansi-red-intense}{HTML}{B22B31}
\definecolor{ansi-green}{HTML}{00A250}
\definecolor{ansi-green-intense}{HTML}{007427}
\definecolor{ansi-yellow}{HTML}{DDB62B}
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
\definecolor{ansi-blue}{HTML}{208FFB}
\definecolor{ansi-blue-intense}{HTML}{0065CA}
\definecolor{ansi-magenta}{HTML}{D160C4}
\definecolor{ansi-magenta-intense}{HTML}{A03196}
\definecolor{ansi-cyan}{HTML}{60C6C8}
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
\definecolor{ansi-white}{HTML}{C5C1B4}
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF}
\definecolor{ansi-default-inverse-bg}{HTML}{000000}

% Define an environment for non-plain-text code cell outputs (e.g. images)
\makeatletter
\newenvironment{nbsphinxfancyoutput}{%
    % Avoid fatal error with framed.sty if graphics too long to fit on one page
    \let\sphinxincludegraphics\nbsphinxincludegraphics
    \nbsphinx@image@maxheight\textheight
    \advance\nbsphinx@image@maxheight -2\fboxsep   % default \fboxsep 3pt
    \advance\nbsphinx@image@maxheight -2\fboxrule  % default \fboxrule 0.4pt
    \advance\nbsphinx@image@maxheight -\baselineskip
\def\nbsphinxfcolorbox{\spx@fcolorbox{nbsphinx-code-border}{white}}%
\def\FrameCommand{\nbsphinxfcolorbox\nbsphinxfancyaddprompt\@empty}%
\def\FirstFrameCommand{\nbsphinxfcolorbox\nbsphinxfancyaddprompt\sphinxVerbatim@Continues}%
\def\MidFrameCommand{\nbsphinxfcolorbox\sphinxVerbatim@Continued\sphinxVerbatim@Continues}%
\def\LastFrameCommand{\nbsphinxfcolorbox\sphinxVerbatim@Continued\@empty}%
\MakeFramed{\advance\hsize-\width\@totalleftmargin\z@\linewidth\hsize\@setminipage}%
\lineskip=1ex\lineskiplimit=1ex\raggedright%
}{\par\unskip\@minipagefalse\endMakeFramed}
\makeatother
\newbox\nbsphinxpromptbox
\def\nbsphinxfancyaddprompt{\ifvoid\nbsphinxpromptbox\else
    \kern\fboxrule\kern\fboxsep
    \copy\nbsphinxpromptbox
    \kern-\ht\nbsphinxpromptbox\kern-\dp\nbsphinxpromptbox
    \kern-\fboxsep\kern-\fboxrule\nointerlineskip
    \fi}
\newlength\nbsphinxcodecellspacing
\setlength{\nbsphinxcodecellspacing}{0pt}

% Define support macros for attaching opening and closing lines to notebooks
\newsavebox\nbsphinxbox
\makeatletter
\newcommand{\nbsphinxstartnotebook}[1]{%
    \par
    % measure needed space
    \setbox\nbsphinxbox\vtop{{#1\par}}
    % reserve some space at bottom of page, else start new page
    \needspace{\dimexpr2.5\baselineskip+\ht\nbsphinxbox+\dp\nbsphinxbox}
    % mimick vertical spacing from \section command
      \addpenalty\@secpenalty
      \@tempskipa 3.5ex \@plus 1ex \@minus .2ex\relax
      \addvspace\@tempskipa
      {\Large\@tempskipa\baselineskip
             \advance\@tempskipa-\prevdepth
             \advance\@tempskipa-\ht\nbsphinxbox
             \ifdim\@tempskipa>\z@
               \vskip \@tempskipa
             \fi}
    \unvbox\nbsphinxbox
    % if notebook starts with a \section, prevent it from adding extra space
    \@nobreaktrue\everypar{\@nobreakfalse\everypar{}}%
    % compensate the parskip which will get inserted by next paragraph
    \nobreak\vskip-\parskip
    % do not break here
    \nobreak
}% end of \nbsphinxstartnotebook

\newcommand{\nbsphinxstopnotebook}[1]{%
    \par
    % measure needed space
    \setbox\nbsphinxbox\vbox{{#1\par}}
    \nobreak % it updates page totals
    \dimen@\pagegoal
    \advance\dimen@-\pagetotal \advance\dimen@-\pagedepth
    \advance\dimen@-\ht\nbsphinxbox \advance\dimen@-\dp\nbsphinxbox
    \ifdim\dimen@<\z@
      % little space left
      \unvbox\nbsphinxbox
      \kern-.8\baselineskip
      \nobreak\vskip\z@\@plus1fil
      \penalty100
      \vskip\z@\@plus-1fil
      \kern.8\baselineskip
    \else
      \unvbox\nbsphinxbox
    \fi
}% end of \nbsphinxstopnotebook

% Ensure height of an included graphics fits in nbsphinxfancyoutput frame
\newdimen\nbsphinx@image@maxheight % set in nbsphinxfancyoutput environment
\newcommand*{\nbsphinxincludegraphics}[2][]{%
    \gdef\spx@includegraphics@options{#1}%
    \setbox\spx@image@box\hbox{\includegraphics[#1,draft]{#2}}%
    \in@false
    \ifdim \wd\spx@image@box>\linewidth
      \g@addto@macro\spx@includegraphics@options{,width=\linewidth}%
      \in@true
    \fi
    % no rotation, no need to worry about depth
    \ifdim \ht\spx@image@box>\nbsphinx@image@maxheight
      \g@addto@macro\spx@includegraphics@options{,height=\nbsphinx@image@maxheight}%
      \in@true
    \fi
    \ifin@
      \g@addto@macro\spx@includegraphics@options{,keepaspectratio}%
    \fi
    \setbox\spx@image@box\box\voidb@x % clear memory
    \expandafter\includegraphics\expandafter[\spx@includegraphics@options]{#2}%
}% end of "\MakeFrame"-safe variant of \sphinxincludegraphics
\makeatother

\makeatletter
\renewcommand*\sphinx@verbatim@nolig@list{\do\'\do\`}
\begingroup
\catcode`'=\active
\let\nbsphinx@noligs\@noligs
\g@addto@macro\nbsphinx@noligs{\let'\PYGZsq}
\endgroup
\makeatother
\renewcommand*\sphinxbreaksbeforeactivelist{\do\<\do\"\do\'}
\renewcommand*\sphinxbreaksafteractivelist{\do\.\do\,\do\:\do\;\do\?\do\!\do\/\do\>\do\-}
\makeatletter
\fvset{codes*=\sphinxbreaksattexescapedchars\do\^\^\let\@noligs\nbsphinx@noligs}
\makeatother


\setcounter{tocdepth}{2}

% Fix for allowing to show unicode delta character 
% See also option 'textgreek' in latex_elements
% (https://www.sphinx-doc.org/en/master/latex.html#latex-elements-confval)
\DeclareUnicodeCharacter{0394}{\ensuremath{\Delta}}

% another fix for minimal length bug
\setlength{\headheight}{14pt} % https://tex.stackexchange.com/a/198694

% another fix for very long equations
\allowdisplaybreaks % https://tex.stackexchange.com/a/51883


\title{PyAnalog}
\date{Jan 04, 2024}
\release{}
\author{The Analog People}
\newcommand{\sphinxlogo}{\vbox{}}
\renewcommand{\releasename}{}
\makeindex
\begin{document}

\pagestyle{empty}
\sphinxmaketitle
\pagestyle{plain}
\sphinxtableofcontents
\pagestyle{normal}
\phantomsection\label{\detokenize{index::doc}}


\section*{Abstract and Summary of PyAnalog}

\sphinxcode{\sphinxupquote{pyanalog}} is a \sphinxhref{https://www.python.org/}{Python3}%
\begin{footnote}[1]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.python.org/}
%
\end{footnote} package and
demonstrator/research code for a software stack for analog computers.
It empowers users to
\begin{itemize}
\item {} 
manipulate ordinary differential equations in a way suitable for
procession with the exemplary
\sphinxhref{http://analogparadigm.com/}{Analog Paradigm Model\sphinxhyphen{}1}%
\begin{footnote}[2]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/}
%
\end{footnote}
analog computer or similar \sphinxstyleemphasis{high\sphinxhyphen{}level} architectures in terms of
OpAmp\sphinxhyphen{}Level circuit description (\sphinxstyleemphasis{not} SPICE\sphinxhyphen{}level circuit description).

\item {} 
simulate abstract computing circuits made of elements such as
\sphinxstyleemphasis{summers, integrators, differentiator and multipliers}. The heart of the code is
a {\hyperref[\detokenize{dda/cpp-codegen:cpp-codegen}]{\sphinxcrossref{\DUrole{std,std-ref}{custom ODE solver (based on C++ codegeneration)}}}} (\autopageref*{\detokenize{dda/cpp-codegen:cpp-codegen}}),
but also interfaces to {\hyperref[\detokenize{dda/scipy:dda-scipy}]{\sphinxcrossref{\DUrole{std,std-ref}{SciPy}}}} (\autopageref*{\detokenize{dda/scipy:dda-scipy}}) and {\hyperref[\detokenize{dda/cas:cas}]{\sphinxcrossref{\DUrole{std,std-ref}{SymPy}}}} (\autopageref*{\detokenize{dda/cas:cas}})
solvers exist. Notably, the C++ solver can also solve integro\sphinxhyphen{}differential
equations.

\item {} 
generate and manipulate
{\hyperref[\detokenize{fpaa/fpaa:fpaa}]{\sphinxcrossref{\DUrole{std,std-ref}{netlists and VHDL\sphinxhyphen{}like circuit descriptions}}}} (\autopageref*{\detokenize{fpaa/fpaa:fpaa}})

\item {} 
compile against machine architectures on a macrocell\sphinxhyphen{}level,
set digital potentiometer arrays, cross bar switches, digital switches,
etc.

\item {} 
{\hyperref[\detokenize{hycon/hycon:hycon}]{\sphinxcrossref{\DUrole{std,std-ref}{interface a Model\sphinxhyphen{}1 hybrid controller}}}} (\autopageref*{\detokenize{hycon/hycon:hycon}}) in order to run
a program, steer the operation, gain and visualize/postprocess output data.

\end{itemize}

The codes are supposed to work well in the
\sphinxhref{https://www.scipy.org/}{Scientific Python}%
\begin{footnote}[3]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.scipy.org/}
%
\end{footnote} ecosystem. The target
audience are clearly software engineers and scientists. The user
interface is either command line (bash or python shell) or scripting
(Python or C/YAML\sphinxhyphen{}like domain specific languages). This code can
interface with remote analog computers (AAAS \textendash{} \sphinxstyleemphasis{analog computing
as a service}).

The \sphinxcode{\sphinxupquote{pyanalog}} code is open\sphinxhyphen{}source and a \sphinxstyleemphasis{research code which is worked
actively on}, ie. it is “work in progress”. It is authored
\sphinxhref{http://www.anabrid.com}{Anabrid GmbH}%
\begin{footnote}[4]\sphinxAtStartFootnote
\sphinxnolinkurl{http://www.anabrid.com}
%
\end{footnote}. The code is currently
dual\sphinxhyphen{}licensed by \sphinxhref{https://github.com/anabrid/pyanalog/blob/master/LICENSE.GPL3}{GPL\sphinxhyphen{}3}%
\begin{footnote}[5]\sphinxAtStartFootnote
\sphinxnolinkurl{https://github.com/anabrid/pyanalog/blob/master/LICENSE.GPL3}
%
\end{footnote}
and \sphinxhref{https://github.com/anabrid/pyanalog/blob/master/LICENSE.ANABRID}{a proprietary/commercial use license}%
\begin{footnote}[6]\sphinxAtStartFootnote
\sphinxnolinkurl{https://github.com/anabrid/pyanalog/blob/master/LICENSE.ANABRID}
%
\end{footnote}.
See \sphinxurl{http://www.anabrid.com/licensing} for further details.

\chapter{Introduction}


\section{Overview of PyAnalog}
\label{\detokenize{overview:overview-of-pyanalog}}\label{\detokenize{overview:overview}}\label{\detokenize{overview::doc}}

\subsection{The big picture}
\label{\detokenize{overview:the-big-picture}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
Input: Ordinary Differential Equation in mathematical notation
       (for instance in SymPy, Sage, Matlab, Latex, etc.)
     |
     v

PyDDA: Generation of a circuit
     |
  +\PYGZhy{}\PYGZhy{}+\PYGZhy{}\PYGZhy{}\PYGZhy{}+   Several backends to deal with the
  |  |   |   circuits, for instance:
  | ...  |
  |      +\PYGZhy{}\PYGZhy{}\PYGZgt{} Simulation with numerics (C++ or SciPy/Netlib ODE solver)
  |
  v

PyFPAA:  Circuit synthesis (=mapping) with based on architecture
         description.
  |
  |
  v

PyHyCon: Interaction with Analog\PYGZhy{}as\PYGZhy{}a\PYGZhy{}service
         (SSH to the small analog machine in Bernds basement)
  |
  v

Output: Measurement data from all relevant fields
\end{sphinxVerbatim}


\subsection{The particular python modules}
\label{\detokenize{overview:the-particular-python-modules}}
First and foremost, this documentation is an API documentation.
Therefore, it mostly covers the functions and classes exposed
by the following three python modules:
\begin{itemize}
\item {} 
{\hyperref[\detokenize{dda/intro:dda-intro}]{\sphinxcrossref{\DUrole{std,std-ref}{PyDDA}}}} (\autopageref*{\detokenize{dda/intro:dda-intro}}) is a tool for simple algebraic transformations of equations
and circuits as well as their numerical simulation.
DDA stands for \sphinxstyleemphasis{Digital Differential Analyzer}.

\item {} 
{\hyperref[\detokenize{fpaa/fpaa:fpaa}]{\sphinxcrossref{\DUrole{std,std-ref}{PyFPAA}}}} (\autopageref*{\detokenize{fpaa/fpaa:fpaa}}) is a tool for compiling an electrical circuit to a machine
architecture. This especially programs digital potentiometers and
cross bar switches and relies on a minimalistic hardware description
language (HDL) written in YAML.
FPAA stands for \sphinxstyleemphasis{Field Programmable Analog Array}.

\item {} 
{\hyperref[\detokenize{hycon/hycon:hycon}]{\sphinxcrossref{\DUrole{std,std-ref}{PyHyCon}}}} (\autopageref*{\detokenize{hycon/hycon:hycon}}) is an interface to a Model\sphinxhyphen{}1 \sphinxstyleemphasis{Hybrid Controller} in order to
run a program, steer the operation and gain output data.

\end{itemize}

You can read more about the goals of this software at the page
{\hyperref[\detokenize{dda/rationale:dda-rationale}]{\sphinxcrossref{\DUrole{std,std-ref}{A rationale about DDA}}}} (\autopageref*{\detokenize{dda/rationale:dda-rationale}}).

\begin{sphinxadmonition}{note}{Note:}
Currently, the DDA code is by far the biggest part of the pyanalog package.
The Hybrid Controller client is also usable. The FPAA part is working on its
own and there are interfaces to the PyHyCon, however the interface between
DDA and FPAA is basically nonexistent in the moment.
\end{sphinxadmonition}


\section{Obtaining and installing PyAnalog}
\label{\detokenize{installation:obtaining-and-installing-pyanalog}}\label{\detokenize{installation:installation}}\label{\detokenize{installation::doc}}
PyAnalog can be used on a “vanilla” Python installation without any dependencies.
Only make sure you use a \sphinxstyleemphasis{recent} Python 3 installation:
We use \sphinxhref{https://docs.python.org/3.6/whatsnew/3.6.html\#whatsnew36-pep498}{f\sphinxhyphen{}strings}%
\begin{footnote}[7]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.python.org/3.6/whatsnew/3.6.html\#whatsnew36-pep498}
%
\end{footnote},
so at least \sphinxstyleemphasis{Python 3.6} is required.

In order to use some of the advanced features, we recommend to install the following
Python packages:
\begin{itemize}
\item {} 
\sphinxhref{https://pyyaml.org/}{PyYAML}%
\begin{footnote}[8]\sphinxAtStartFootnote
\sphinxnolinkurl{https://pyyaml.org/}
%
\end{footnote}, for the intended usage of {\hyperref[\detokenize{fpaa/fpaa:fpaa}]{\sphinxcrossref{\DUrole{std,std-ref}{PyFPAA}}}} (\autopageref*{\detokenize{fpaa/fpaa:fpaa}})

\item {} 
\sphinxhref{https://www.sympy.org/}{SymPy}%
\begin{footnote}[9]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.sympy.org/}
%
\end{footnote}, for the {\hyperref[\detokenize{dda/cas:cas}]{\sphinxcrossref{\DUrole{std,std-ref}{SymPy/Computer Algebra interface}}}} (\autopageref*{\detokenize{dda/cas:cas}}) of PyDDA

\item {} 
\sphinxhref{http://www.scipy.org/}{SciPy}%
\begin{footnote}[10]\sphinxAtStartFootnote
\sphinxnolinkurl{http://www.scipy.org/}
%
\end{footnote}, for the {\hyperref[\detokenize{dda/scipy:dda-scipy}]{\sphinxcrossref{\DUrole{std,std-ref}{SciPy interface}}}} (\autopageref*{\detokenize{dda/scipy:dda-scipy}}) of PyDDA.
Furthermore, some additioanl postprocessing tools, as well as unit tests and examples of PyDDA
require \sphinxhref{https://numpy.org/}{NumPy}%
\begin{footnote}[11]\sphinxAtStartFootnote
\sphinxnolinkurl{https://numpy.org/}
%
\end{footnote} and \sphinxhref{https://matplotlib.org/}{Matplotlib}%
\begin{footnote}[12]\sphinxAtStartFootnote
\sphinxnolinkurl{https://matplotlib.org/}
%
\end{footnote} to be installed.

\end{itemize}

The code is primarily developed on Linux, but has also been used successfully on Mac OS X
and even Microsoft Windows. If you run one of these platforms and never got in contact to
Python coding there yet, the following guides and tips can be helpful for getting a
PyAnalog running on Mac or Windows.


\subsection{Obtaining the code}
\label{\detokenize{installation:obtaining-the-code}}
The PyAnalog code is public available at \sphinxurl{https://github.com/anabrid/pyanalog}.
Furthermore, we maintain an in\sphinxhyphen{}house (private) mirror at
\sphinxurl{https://lab.analogparadigm.com/software/pyanalog}. You don’t need access to the later repository
right now.

\begin{sphinxadmonition}{note}{Note:}
We try to keep the \sphinxhref{https://github.com/anabrid/pyanalog/commits/master}{master branch}%
\begin{footnote}[13]\sphinxAtStartFootnote
\sphinxnolinkurl{https://github.com/anabrid/pyanalog/commits/master}
%
\end{footnote}
in a working condition. If things do not work, you might want to checkout the last
working commit in the master. You can recognize it
\sphinxhref{https://github.com/anabrid/pyanalog/commits/master}{at the github commit history}%
\begin{footnote}[14]\sphinxAtStartFootnote
\sphinxnolinkurl{https://github.com/anabrid/pyanalog/commits/master}
%
\end{footnote}
where there is a green checkmark at the tests (and not a red crossmark).
I promise there will be releases/versions/tags soon :\sphinxhyphen{})
\end{sphinxadmonition}


\subsection{Mac OS X\sphinxhyphen{}specific installation notes}
\label{\detokenize{installation:mac-os-x-specific-installation-notes}}
First, make sure you have some (recent) Python 3 installed on your machine. You can
check by opening a terminal and executing \sphinxcode{\sphinxupquote{python \sphinxhyphen{}\sphinxhyphen{}version}}. If still have installed
a very old version such as Python 2.7, you need to upgrade it.
There are \sphinxhref{https://docs.python-guide.org/starting/install3/osx/}{many guides in the web}%
\begin{footnote}[15]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.python-guide.org/starting/install3/osx/}
%
\end{footnote}.
It is likely that the manual installation of a newer Python version will give you two
Pythons installed on your system. In many situations, you have to call the more recent
version by invoking a command such as \sphinxcode{\sphinxupquote{python3}} in place of \sphinxcode{\sphinxupquote{python}}. The same
aplies with the Python package manager \sphinxcode{\sphinxupquote{pip3}} instead of \sphinxcode{\sphinxupquote{pip}}. There is nothing
wrong with this, and similar situations exist on some older Linux distributions where
Python2 and Python3 live next to each other on the same system.


\subsubsection{Mac OS X quickstart guide}
\label{\detokenize{installation:mac-os-x-quickstart-guide}}
The following code block shows a minimal way how quickly to start on Mac OS X.
This assumes you have some C++ compiler available, e.g. from Xcode (Clang).

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYGZdl{} pip3 install scipy numpy matplotlib \PYG{c+c1}{\PYGZsh{} the only dependencies you really need}
\PYGZdl{} git clone https://github.com/anabrid/pyanalog.git
\PYGZdl{} \PYG{n+nb}{cd} pyanalog
\PYGZdl{} python3 setup.py develop \PYGZhy{}\PYGZhy{}user \PYG{c+c1}{\PYGZsh{} this way you can import the python module from anwhere}
\PYGZdl{} \PYG{n+nb}{cd} examples/traditional\PYGZhy{}dda\PYGZhy{}circuits
\PYGZdl{} python3 \PYGZhy{}m dda chua.dda c \PYGZgt{} chua.cpp
\PYGZdl{} c++ \PYGZhy{}\PYGZhy{}std\PYG{o}{=}c++1z chua.cpp     \PYG{c+c1}{\PYGZsh{} c++1z\PYGZhy{}Standard is specific to Mac / clang}
\PYGZdl{} ./a.out \PYGZgt{} chua.dat
\PYGZdl{} gnuplot etc...
\end{sphinxVerbatim}

Note that with the Clang/LLVM compiler, you have to set \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}std=c++1z}} instead of
\sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}std=c++17}} (as with GCC).


\subsection{Microsoft Windows\sphinxhyphen{}specific installation notes}
\label{\detokenize{installation:microsoft-windows-specific-installation-notes}}
For Windows, there are several Python distributions available. The most prominent and mature
is certainly \sphinxhref{https://www.anaconda.com/}{Anaconda}%
\begin{footnote}[16]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.anaconda.com/}
%
\end{footnote}. Conda is much into
\sphinxhref{https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html}{Python enviroments}%
\begin{footnote}[17]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html}
%
\end{footnote},
which is somewhat orthogonal to the standard
\sphinxhref{https://pypi.org/project/pip/}{Python package manager pip}%
\begin{footnote}[18]\sphinxAtStartFootnote
\sphinxnolinkurl{https://pypi.org/project/pip/}
%
\end{footnote}.
However, there are straightforwards ways to \sphinxhref{https://datumorphism.leima.is/til/programming/python/python-anaconda-install-requirements/}{install the requirements.txt in conda}%
\begin{footnote}[19]\sphinxAtStartFootnote
\sphinxnolinkurl{https://datumorphism.leima.is/til/programming/python/python-anaconda-install-requirements/}
%
\end{footnote}
(see also here \sphinxhref{https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html\#using-pip-in-an-environment}{how to use pip in an environment}%
\begin{footnote}[20]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html\#using-pip-in-an-environment}
%
\end{footnote}).

Other options exist. For instance, you can install Python also directly from the Windows
store (and use pip as usual). To do so, just open any Terminal (Powershell or \sphinxcode{\sphinxupquote{cmd.exe}})
and type \sphinxcode{\sphinxupquote{python}}. This will guide you straight to Windows store. You can also install
the popular IDE \sphinxhref{https://www.spyder-ide.org/}{Spyder}%
\begin{footnote}[21]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.spyder-ide.org/}
%
\end{footnote} which ships a Python installation
with itself.
This is particularly handy because it provides also a
lean way to setup the developer machine. For instance, there is a menu item
\sphinxstyleemphasis{Tools/Current user environment variables…} which allows you to set the system wide
\sphinxcode{\sphinxupquote{PATH}}.

Regarding C++ compilers, we have made best experiences with \sphinxhref{https://www.mingw-w64.org/}{MinGW}%
\begin{footnote}[22]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.mingw-w64.org/}
%
\end{footnote},
the GCC port for Windows.  Make sure
you add the installation directory to your \sphinxcode{\sphinxupquote{PATH}} in order to be able to access the compiler
from everywhere (i.e. every terminal).


\subsubsection{Regarding Windows Environment variables}
\label{\detokenize{installation:regarding-windows-environment-variables}}
The \sphinxcode{\sphinxupquote{HKEY\_CURRENT\_USER\textbackslash{}Environment}} should, as a list, probably contain paths such
as (in this example assumung you have installed MinGW and Spyder, system\sphinxhyphen{}wide):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{C}\PYG{p}{:}\PYGZbs{}\PYG{n}{MinGW}\PYGZbs{}\PYG{n+nb}{bin}
\PYG{n}{C}\PYG{p}{:}\PYGZbs{}\PYG{n}{Program} \PYG{n}{Files}\PYGZbs{}\PYG{n}{Spyder}\PYGZbs{}\PYG{n}{Python}
\end{sphinxVerbatim}

This way, you are fully flexible to use both the C compiler as well as the Python binaries
from everywhere. If you still experience that Windows wants you to visit the Microsoft
store in order to do a \sphinxstyleemphasis{second and independent} installation of Python (which means you also
have two sets of completely independent module installations, individually managed by \sphinxstyleemphasis{pip}),
you might want to carry out \sphinxhref{https://stackoverflow.com/a/63203720}{these steps}%
\begin{footnote}[23]\sphinxAtStartFootnote
\sphinxnolinkurl{https://stackoverflow.com/a/63203720}
%
\end{footnote} in order
to get rid of the python stub pointers to the store:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{cd} \PYG{n}{C}\PYG{p}{:}\PYGZbs{}\PYG{n}{Users}\PYGZbs{}\PYG{o}{\PYGZlt{}}\PYG{n}{you} \PYG{n}{name}\PYG{o}{\PYGZgt{}}\PYGZbs{}\PYG{n}{AppData}\PYGZbs{}\PYG{n}{Local}\PYGZbs{}\PYG{n}{Microsoft}\PYGZbs{}\PYG{n}{WindowsApps}
\PYG{k}{del} \PYG{n}{python}\PYG{o}{.}\PYG{n}{exe}
\PYG{k}{del} \PYG{n}{python3}\PYG{o}{.}\PYG{n}{exe}
\end{sphinxVerbatim}

In case you use Anaconda and do not want (or can) add Python to your path, then you can
also start write some wrapper \sphinxcode{\sphinxupquote{BAT}} script for your actual Python script:
\sphinxSetupCaptionForVerbatim{run\sphinxhyphen{}script.bat}
\def\sphinxLiteralBlockLabel{\label{\detokenize{installation:run-script-bat}}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{c+c1}{REM conda activate base}
\PYG{c+c1}{REM This activates (base) in  current scope}
\PYG{c+c1}{REM Probably have to change \PYGZpc{}HOMEPATH\PYGZpc{} to where conda is installed (user or system wide)}
\PYG{k}{CALL} \PYG{n+nv}{\PYGZpc{}HOMEPATH\PYGZpc{}}\PYGZbs{}anaconda3\PYGZbs{}Scripts\PYGZbs{}activate.bat

python.exe your\PYGZhy{}actual\PYGZhy{}script.py

\PYG{k}{PAUSE}
\end{sphinxVerbatim}

Here, the Windows \sphinxhref{https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call}{Batch call}%
\begin{footnote}[24]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call}
%
\end{footnote}
works the same way as \sphinxhref{https://superuser.com/questions/46139/what-does-source-do}{source does in the unix bash}%
\begin{footnote}[25]\sphinxAtStartFootnote
\sphinxnolinkurl{https://superuser.com/questions/46139/what-does-source-do}
%
\end{footnote},
allowing you to invoke \sphinxcode{\sphinxupquote{python.exe}} or \sphinxcode{\sphinxupquote{pip.exe}} afterwards.
\sphinxhref{https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/pause}{Pause}%
\begin{footnote}[26]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/pause}
%
\end{footnote} prevents
the Windows terminal from closing after invoking, so you can still see the output when
launching the script by double\sphinxhyphen{}clicking the Bat file in Windows explorer.


\subsubsection{Further software recommendations for Windows}
\label{\detokenize{installation:further-software-recommendations-for-windows}}
If you do not have a comfortable IDE, you might want to look into
\sphinxhref{https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.2}{Microsoft Powershell}%
\begin{footnote}[27]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.2}
%
\end{footnote} as well as the new
\sphinxhref{https://www.microsoft.com/de-de/p/windows-terminal/9n0dx20hk701\#activetab=pivot:overviewtab}{Windows Terminal}%
\begin{footnote}[28]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.microsoft.com/de-de/p/windows-terminal/9n0dx20hk701\#activetab=pivot:overviewtab}
%
\end{footnote}
which can be obtained in the Microsoft store for free.

While it is attractive to download the PyAnalog software as a ZIP file from Github, we
recommend you instead to install a proper Git client, such as the comprehensible
\sphinxhref{https://desktop.github.com}{Github Desktop GUI}%
\begin{footnote}[29]\sphinxAtStartFootnote
\sphinxnolinkurl{https://desktop.github.com}
%
\end{footnote}. It can also be used independently
from the \sphinxhref{https://git-scm.com/download/win}{Windows Git Command Line Interface}%
\begin{footnote}[30]\sphinxAtStartFootnote
\sphinxnolinkurl{https://git-scm.com/download/win}
%
\end{footnote}, which
itself can be installed with \sphinxhref{https://docs.microsoft.com/en-us/windows/package-manager/winget/}{winget}%
\begin{footnote}[31]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.microsoft.com/en-us/windows/package-manager/winget/}
%
\end{footnote}.
With git, it is as easy as a single click on \sphinxstyleemphasis{update} or an invocation of \sphinxcode{\sphinxupquote{git pull}}
to obtain a more recent version of the PyAnalog code.

\begin{sphinxadmonition}{note}{Note:}
At Windows, we have experienced some hazzles with \sphinxstyleemphasis{UTF\sphinxhyphen{}16} encoded files. While we are
working on improving the compatibility with the PyAnalog tools, you can convert any
file to \sphinxstyleemphasis{UTF\sphinxhyphen{}8} by using such a  Powershell command:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{Get}\PYG{o}{\PYGZhy{}}\PYG{n}{Content} \PYG{n}{nameOfYourFile}\PYG{o}{.}\PYG{n}{txt} \PYG{o}{|} \PYG{n}{Out}\PYG{o}{\PYGZhy{}}\PYG{n}{File} \PYG{o}{\PYGZhy{}}\PYG{n}{Encoding} \PYG{n}{UTF8} \PYG{n}{nameOfYourFile}\PYG{o}{\PYGZhy{}}\PYG{n}{fixed}\PYG{o}{.}\PYG{n}{txt}
\end{sphinxVerbatim}

Also don’t forget that Windows generally does not allow you to \sphinxstyleemphasis{open files for writing while
they are opened for reading}. If you are used to the unix kind of dealing with files, this can
make some steps more cumbersome and result in more copies of files.
\end{sphinxadmonition}


\subsection{Recommended way of installation (developer machine setup)}
\label{\detokenize{installation:recommended-way-of-installation-developer-machine-setup}}
We recommend the following way of obtaining and installing the PyAnalog code
on your developer machine using \sphinxstyleemphasis{setuptools} by using the
\sphinxhref{https://setuptools.readthedocs.io/en/latest/setuptools.html\#development-mode}{development mode}%
\begin{footnote}[32]\sphinxAtStartFootnote
\sphinxnolinkurl{https://setuptools.readthedocs.io/en/latest/setuptools.html\#development-mode}
%
\end{footnote}
(which creastes a user\sphinxhyphen{}wide softlink to the working copy):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYGZdl{} \PYG{n+nb}{cd} prefered/directory/for/code/of/the/analogians
\PYGZdl{} git clone https://github.com/anabrid/pyanalog.git \PYG{c+c1}{\PYGZsh{} this works always}
\PYGZdl{} git clone git@github.com:anabrid/pyanalog.git     \PYG{c+c1}{\PYGZsh{} use this if you are experienced at github}
\PYGZdl{} \PYG{n+nb}{cd} pyanalog
\PYGZdl{} python3 setup.py develop \PYGZhy{}\PYGZhy{}user
\end{sphinxVerbatim}

After these steps you are ready to use import the pyanalog package modules from any
Python3 script anywhere on your system, but only \sphinxstyleemphasis{as your current user}. The installation
is successful when you can for instance \sphinxcode{\sphinxupquote{import dda}} somewhere:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYGZdl{} python3
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0] on linux
Type \PYGZdq{}help\PYGZdq{}, \PYGZdq{}copyright\PYGZdq{}, \PYGZdq{}credits\PYGZdq{} or \PYGZdq{}license\PYGZdq{} for more information.
\PYGZgt{}\PYGZgt{}\PYGZgt{} import dda
\PYGZgt{}\PYGZgt{}\PYGZgt{} dda.Symbol(\PYGZdq{}foo\PYGZdq{})
foo
\end{sphinxVerbatim}


\subsection{User (non\sphinxhyphen{}developer) installation}
\label{\detokenize{installation:user-non-developer-installation}}
If you want to install the package, just call \sphinxcode{\sphinxupquote{pip install}} or \sphinxcode{\sphinxupquote{python3 setup.py install}}
in the repository root directory after cloning or without any cloning by just running:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYGZdl{} pip install git+ssh://git@github.com:anabrid/pyanalog.git
\end{sphinxVerbatim}

This will automatically install all the dependencies from the \sphinxcode{\sphinxupquote{requirements.txt}} file.

You can also add the flags \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}user}} for a per\sphinxhyphen{}user (instead of system wide) installation.
If you want to perform an upgrade on an existing installation, add the \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}upgrade}}
flag.

Note that by using this installation method, you cannot easily make edits to the pyanalog
code itself. This is perfectly fine if you only want to use the library.

\begin{sphinxadmonition}{note}{Note:}
Since the overall code is still subject to heavy changes, you should also opt in
for the developer machine setup installation method if you do not indend to work
on the PyAnalog code. This is for easier updating or changing versions with \sphinxcode{\sphinxupquote{git}}
without having to perform a fresh installation. Basically, with the development
installation way, you can change/update/downgrade the PyAnalog code and immediately
profit in your applications.
\end{sphinxadmonition}


\subsection{Using without installation}
\label{\detokenize{installation:using-without-installation}}
We differentiate between \sphinxstyleemphasis{installing dependencies} for using PyAnalog and \sphinxstyleemphasis{installing
PyAnalog itself}. While you should ensure having all the dependencies (which are not
a lot, but see above), when it comes to installing PyAnalog, you can gratefully skip
this step if you don’t bother or don’t like to do so.

That is, you can just checkout the repository, navigate to the root directory and open
a python script from there. This way, you \sphinxstyleemphasis{don’t have to install anything} but have
the modules right in your \sphinxcode{\sphinxupquote{PYTHONPATH}}. This is really the easiest way of getting
started if you don’t want to mess around with \sphinxcode{\sphinxupquote{pip}} or \sphinxcode{\sphinxupquote{setup.py}}.

However, it is usually good practice to use \sphinxstyleemphasis{virtualenv}. Using \sphinxstyleemphasis{virtualenv} was not
covered in this document at all, but standard routines apply, given the presence of
\sphinxcode{\sphinxupquote{requirements.txt}} and \sphinxcode{\sphinxupquote{setup.py}}.


\section{Some general recommendations in the Python ecosystem}
\label{\detokenize{tips:some-general-recommendations-in-the-python-ecosystem}}\label{\detokenize{tips:tips}}\label{\detokenize{tips::doc}}
If you are new to Python, here are some tools you should look into:
\begin{itemize}
\item {} 
The \sphinxhref{https://ipython.org/}{Interactive Python shell}%
\begin{footnote}[33]\sphinxAtStartFootnote
\sphinxnolinkurl{https://ipython.org/}
%
\end{footnote} (IPython). It enriches the
\sphinxhref{https://en.wikipedia.org/wiki/Read\%E2\%80\%93eval\%E2\%80\%93print\_loop}{REPL}%
\begin{footnote}[34]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Read\%E2\%80\%93eval\%E2\%80\%93print\_loop}
%
\end{footnote} interaction
with syntax highlighting, tab completion, comprehensive object introspection,
input and output history, much more readable stack traces, etc. (see
\sphinxhref{https://ipython.readthedocs.io/en/stable/}{list of features}%
\begin{footnote}[35]\sphinxAtStartFootnote
\sphinxnolinkurl{https://ipython.readthedocs.io/en/stable/}
%
\end{footnote}).

\item {} 
\sphinxhref{https://jupyter.org/}{Jupyter}%
\begin{footnote}[36]\sphinxAtStartFootnote
\sphinxnolinkurl{https://jupyter.org/}
%
\end{footnote} and \sphinxhref{https://jupyter.org/try}{JupyterLab}%
\begin{footnote}[37]\sphinxAtStartFootnote
\sphinxnolinkurl{https://jupyter.org/try}
%
\end{footnote}. They
bring a Matlab\sphinxhyphen{}like notebook\sphinxhyphen{}oriented interface which allows for writing high\sphinxhyphen{}quality
documents with mixture of code, output and Latex/Rich text documentation. These
notebooks can be rendered as websites and shared easily.
Most noteworthly, they allow interactivity in cells, such as sliders and animations.
There is a whole universe to explore once you look for Jupyter notebooks. And
you can easily \sphinxhref{https://mybinder.org/}{host your own notebooks in the cloud}%
\begin{footnote}[38]\sphinxAtStartFootnote
\sphinxnolinkurl{https://mybinder.org/}
%
\end{footnote}.

\item {} 
The \sphinxhref{https://docs.python.org/3/library/pdb.html}{Python debugger}%
\begin{footnote}[39]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.python.org/3/library/pdb.html}
%
\end{footnote} can come in handy
in case of errors. With IPython, it’s just the four letters \sphinxcode{\sphinxupquote{\%pdb}} away.

\item {} 
If you look for plotting, \sphinxhref{https://matplotlib.org/}{Matplotlib}%
\begin{footnote}[40]\sphinxAtStartFootnote
\sphinxnolinkurl{https://matplotlib.org/}
%
\end{footnote} is the defacto
standard. Being part of Scipy, it depends on \sphinxhref{https://numpy.org/}{Numpy}%
\begin{footnote}[41]\sphinxAtStartFootnote
\sphinxnolinkurl{https://numpy.org/}
%
\end{footnote}, which
provides N\sphinxhyphen{}dimensional arrays, linear algebra and input/output. When it comes to
scientific computing, Numpy got some kind of hub and it’s website lists dozens of
related projects within all sciences.

\end{itemize}


\section{Software testing in PyAnalog}
\label{\detokenize{code-testing:software-testing-in-pyanalog}}\label{\detokenize{code-testing:code-testing}}\label{\detokenize{code-testing::doc}}
The PyAnalog code is still quite alpha, but we do a number of software tests
without much extra work:
\begin{description}
\item[{\sphinxhref{https://docs.python.org/3/library/doctest.html}{Doctests}\sphinxfootnotemark[42]}] \leavevmode%
\begin{footnotetext}[42]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.python.org/3/library/doctest.html}
%
\end{footnotetext}\ignorespaces 
are super
simple to add, they are just embedded in the documentation. It’s a quite
pythonic way to demonstrate (and test at the same time) the functionality
of small pieces of code.

We have doctests all over the place. The code snippets are of course
also included in the documentation. You can copy \& paste them into your
python console to play with the API.

\item[{Acceptance/Integration tests}] \leavevmode
We can provide some DDA files
where we know the solution analytically. It should be a useful exercise
both for readers and testers to run these examples. We use the
\sphinxhref{https://pytest.org}{pytest}%
\begin{footnote}[43]\sphinxAtStartFootnote
\sphinxnolinkurl{https://pytest.org}
%
\end{footnote} third party library for (unit) testing.

These tests are located in the \sphinxcode{\sphinxupquote{tests/}} directory. They can be executed
by running \sphinxcode{\sphinxupquote{pytest tests}} or just \sphinxcode{\sphinxupquote{make test}} from the parent directory.

\end{description}

\begin{sphinxadmonition}{note}{Note:}
Tests are special because they can be evaluated for success or failure
automatically. This differs them from other code contributions, such
as the example codes in the \sphinxcode{\sphinxupquote{examples/}} directory, which cannot be
evaluated for correctnes.
\end{sphinxadmonition}


\subsection{How to run the tests}
\label{\detokenize{code-testing:how-to-run-the-tests}}
Just run \sphinxcode{\sphinxupquote{make test}} in the root directory to run all of the tests. The output
should look somewhat like this one:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYGZdl{}make test
make doctest unittests
make[1]: Verzeichnis ..../dda wird betreten
python3 \PYGZhy{}m pytest \PYGZhy{}\PYGZhy{}doctest\PYGZhy{}modules \PYGZhy{}\PYGZhy{}pyargs dda \PYGZhy{}\PYGZhy{}ignore=dda/\PYGZus{}\PYGZus{}main\PYGZus{}\PYGZus{}.py  \PYGZhy{}v
============================================= test session starts =============================================
platform linux \PYGZhy{}\PYGZhy{} Python 3.9.7, pytest\PYGZhy{}6.2.5, py\PYGZhy{}1.10.0, pluggy\PYGZhy{}0.13.1 \PYGZhy{}\PYGZhy{} /usr/bin/python3
cachedir: .pytest\PYGZus{}cache
rootdir: /home/sven/Analog/Software/dda
collected 22 items

dda/\PYGZus{}\PYGZus{}init\PYGZus{}\PYGZus{}.py::dda.clean PASSED                                                                       [  4\PYGZpc{}]
dda/ast.py::dda.ast.BreveState PASSED                                                                   [  9\PYGZpc{}]
dda/ast.py::dda.ast.State PASSED                                                                        [ 13\PYGZpc{}]
dda/ast.py::dda.ast.State.dependency\PYGZus{}graph PASSED                                                       [ 18\PYGZpc{}]
dda/ast.py::dda.ast.State.equation\PYGZus{}adder PASSED                                                         [ 22\PYGZpc{}]
dda/ast.py::dda.ast.State.name\PYGZus{}computing\PYGZus{}elements PASSED                                                [ 27\PYGZpc{}]
dda/ast.py::dda.ast.State.variable\PYGZus{}ordering PASSED                                                      [ 31\PYGZpc{}]
dda/ast.py::dda.ast.Symbol PASSED                                                                       [ 36\PYGZpc{}]
dda/ast.py::dda.ast.Symbol.draw\PYGZus{}graph PASSED                                                            [ 40\PYGZpc{}]
dda/ast.py::dda.ast.Symbol.map\PYGZus{}heads PASSED                                                             [ 45\PYGZpc{}]
dda/ast.py::dda.ast.Symbol.map\PYGZus{}tails PASSED                                                             [ 50\PYGZpc{}]
dda/ast.py::dda.ast.Symbol.map\PYGZus{}terms PASSED                                                             [ 54\PYGZpc{}]
dda/ast.py::dda.ast.Symbol.map\PYGZus{}variables PASSED                                                         [ 59\PYGZpc{}]
dda/ast.py::dda.ast.symbols PASSED                                                                      [ 63\PYGZpc{}]
dda/computing\PYGZus{}elements.py::dda.computing\PYGZus{}elements PASSED                                                [ 68\PYGZpc{}]
dda/cpp\PYGZus{}exporter.py::dda.cpp\PYGZus{}exporter.run PASSED                                                        [ 72\PYGZpc{}]
dda/dsl.py::dda.dsl PASSED                                                                              [ 77\PYGZpc{}]
dda/dsl.py::dda.dsl.read\PYGZus{}traditional\PYGZus{}dda SKIPPED (all tests skipped by +SKIP option)                    [ 81\PYGZpc{}]
dda/scipy.py::dda.scipy.to\PYGZus{}scipy PASSED                                                                 [ 86\PYGZpc{}]
dda/scipy.py::dda.scipy.to\PYGZus{}scipy.rhs PASSED                                                             [ 90\PYGZpc{}]
dda/sympy.py::dda.sympy.to\PYGZus{}latex PASSED                                                                 [ 95\PYGZpc{}]
dda/sympy.py::dda.sympy.to\PYGZus{}sympy PASSED                                                                 [100\PYGZpc{}]

======================================== 21 passed, 1 skipped in 1.82s ========================================
python3 \PYGZhy{}m pytest \PYGZhy{}\PYGZhy{}doctest\PYGZhy{}modules \PYGZhy{}\PYGZhy{}pyargs hycon  \PYGZhy{}v
============================================= test session starts =============================================
platform linux \PYGZhy{}\PYGZhy{} Python 3.9.7, pytest\PYGZhy{}6.2.5, py\PYGZhy{}1.10.0, pluggy\PYGZhy{}0.13.1 \PYGZhy{}\PYGZhy{} /usr/bin/python3
cachedir: .pytest\PYGZus{}cache
rootdir: /home/sven/Analog/Software/dda
collected 12 items

hycon/HyCon.py::hycon.HyCon PASSED                                                                      [  8\PYGZpc{}]
hycon/HyCon.py::hycon.HyCon.ensure PASSED                                                               [ 16\PYGZpc{}]
hycon/HyCon.py::hycon.HyCon.expect PASSED                                                               [ 25\PYGZpc{}]
hycon/autosetup.py::hycon.autosetup.DotDict PASSED                                                      [ 33\PYGZpc{}]
hycon/autosetup.py::hycon.autosetup.PotentiometerAddress PASSED                                         [ 41\PYGZpc{}]
hycon/connections.py::hycon.connections PASSED                                                          [ 50\PYGZpc{}]
hycon/replay.py::hycon.replay.HyConRequestReader PASSED                                                 [ 58\PYGZpc{}]
hycon/replay.py::hycon.replay.consume PASSED                                                            [ 66\PYGZpc{}]
hycon/replay.py::hycon.replay.consume.list PASSED                                                       [ 75\PYGZpc{}]
hycon/replay.py::hycon.replay.consume.number PASSED                                                     [ 83\PYGZpc{}]
hycon/replay.py::hycon.replay.delayed PASSED                                                            [ 91\PYGZpc{}]
hycon/replay.py::hycon.replay.replay PASSED                                                             [100\PYGZpc{}]

============================================= 12 passed in 0.03s ==============================================
\PYGZsh{} all other modules don\PYGZsq{}t have useful tests anyway
python3 \PYGZhy{}m pytest \PYGZhy{}v
============================================= test session starts =============================================
platform linux \PYGZhy{}\PYGZhy{} Python 3.9.7, pytest\PYGZhy{}6.2.5, py\PYGZhy{}1.10.0, pluggy\PYGZhy{}0.13.1 \PYGZhy{}\PYGZhy{} /usr/bin/python3
cachedir: .pytest\PYGZus{}cache
rootdir: /home/sven/Analog/Software/dda
collected 15 items

tests/test\PYGZus{}cpp\PYGZus{}interface.py::test\PYGZus{}similar\PYGZus{}dtypes PASSED                                                 [  6\PYGZpc{}]
tests/test\PYGZus{}differentiation.py::test\PYGZus{}polynomial\PYGZus{}diff PASSED                                              [ 13\PYGZpc{}]
tests/test\PYGZus{}differentiation.py::test\PYGZus{}sinusodial\PYGZus{}diff PASSED                                              [ 20\PYGZpc{}]
tests/test\PYGZus{}exponential\PYGZus{}solution.py::test\PYGZus{}run\PYGZus{}simulation PASSED                                          [ 26\PYGZpc{}]
tests/test\PYGZus{}latex\PYGZus{}symbols.py::test\PYGZus{}state PASSED                                                          [ 33\PYGZpc{}]
tests/test\PYGZus{}latex\PYGZus{}symbols.py::test\PYGZus{}c\PYGZus{}code PASSED                                                         [ 40\PYGZpc{}]
tests/test\PYGZus{}latex\PYGZus{}symbols.py::test\PYGZus{}dda\PYGZus{}code PASSED                                                       [ 46\PYGZpc{}]
tests/test\PYGZus{}simulation\PYGZus{}time.py::test\PYGZus{}setup\PYGZus{}state PASSED                                                  [ 53\PYGZpc{}]
tests/test\PYGZus{}simulation\PYGZus{}time.py::test\PYGZus{}run\PYGZus{}simulation PASSED                                               [ 60\PYGZpc{}]
tests/test\PYGZus{}symbol\PYGZus{}mappings.py::test\PYGZus{}map\PYGZus{}variable PASSED                                                 [ 66\PYGZpc{}]
tests/test\PYGZus{}traditional\PYGZus{}ddas.py::test\PYGZus{}if\PYGZus{}double\PYGZus{}pendulum\PYGZus{}is\PYGZus{}scaled PASSED                                [ 73\PYGZpc{}]
tests/test\PYGZus{}traditional\PYGZus{}ddas.py::test\PYGZus{}if\PYGZus{}double\PYGZus{}pendulum\PYGZus{}is\PYGZus{}working PASSED                               [ 80\PYGZpc{}]
tests/test\PYGZus{}traditional\PYGZus{}ddas.py::test\PYGZus{}if\PYGZus{}chua\PYGZus{}is\PYGZus{}scaled PASSED                                           [ 86\PYGZpc{}]
tests/test\PYGZus{}traditional\PYGZus{}ddas.py::test\PYGZus{}notch\PYGZus{}is\PYGZus{}scaled PASSED                                             [ 93\PYGZpc{}]
tests/test\PYGZus{}traditional\PYGZus{}ddas.py::test\PYGZus{}nose PASSED                                                        [100\PYGZpc{}]

============================================= 15 passed in 11.23s =============================================
make[1]: Verzeichnis ..../dda wird verlassen
\end{sphinxVerbatim}

Test scripts can also be run and inspected with python interactively, i.e.

\begin{sphinxVerbatim}[commandchars=\\\{\}]
you@yourcomputer\PYGZdl{} python \PYGZhy{}i test\PYGZus{}exponential\PYGZus{}solution.py
\PYGZgt{}\PYGZgt{}\PYGZgt{} from pylab import *
\PYGZgt{}\PYGZgt{}\PYGZgt{} ion()
\PYGZgt{}\PYGZgt{}\PYGZgt{} time, ysim = test\PYGZus{}run\PYGZus{}simulation()
generated.cc: In Elementfunktion »void csv\PYGZus{}writer::write\PYGZus{}header() const«:
generated.cc:171:43: Warnung: Operation auf »i« könnte undefiniert sein [\PYGZhy{}Wsequence\PYGZhy{}point]
171 |             std::cout \PYGZlt{}\PYGZlt{} query\PYGZus{}variables[i++] \PYGZlt{}\PYGZlt{} sep(i);
    |                                          \PYGZti{}\PYGZca{}\PYGZti{}
generated.cc: In Funktion »int main(int, char**)«:
generated.cc:275:90: Warnung: Operation auf »i« könnte undefiniert sein [\PYGZhy{}Wsequence\PYGZhy{}point]
275 |                 for(size\PYGZus{}t j=0;j\PYGZlt{}5 \PYGZam{}\PYGZam{} i\PYGZlt{}all\PYGZus{}variables.size();j++) cerr \PYGZlt{}\PYGZlt{} all\PYGZus{}variables[i++] \PYGZlt{}\PYGZlt{} (i!=all\PYGZus{}variables.size() ? \PYGZdq{}, \PYGZdq{} : \PYGZdq{}\PYGZdq{}); \PYGZcb{}
    |                                                                                         \PYGZti{}\PYGZca{}\PYGZti{}
Running: ./a.out \PYGZhy{}\PYGZhy{}max\PYGZus{}iterations=60 \PYGZhy{}\PYGZhy{}modulo\PYGZus{}write=1 \PYGZhy{}\PYGZhy{}always\PYGZus{}compute\PYGZus{}aux\PYGZus{}before\PYGZus{}printing=1 \PYGZhy{}\PYGZhy{}write\PYGZus{}initial\PYGZus{}conditions=0
\PYGZgt{}\PYGZgt{}\PYGZgt{} print(time)
[0.05 0.1  0.15 0.2  0.25 0.3  0.35 0.4  0.45 0.5  0.55 0.6  0.65 0.7
0.75 0.8  0.85 0.9  0.95 1.   1.05 1.1  1.15 1.2  1.25 1.3  1.35 1.4
1.45 1.5  1.55 1.6  1.65 1.7  1.75 1.8  1.85 1.9  1.95 2.   2.05 2.1
2.15 2.2  2.25 2.3  2.35 2.4  2.45 2.5  2.55 2.6  2.65 2.7  2.75 2.8
2.85 2.9  2.95 3.  ]
\PYGZgt{}\PYGZgt{}\PYGZgt{} plot(time, ysim, \PYGZdq{}o\PYGZdq{})
[\PYGZlt{}matplotlib.lines.Line2D object at 0x7fe9a99c7520\PYGZgt{}]
\PYGZgt{}\PYGZgt{}\PYGZgt{} plot(time, \PYGZhy{}exp(\PYGZhy{}time))
[\PYGZlt{}matplotlib.lines.Line2D object at 0x7fe9982f43a0\PYGZgt{}]
\PYGZgt{}\PYGZgt{}\PYGZgt{} savefig(\PYGZdq{}exponential\PYGZus{}solution.png\PYGZdq{})
\end{sphinxVerbatim}


\subsection{How to run doctests on the whole package}
\label{\detokenize{code-testing:how-to-run-doctests-on-the-whole-package}}
Use \sphinxhref{https://docs.pytest.org/}{pytest}%
\begin{footnote}[44]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.pytest.org/}
%
\end{footnote} as a slim frontend for the python
doctest builtin, for instance:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYGZdl{} cd \PYGZdl{}(git rev\PYGZhy{}parse \PYGZhy{}\PYGZhy{}show\PYGZhy{}toplevel)            \PYGZsh{} execute from PyAnalog root directory
\PYGZdl{} pytest\PYGZhy{}3 \PYGZhy{}\PYGZhy{}doctest\PYGZhy{}modules \PYGZhy{}\PYGZhy{}pyargs dda  \PYGZhy{}v
\end{sphinxVerbatim}

See also the \sphinxcode{\sphinxupquote{Makefile}} provided in the root directory.


\subsection{Where are the tests running?}
\label{\detokenize{code-testing:where-are-the-tests-running}}
Tests are run by our \sphinxstyleemphasis{Gitlab Continous Integration} whenever the code is committed. You can
view the file \sphinxcode{\sphinxupquote{.gitlab\sphinxhyphen{}ci.yml}} in the root of the repository in order to see what is happening,
which is at the moment something like
\begin{itemize}
\item {} 
Make the docs (run sphinx)

\item {} 
Deploy the docs (upload them somewhere)

\item {} 
Run all the tests (as above)

\end{itemize}

The finished/running pipelines can be seen at \sphinxurl{https://lab.analogparadigm.com/software/dda/-/pipelines}
We also run these tests at our Gitlab CI when pushes happen to the Github repository
\sphinxurl{https://github.com/anabrid/pyanalog} thanks to mirroring at
\sphinxurl{https://lab.analogparadigm.com/software/pyanalog-mirror-from-github}


\subsection{What about analog hardware tests}
\label{\detokenize{code-testing:what-about-analog-hardware-tests}}
This would require having dedicated testing hardware somewhere. This is out of scope for the moment.

\chapter{PyDDA}


\section{Introduction to PyDDA}
\label{\detokenize{dda/intro:introduction-to-pydda}}\label{\detokenize{dda/intro:dda-intro}}\label{\detokenize{dda/intro::doc}}
PyDDA is a small library to write and generate DDA code in Python.
DDA stands for \sphinxstyleemphasis{digital differential analyzer}. In this context, it is
a code for solving ordinary differential equations (ODEs) given in a domain
specific language description (i.e. an electrical circuit).

The main advantage of this implementation in contrast to the older Perl
implementation is the \sphinxstyleemphasis{abstract syntax tree} level of circuit representation.
The syntax tree representation allows for fine\sphinxhyphen{}grained manipulations of
terms where the older Perl code could only apply regular expressions.

This code can replace the old \sphinxcode{\sphinxupquote{dda2c.pl}} Perl implementation
(see \sphinxcode{\sphinxupquote{misc/}} directory for it’s code,
\sphinxhref{https://github.com/anabrid/pyanalog/tree/master/misc/DDA.pl}{or also here}%
\begin{footnote}[45]\sphinxAtStartFootnote
\sphinxnolinkurl{https://github.com/anabrid/pyanalog/tree/master/misc/DDA.pl}
%
\end{footnote}). It is a
standalone Python 3 code with no third party dependencies. It generates
standalone C++ code with no dependencies (not even on the old \sphinxcode{\sphinxupquote{dda.h}}).


\subsection{Usage: As a library or from the command line}
\label{\detokenize{dda/intro:usage-as-a-library-or-from-the-command-line}}
The {\hyperref[\detokenize{dda/package:module-dda}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda}}}}} (\autopageref*{\detokenize{dda/package:module-dda}}) module can either be used from a DDA file written in Python or
directly from old\sphinxhyphen{}style traditional DDA plaintext files. While pythonic
dda files have the advantage to be able to use all the flexibility of
Python scripting (such as using numpy for linear algebra computations
and matplotlib for postprocessing of results), plaintext DDA files are
in general shorter and more precise to read. See {\hyperref[\detokenize{dda/dsl:module-dda.dsl}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.dsl}}}}} (\autopageref*{\detokenize{dda/dsl:module-dda.dsl}}) for further
details on the \sphinxstyleemphasis{traditional} DDA file format.

The module can also be used from the command line as a utility. The
behaviour is similar to the \sphinxcode{\sphinxupquote{simulate.pl}} and \sphinxcode{\sphinxupquote{dda2c.pl}} utilities but also
covers a few more features. Usage example (implementation
provided by {\hyperref[\detokenize{dda/dsl:dda.dsl.cli_exporter}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.dsl.cli\_exporter()}}}}} (\autopageref*{\detokenize{dda/dsl:dda.dsl.cli_exporter}}) ):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
me@localhost \PYGZdl{} python \PYGZhy{}m dda \PYGZhy{}\PYGZhy{}help
usage: dda.py [\PYGZhy{}h] [\PYGZhy{}o [OUTPUT]] [circuit\PYGZus{}file] \PYGZob{}c,dda,dot,latex\PYGZcb{}

PyDDA, the AST\PYGZhy{}based DDA compiler

positional arguments:
circuit\PYGZus{}file          DDA setup (traditional file). Default is stdin.
\PYGZob{}c,dda,dot,latex\PYGZcb{}     File formats which can be generated

optional arguments:
\PYGZhy{}h, \PYGZhy{}\PYGZhy{}help            show this help message and exit
\PYGZhy{}o [OUTPUT], \PYGZhy{}\PYGZhy{}output [OUTPUT]
                        Where to write exported code to. Default is stdout.

A Command Line Interface (CLI) for PyDDA...
\end{sphinxVerbatim}

Here is a full bash script which demonstrates how to use PyDDA as a drop\sphinxhyphen{}in replacement
for the traditional Perl\sphinxhyphen{}based DDA code. It allows using the PyDDA C++ code generator
without writing a single line of Python:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{c+ch}{\PYGZsh{}!/usr/bin/bash}

\PYG{c+c1}{\PYGZsh{} given the DDA file \PYGZdq{}notch\PYGZus{}simplified.dda\PYGZdq{}, which you can find in the}
\PYG{c+c1}{\PYGZsh{} directory ./examples/traditional\PYGZhy{}dda\PYGZhy{}circuits, we simulate the system}
\PYG{c+c1}{\PYGZsh{} for 2000 timesteps and plot the time evolution of the fields \PYGZdq{}cn\PYGZdq{}, \PYGZdq{}cd\PYGZdq{} and \PYGZdq{}cnr\PYGZdq{}}
\PYG{c+c1}{\PYGZsh{} which are part of the DDA file (in terms of \PYGZdq{}cn = int(...)\PYGZdq{})}

\PYG{n}{python} \PYG{o}{\PYGZhy{}}\PYG{n}{m} \PYG{n}{dda} \PYG{n}{notch\PYGZus{}simplified}\PYG{o}{.}\PYG{n}{dda} \PYG{n}{C} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{output} \PYG{n}{notch\PYGZus{}simplified}\PYG{o}{.}\PYG{n}{cc}
\PYG{n}{g}\PYG{o}{+}\PYG{o}{+} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{std}\PYG{o}{=}\PYG{n}{c}\PYG{o}{+}\PYG{o}{+}\PYG{l+m+mi}{17}  \PYG{n}{notch\PYGZus{}simplified}\PYG{o}{.}\PYG{n}{cc} \PYG{o}{\PYGZhy{}}\PYG{n}{onotch\PYGZus{}simplified}\PYG{o}{.}\PYG{n}{exe}
\PYG{o}{.}\PYG{o}{/}\PYG{n}{notch\PYGZus{}simplified}\PYG{o}{.}\PYG{n}{exe} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{max\PYGZus{}iterations}\PYG{o}{=}\PYG{l+m+mi}{2000} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{skip\PYGZus{}header}\PYG{o}{=}\PYG{l+m+mi}{1}  \PYG{n}{cn} \PYG{n}{cd} \PYG{n}{cnr}  \PYG{o}{\PYGZgt{}} \PYG{n}{scratch}\PYG{o}{.}\PYG{n}{dat}

\PYG{n}{cat} \PYG{o}{\PYGZlt{}\PYGZlt{}}\PYG{n}{GNUPLOT\PYGZus{}FILE} \PYG{o}{\PYGZgt{}} \PYG{n}{gnuplot}\PYG{o}{.}\PYG{n}{dat}

\PYG{n+nb}{set} \PYG{n}{terminal} \PYG{n}{pdf}
\PYG{n+nb}{set} \PYG{n}{output} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{notch\PYGZus{}simplified\PYGZus{}gnuplot.pdf}\PYG{l+s+s2}{\PYGZdq{}}
\PYG{n+nb}{set} \PYG{n}{key} \PYG{n}{autotitle} \PYG{n}{columnheader}
\PYG{n+nb}{set} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Notch simplified (with PyDDA/Gnuplot)}\PYG{l+s+s2}{\PYGZdq{}}

\PYG{n}{plot} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{scratch.dat}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{1} \PYG{k}{with} \PYG{n}{lines} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{cn}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYGZbs{}
     \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{scratch.dat}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{2} \PYG{k}{with} \PYG{n}{lines} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{cd}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYGZbs{}
     \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{scratch.dat}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{3} \PYG{k}{with} \PYG{n}{lines} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{cnr}\PYG{l+s+s2}{\PYGZdq{}}

\PYG{n}{GNUPLOT\PYGZus{}FILE}

\PYG{n}{gnuplot} \PYG{n}{gnuplot}\PYG{o}{.}\PYG{n}{dat}
\PYG{n+nb}{open} \PYG{n}{notch\PYGZus{}simplified\PYGZus{}gnuplot}\PYG{o}{.}\PYG{n}{pdf}
\end{sphinxVerbatim}


\subsection{Usage without a C++ compiler}
\label{\detokenize{dda/intro:usage-without-a-c-compiler}}
The PyDDA code grew out of its predecessor (\sphinxcode{\sphinxupquote{dda2c.pl}}) as a \sphinxstyleemphasis{code generator}
for an ODE solver. Having C++ has target language, it requires a C++ compiler
to work. However, during the time, PyDDA got mature as a toolkit for exporting
the code also in different formats. In fact, using the {\hyperref[\detokenize{dda/scipy:module-dda.scipy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.scipy}}}}} (\autopageref*{\detokenize{dda/scipy:module-dda.scipy}})
module, one can avoid C++ and use PyDDA solely within the Python environment.
This can be handy for anyone who cannot or does not want to deal with C++
or all the fundamentals.

Therefore, instead of following all the tedious way of C++ code generation,
compilation and running (which also requires that you have all the build
tools installed for compiling C++ on your system), you can also take the
short track by making use of SciPy, which is also much easier to install
on many systems. This also works from the command line:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
me@localhost \PYGZdl{} python \PYGZhy{}m dda.scipy \PYGZhy{}\PYGZhy{}help
usage: scipy.py [\PYGZhy{}h] [\PYGZhy{}o [OUTPUT]] \PYGZhy{}t TFINAL [\PYGZhy{}\PYGZhy{}method [METHOD]] [circuit\PYGZus{}file]

PyDDA\PYGZsq{}s scipy interface simulation runner

positional arguments:
circuit\PYGZus{}file          DDA setup (traditional file). Default is stdin.

optional arguments:
\PYGZhy{}h, \PYGZhy{}\PYGZhy{}help            show this help message and exit
\PYGZhy{}o [OUTPUT], \PYGZhy{}\PYGZhy{}output [OUTPUT]
                        Where to write output CSV to. Default is stdout.
\PYGZhy{}q [QUERY\PYGZus{}FIELDS ...], \PYGZhy{}\PYGZhy{}query\PYGZhy{}fields [QUERY\PYGZus{}FIELDS ...]
                        List of fields to plot. Just pass whitespace seperated (i.e. \PYGZhy{}q a b c). Also add \PYGZsq{}t\PYGZsq{} if you want
                        to have the solution time (recommended).

Arguments passed to scipy.integrate.solve\PYGZus{}ivp:
\PYGZhy{}t TFINAL, \PYGZhy{}\PYGZhy{}tfinal TFINAL
                        Time (in simulation units) to run up to. Do not confuse this with some iteration counter.
\PYGZhy{}m [METHOD], \PYGZhy{}\PYGZhy{}method [METHOD]
                        Integration method to use
\PYGZhy{}d, \PYGZhy{}\PYGZhy{}dense\PYGZhy{}output    Dense Output (default is not dense)

A Command Line Interface (CLI) for :mod:`dda.scipy`. This CLI API basically solves a DDA file ...
\end{sphinxVerbatim}

Here is a shell script example, again with the notch DDA file, of using SciPy instead
of the C++ based solver:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{c+ch}{\PYGZsh{}!/usr/bin/bash}

\PYG{c+c1}{\PYGZsh{} given the DDA file \PYGZdq{}notch\PYGZus{}simplified.dda\PYGZdq{}, which you can find in the}
\PYG{c+c1}{\PYGZsh{} directory ./examples/traditional\PYGZhy{}dda\PYGZhy{}circuits, we simulate the system}
\PYG{c+c1}{\PYGZsh{} for 2000 timesteps and plot the time evolution of the fields \PYGZdq{}cn\PYGZdq{}, \PYGZdq{}cd\PYGZdq{} and \PYGZdq{}cnr\PYGZdq{}}
\PYG{c+c1}{\PYGZsh{} which are part of the DDA file (in terms of \PYGZdq{}cn = int(...)\PYGZdq{})}

\PYG{n}{python} \PYG{o}{\PYGZhy{}}\PYG{n}{m} \PYG{n}{dda}\PYG{o}{.}\PYG{n}{scipy} \PYG{o}{\PYGZhy{}}\PYG{n}{d} \PYG{o}{\PYGZhy{}}\PYG{n}{t} \PYG{l+m+mi}{20} \PYG{o}{\PYGZhy{}}\PYG{n}{q} \PYG{n}{cn\PYGZus{}minus} \PYG{n}{cd\PYGZus{}minus} \PYG{n}{cnr\PYGZus{}minus} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{method} \PYG{n}{RK45} \PYG{n}{notch\PYGZus{}simplified}\PYG{o}{.}\PYG{n}{dda} \PYG{o}{\PYGZgt{}} \PYG{n}{scratch}\PYG{o}{.}\PYG{n}{dat}

\PYG{n}{cat} \PYG{o}{\PYGZlt{}\PYGZlt{}}\PYG{n}{GNUPLOT\PYGZus{}FILE} \PYG{o}{\PYGZgt{}} \PYG{n}{gnuplot}\PYG{o}{.}\PYG{n}{dat}

\PYG{n+nb}{set} \PYG{n}{terminal} \PYG{n}{pdf}
\PYG{n+nb}{set} \PYG{n}{output} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{notch\PYGZus{}simplified\PYGZus{}gnuplot.pdf}\PYG{l+s+s2}{\PYGZdq{}}
\PYG{n+nb}{set} \PYG{n}{key} \PYG{n}{autotitle} \PYG{n}{columnheader}
\PYG{n+nb}{set} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Notch simplified (with PyDDA/Gnuplot)}\PYG{l+s+s2}{\PYGZdq{}}

\PYG{n}{plot} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{scratch.dat}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{1} \PYG{k}{with} \PYG{n}{lines} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{cn}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYGZbs{}
     \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{scratch.dat}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{2} \PYG{k}{with} \PYG{n}{lines} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{cd}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYGZbs{}
     \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{scratch.dat}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{3} \PYG{k}{with} \PYG{n}{lines} \PYG{n}{title} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{cnr}\PYG{l+s+s2}{\PYGZdq{}}

\PYG{n}{GNUPLOT\PYGZus{}FILE}

\PYG{n}{gnuplot} \PYG{n}{gnuplot}\PYG{o}{.}\PYG{n}{dat}
\PYG{n+nb}{open} \PYG{n}{notch\PYGZus{}simplified\PYGZus{}gnuplot}\PYG{o}{.}\PYG{n}{pdf}
\end{sphinxVerbatim}

Note that the naming of the columns is different to the top example, since you can only
access the \sphinxstyleemphasis{evolution quantities}, whcih are called \sphinxcode{\sphinxupquote{cn\_minus}} here, while \sphinxcode{\sphinxupquote{cn}} is a
deviated quantity. More details on these limitations can be found in the description of
the {\hyperref[\detokenize{dda/scipy:module-dda.scipy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.scipy}}}}} (\autopageref*{\detokenize{dda/scipy:module-dda.scipy}}) module.


\subsection{Known Bugs and limitations}
\label{\detokenize{dda/intro:known-bugs-and-limitations}}
Please see the issue list at \sphinxurl{https://github.com/anabrid/pyanalog/issues} for
a list of bugs.

We also have an internal bug tracker at
\sphinxurl{https://lab.analogparadigm.com/software/pyanalog/-/issues}
which is subject to be merged into the public one.


\section{A rationale about DDA}
\label{\detokenize{dda/rationale:a-rationale-about-dda}}\label{\detokenize{dda/rationale:dda-rationale}}\label{\detokenize{dda/rationale::doc}}
The following text is an introduction into the \sphinxstyleemphasis{DDA} concepts. It is envisaged for readers
who want to trace the connections between analog computing and it’s digital simulation.
If you only want to work with \sphinxtitleref{PyDDA} but do not care about the fundamentals, you can
skip this text.


\subsection{The digital number flow machine}
\label{\detokenize{dda/rationale:the-digital-number-flow-machine}}
DDA is short for \sphinxstyleemphasis{digital differential analyzer}. This term describes a certain way of
building an algorithmic\sphinxhyphen{}logical unit which is programmed with a dataflow paradigm. It
can be imagined as an analog computer but with digital computing elements in place of
analog computing elements. Such a DDA machine could feature \sphinxstyleemphasis{n} bit integer adders
(for instance a ripple\sphinxhyphen{}carry adder), binary multipliers, and even discrete integrators
for adding integers (i.e. a stateful computing element). In general, it is straightforward
to design such a machine for some fixed width binary number representation. It is worth
emphasizing that such a machine neither features continous time nor continous number
representation as a real analog computer would have. Nevertheless, it is an interesting
computing architecture as it is half\sphinxhyphen{}way between an analog and a digital computer.

In the age of FPGAs (field programmable gate arrays), it is straightforward to generate
digital computing circuits by software descriptions. Furthermore, being a digital
computer, the DDA architecture can be simulated by any Turing machine. This makes it
straightforward to write a simulator for contemporary register machines (that is,
regular and widespread computers/processors).


\subsection{Describing and simulating a DDA machine}
\label{\detokenize{dda/rationale:describing-and-simulating-a-dda-machine}}
The DDA code proposed in this document consists of several parts:
\begin{itemize}
\item {} 
An easy description language for the computational network (circuit)

\item {} 
A compiler from that language to an iterative imperative code (Perl/C)

\item {} 
Tools for running such a code and evaluating the results

\end{itemize}

Loosely speaking, this translation works as follows: A circuit file is an ASCII
line based text file which looks like

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{dt} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mf}{0.0005}\PYG{p}{)}
\PYG{n}{t} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{)}
\PYG{n}{y0}  \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{minus\PYGZus{}dy0} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{)}

\PYG{n}{minus\PYGZus{}dy} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{minus\PYGZus{}dy0}\PYG{p}{)}
\PYG{n}{y}        \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{minus\PYGZus{}dy}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{y0}\PYG{p}{)}
\end{sphinxVerbatim}

That is, each line is an assignment of some variable to some expression, which is either
a constant (\sphinxcode{\sphinxupquote{const}}) or a compound expression of computing elements. These expressions
are written in some standard C\sphinxhyphen{}like notation \sphinxcode{\sphinxupquote{f(x,y,...)}} where \sphinxcode{\sphinxupquote{f}} is the identifier for
the function and \sphinxcode{\sphinxupquote{x,y,...}} are comma seperated arguments. The following \sphinxstyleemphasis{basic arithmetic}
(from the perspective of an analog computer) computing elements are defined:
\begin{itemize}
\item {} 
\(neg(x) = -x\), the inverse

\item {} 
\(div(x, b) = a/b\), the standard division

\item {} 
\(mult(a_0, a_1, \dots) = \prod_i a_i\), the standard multiplication

\item {} 
\(sum(a_0, a_1, \dots) = - \sum_i a_i\), the summation in analog\sphinxhyphen{}computer typical
\sphinxstyleemphasis{negating} convention.

\item {} 
\(int(a_0, a_1, \dots, \Delta t, I_0) \approx - \int \sum_i a_i \, \Delta t + I_0\),
the time integration (again in analog\sphinxhyphen{}computer typical negating convention).
The digital integrator is discussed in detail in the following text.

\end{itemize}

Furthermore, a couple of case\sphinxhyphen{}discreminating computing elements are defined. Here,
they are given in C\sphinxhyphen{}like notation \sphinxcode{\sphinxupquote{x ? y : z}} which evaluates to \sphinxcode{\sphinxupquote{if(x) then y else z}}.
\begin{itemize}
\item {} 
\sphinxcode{\sphinxupquote{lt(a,b,c,d) = (a \textless{}  b) ? c : d}}

\item {} 
\sphinxcode{\sphinxupquote{le(a,b,c,d) = (a \textless{}= b) ? c : d}}

\item {} 
\sphinxcode{\sphinxupquote{gt(a,b,c,d) = lt(b,a,c,d)}}

\item {} 
\sphinxcode{\sphinxupquote{ge(a,b,c,d) = le(b,a,c,d)}}

\item {} 
\sphinxcode{\sphinxupquote{dead\_lower(a,b) = (a\textless{}b) ? (a\sphinxhyphen{}b) : 0 = gt(a,b,a\sphinxhyphen{}b,0)}}

\item {} 
\sphinxcode{\sphinxupquote{dead\_upper(a,b) = (a\textgreater{}b) ? (a\sphinxhyphen{}b) : 0 = lt(b,a,a\sphinxhyphen{}b,0)}}

\item {} 
\sphinxcode{\sphinxupquote{min(a,b) = (a\textless{}b) ? a : b = lt(a,b,a,b)}}

\item {} 
\sphinxcode{\sphinxupquote{max(a,b) = (a\textgreater{}b) ? a : b = gt(a,b,a,b)}}

\item {} 
\sphinxcode{\sphinxupquote{abs(a) = (a\textless{}0) ? \sphinxhyphen{}a : a  = lt(a,0,\sphinxhyphen{}a,a)}}

\item {} 
\sphinxcode{\sphinxupquote{floor(a) = (int)a}}  rounds \sphinxcode{\sphinxupquote{a}} to the next lower integer.

\end{itemize}

Note that this is only a subset of the overall computing elements defined. It is easy
to introduce new computing elements, they are defined in the {\hyperref[\detokenize{dda/computing_elements:module-dda.computing_elements}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.computing\_elements}}}}} (\autopageref*{\detokenize{dda/computing_elements:module-dda.computing_elements}}).


\subsection{Linearization of a circuit}
\label{\detokenize{dda/rationale:linearization-of-a-circuit}}
The \sphinxcode{\sphinxupquote{dda2c.pl}} Perl script translates a DDA circuit file to a valid \sphinxstyleemphasis{C} program. To do
so, all quantities are treated as \sphinxstyleemphasis{real valued} and are associated with the \sphinxstyleemphasis{double}
floating point data type. As C is a strongly typed language, all defined quantities are
collected and introduced as stack variables before use.

The actual imperative program then just takes the DDA circuit line\sphinxhyphen{}by\sphinxhyphen{}line. This introduces
a bias, as the computing network by itself is executed \sphinxstyleemphasis{synchronously} while a simulation
with a single arithmetic logical unit (ALU) on an ordinary processor can only execute one
operation at a time.

\begin{sphinxadmonition}{note}{Note:}
It would be interesting to think a bit whether we could not write an DDA\sphinxhyphen{}level exact
simulator, since the DDA machine is clocked. We should be able to correctly simulate
this clock.
\end{sphinxadmonition}

Since the DDA is subject to a discrete computing cycle, a register machine can simulate
the DDA architecture cycle by cycle, computing the value of each computing element
input and output. For the sake of extraordinary introspection and debugging facilities,
the DDA to C compiler dismantles compound expressions \sphinxcode{\sphinxupquote{f(g(x))}} or \sphinxcode{\sphinxupquote{f(a,b(c),d(e))}}
and entitles all intermediate expressions such as \sphinxcode{\sphinxupquote{gx=g(x)}} in \sphinxcode{\sphinxupquote{f(gx)}} or
\sphinxcode{\sphinxupquote{g=b(c)}} and \sphinxcode{\sphinxupquote{h=d(e)}} in \sphinxcode{\sphinxupquote{f(a,g,h)}}. This is especially handy when the DDA is seen
as an approximation of the analog computer, as it allows for checking the boundness
(correct scaling) of all variables during the cycles (time evolution).

Having said that, the DDA simulator allows for simulating a DDA circuit iteration by
iteration and dumping (outputting) values every \sphinxcode{\sphinxupquote{n}} iterations. Therefore, while
the input of a circuit is always fixed by the constants (\sphinxcode{\sphinxupquote{const}} statements, no
focus has given to the point of interfacing other codes, which is left as an exercise
for the reader), the output is always a time series for a given set of quantities. We
refer to theses quantities as \sphinxstyleemphasis{observables}, which are \sphinxstyleemphasis{queried} for at code generation
time. One can thus understand the output as a fully discrete table of numbers, where
the columns hold the time series for a given variable and the each row stands for one
time iteration (or some average or surrogate for a larger number of iterations, if
requested). These numbers are represented as ASCII column seperated values (CSV) in the
output of the compiled C program.


\subsection{Applicability for solving differential equations}
\label{\detokenize{dda/rationale:applicability-for-solving-differential-equations}}
The usability for this software\sphinxhyphen{}based DDA implemenetation for solving ordinary differential
equations highly depends on the internals of the integrator component. From all computing
elements described above, the integrator is the only one with an \sphinxstyleemphasis{internal state}. That
is, it has to remember from iteration to iteration the current integration value.

The most easy integrator component will internally look like the following imperative
dummy code:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{k+kt}{double} \PYG{n+nf}{integrate}\PYG{p}{(}\PYG{k+kt}{double} \PYG{n}{integrand}\PYG{p}{,} \PYG{k+kt}{double} \PYG{n}{dx}\PYG{p}{,} \PYG{k+kt}{double} \PYG{n}{initial\PYGZus{}value}\PYG{p}{)} \PYG{p}{\PYGZob{}}
    \PYG{k}{static} \PYG{k+kt}{double} \PYG{n}{internal\PYGZus{}state} \PYG{o}{=} \PYG{n}{initial\PYGZus{}value}\PYG{p}{;}
    \PYG{n}{internal\PYGZus{}state} \PYG{o}{+}\PYG{o}{=} \PYG{n}{integrand} \PYG{o}{*} \PYG{n}{dx}\PYG{p}{;}
    \PYG{k}{return} \PYG{n}{internal\PYGZus{}state}\PYG{p}{;}
\PYG{p}{\PYGZcb{}}
\end{sphinxVerbatim}

Here, the \sphinxcode{\sphinxupquote{internal\_state}} is declared as a \sphinxstyleemphasis{static} variable, which you can think of a
global variable (with a lifetime longer then the function evaluation) if you don’t know C.
In fact, this dummy code comes quite close to the actual implementation of the integrator
in the DDA C code. We refer to the above numerical scheme as the \sphinxstyleemphasis{Euler time integration},
since it approximates the time\sphinxhyphen{}continous integral by it’s Riemann sum.

Within the DDA code, higher order explicit integration schemes can be chosen, such as
Runge\sphinxhyphen{}Kutta. However, given the nature of the problem description in a circuit, implicit
methods can not be applied by the compiler without an actual analysis of the differential
equation. Howver, on can imagine a DDA circuit which itself describes a numerical scheme
on a digital\sphinxhyphen{}circuit level.


\subsection{On PyDDA, the successor of the DDA Perl code}
\label{\detokenize{dda/rationale:on-pydda-the-successor-of-the-dda-perl-code}}
The first DDA code was written by Bernd. It’s job was to simulate circuits, and this was
performed by a small Perl script which threw a few regexes onto the DDA file to convert it
to an executable C numeric simulation.

As described above, we found out that even with slightly more challenging circuits (kind of \sphinxstyleemphasis{border
cases}, such as the depicted one above) the simple ideology of looping over numeric
equations breaks down.


\subsection{Lexical sorting of variable dependencies}
\label{\detokenize{dda/rationale:lexical-sorting-of-variable-dependencies}}
Instead, was has to be applied for a stable integration of an electric circuit, i.e. an
ordinary differential equaiton, is the correct sorting of equation ordering. To do so,
we must study the dependencies of equations. This requires a memory representation of
equations, and there we enter the domain of \sphinxstyleemphasis{computer algebra systems} (CAS). Their central
piece of information are algebraic equations, which are typically represented as
(abstract) \sphinxstyleemphasis{syntax trees}.

PyDDA was an effort to rewrite the Perl\sphinxhyphen{}based DDA with a minimal amount of work.
Exploiting that DDA looks almost like Python, the idea was to bring a number of
archivements with a single code:
\begin{itemize}
\item {} 
Allow to write high\sphinxhyphen{}level DDA codes, which probably involve indexing, n\sphinxhyphen{}dimensional
arrays, etc.

\item {} 
Allow for easy interoperation with various codes and tools, such as other CAS,
(evventually generated) numerical simulation codes  or reprogrammable analog computers.

\item {} 
Enable the user for a Read\sphinxhyphen{}eval\sphinxhyphen{}print loop interface (REPL) in order to encourage
explorative programming.

\item {} 
Meshing literate programming, generation of documentation and reports out of the
equations without much work

\item {} 
Picking the community where it is: Scientific Python is a thing, and so we choose
python. Thus we also can stick to python when it comes to simulation analysis and
postprocessing.

\item {} 
Avoid dependencies if not neccessary. Don’t reinvent the wheel, but try out how
far we can get without employing a large computer algebra system.

\end{itemize}


\subsection{I want to simulate electronics or solve an ODE. Do I really need DDA?}
\label{\detokenize{dda/rationale:i-want-to-simulate-electronics-or-solve-an-ode-do-i-really-need-dda}}
DDA is great if you want to learn about and work with analog computers.
Expressing your equations in terms of this domain specific hardware
description language (which includes all the “quirks” such as \sphinxstyleemphasis{negating}
operational amplifiers used for summation/integration) can be helpful
when it comes to implementing it on real analog computers. PyDDA is
also a helpful tool if you want to learn about numerical vs. analog
computing, or experiment with more challenging systems such as
partial differential equations.

If your goal is to simulate electronics on an advanced level, you might
want to look into the \sphinxhref{https://en.wikipedia.org/wiki/SPICE}{SPICE class}%
\begin{footnote}[46]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/SPICE}
%
\end{footnote}
of tools, such as \sphinxhref{http://ngspice.sourceforge.net/}{ngspice}%
\begin{footnote}[47]\sphinxAtStartFootnote
\sphinxnolinkurl{http://ngspice.sourceforge.net/}
%
\end{footnote}.

If your goal is to solve a differential equation or
to study a small system of interest, you better do so by using
tools particularly made for doing this job very well, such as
Matlab, GNU Octave or some computer algebra system. These are typically
mature systems with decades of development, while PyAnalog is a small
research code developed by a single person over a single year.

Especially small systems with only a few
unknowns, it is rather straightforward to transform them into analog
circuits once required, and you can safely postpone this task up to
when it gets relevant. The only thing to keep in mind is that when
developing your applications within another (assumably numerical)
toolkit, be careful about implementing your own algorithmic features.
Ideally, you straightforwardly implement a closed set of mathematical
equations in order to maintain the option to implement this system
on an analog computer, without touching the solution vector with
algorithms during the time evolution.

In fact, you even can do a scaling study without PyAnalog. Most
time evolution codes solve some ODE equation \(\dot y = f(y)\)
by allowing the user to implement the function \sphinxcode{\sphinxupquote{f(y)}} freely.
You could easily implement any checks on scaling within \sphinxcode{\sphinxupquote{f(y)}}
in your favourite programming language/tool
.


\section{PyDDA API reference}
\label{\detokenize{dda/api-reference:pydda-api-reference}}\label{\detokenize{dda/api-reference:dda-api}}\label{\detokenize{dda/api-reference::doc}}

\subsection{Abstract Syntax tree}
\label{\detokenize{dda/ast:module-dda.ast}}\label{\detokenize{dda/ast:id1}}\label{\detokenize{dda/ast:abstract-syntax-tree}}\label{\detokenize{dda/ast::doc}}\index{module@\spxentry{module}!dda.ast@\spxentry{dda.ast}}\index{dda.ast@\spxentry{dda.ast}!module@\spxentry{module}}
The minimalistic pythonic standalone abstract syntax tree (\sphinxstylestrong{AST})
representation in this module is the heart of the PyDDA package.
The code has no external dependencies, especially it does not rely
on a Computer Algebra System or even on SymPy.

The {\hyperref[\detokenize{dda/ast:dda.ast.Symbol}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{Symbol}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol}}) object represents a node in a AST and the edges
to it’s children. In order to simplify mass symbol generation,
{\hyperref[\detokenize{dda/ast:dda.ast.symbols}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{symbols()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.symbols}}) can be used.

The {\hyperref[\detokenize{dda/ast:dda.ast.State}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{State}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State}}) object represents a list (set) of equations.
It basically maps variables to their expressions. The {\hyperref[\detokenize{dda/ast:dda.ast.State}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{State}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State}})
represents a (traditional) DDA file. From a python perspective, a
{\hyperref[\detokenize{dda/ast:dda.ast.State}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{State}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State}}) is not much more then a dictionary on stereoids.
\index{Symbol (class in dda.ast)@\spxentry{Symbol}\spxextra{class in dda.ast}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{dda.ast.}}\sphinxbfcode{\sphinxupquote{Symbol}}}{\emph{\DUrole{n}{head}}, \emph{\DUrole{o}{*}\DUrole{n}{tail}}}{}
A symbol is similar to a LISP atom which has a Head and a tail,
where tail is a list. Common notations for such a type are
\begin{itemize}
\item {} 
\sphinxcode{\sphinxupquote{head{[}tail{]}}} in Mathematica,

\item {} 
\sphinxcode{\sphinxupquote{(head, tail)}} in Lisp

\item {} 
\sphinxcode{\sphinxupquote{head(tail)}} in C\sphinxhyphen{}like languages like Python, Perl, Fortran, C

\item {} 
Actually \sphinxcode{\sphinxupquote{{[}head, *tail{]}}} in Python, but we don’t use that.

\end{itemize}

A symbol also represents a vertex (node) and it’s childs in an ordered tree.
Think of head being the vertex and tail the (edge) list of children.
We use the Symbol class to represent the abstract syntax tree (AST)
of the DDA language for describing ODEs and circuitery.

When you call \sphinxcode{\sphinxupquote{str()}} or similar on instances of this class, it will
print its representation in the C\sphinxhyphen{}like notation. This notation is
identical to the “classical” DDA language.

There are two types of Symbols: \sphinxstylestrong{Variables} have no tail, they just
consist of a head:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}
\PYG{g+go}{x}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{o}{.}\PYG{n}{head}
\PYG{g+go}{\PYGZsq{}x\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{o}{.}\PYG{n}{tail}
\PYG{g+go}{()}
\end{sphinxVerbatim}

In contrast, \sphinxstylestrong{Terms} have a tail:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{f}\PYG{p}{)}
\PYG{g+go}{f(x, y)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{o}{.}\PYG{n}{head}
\PYG{g+go}{\PYGZsq{}f\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{o}{.}\PYG{n}{tail}
\PYG{g+go}{(x, y)}
\end{sphinxVerbatim}

Variables can be used to create complex expressions for which
they then serve for as a head:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{p}{,}\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
\PYG{g+go}{f(x, y)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{c+c1}{\PYGZsh{} example for kind of nonsensical terms:}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{f}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}
\PYG{g+go}{x(x, f, x)}
\end{sphinxVerbatim}

Calling a symbol will always replace it’s tail:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{(}\PYG{n}{y}\PYG{p}{)}
\PYG{g+go}{f(y)}
\end{sphinxVerbatim}

Symbols are equal to each other if their head and tail equals:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a1}\PYG{p}{,} \PYG{n}{a2} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a1} \PYG{o}{==} \PYG{n}{a2}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)} \PYG{o}{==} \PYG{n}{f}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)} \PYG{o}{==} \PYG{n}{f}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}
\PYG{g+go}{False}
\end{sphinxVerbatim}

Symbols can be used as dictionary keys, since they hash trivially
due to their unique canonical (pythonic) string interpretation.

\begin{sphinxadmonition}{note}{Note:}
In order to avoid confusion between Python Strings and Symbols,
you should
\begin{itemize}
\item {} 
\sphinxstyleemphasis{always} use strings as Symbol heads but

\item {} 
\sphinxstyleemphasis{never} use strings in Symbol tails. Instead, use there Symbols
only.

\end{itemize}

Think of Symbol implementing the following type (hint):
\sphinxcode{\sphinxupquote{Tuple{[}str, List{[}Symbol{]}{]}}}.

The DDA code helps you to follow this guide. For instance, the
representation of \sphinxcode{\sphinxupquote{f1}} shows that it is a symbol with two
string arguments, while \sphinxcode{\sphinxupquote{f2}} has symbol arguments:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f1} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f2} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f1}
\PYG{g+go}{f(\PYGZsq{}x\PYGZsq{}, \PYGZsq{}y\PYGZsq{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f2}
\PYG{g+go}{f(x, y)}
\end{sphinxVerbatim}

And DDA prevents you from shooting in your foot:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f}\PYG{p}{,} \PYG{n}{x}\PYG{p}{,} \PYG{n}{y} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{f,x,y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f3} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{n}{f}\PYG{p}{,}\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
\PYG{g+gt}{Traceback (most recent call last):}
\PYG{c}{...}
\PYG{g+gr}{TypeError}: \PYG{n}{Trying to initialize Symbol f(x, y) but head f is a Symbol, not a String.}
\end{sphinxVerbatim}

In previous versions of DDA, the thin line between strings and
symbols hasn’t been made so clear and tracing errors was harder.

Summing up, it is a good convention to \sphinxstyleemphasis{only} have Symbols and
floats/integers being part of the Symbol tails.
\end{sphinxadmonition}
\index{is\_variable() (dda.ast.Symbol method)@\spxentry{is\_variable()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.is_variable}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{is\_variable}}}{}{}
A variable is a symbol without a tail.

\end{fulllineitems}

\index{is\_term() (dda.ast.Symbol method)@\spxentry{is\_term()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.is_term}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{is\_term}}}{}{}
A term is a symbol with a tail.

\end{fulllineitems}

\index{variables() (dda.ast.Symbol method)@\spxentry{variables()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.variables}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{variables}}}{}{}
Compute the direct dependencies of this symbol, i.e. other variables
directly occuring in the tail.

\end{fulllineitems}

\index{all\_variables() (dda.ast.Symbol method)@\spxentry{all\_variables()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.all_variables}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{all\_variables}}}{}{}
Like :meth:variables, but also find variables in all children.

\end{fulllineitems}

\index{all\_terms() (dda.ast.Symbol method)@\spxentry{all\_terms()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.all_terms}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{all\_terms}}}{}{}
Like :meth:all\_variables, but for terms: Returns a list of all terms in all children of this node.

\end{fulllineitems}

\index{map\_heads() (dda.ast.Symbol method)@\spxentry{map\_heads()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.map_heads}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{map\_heads}}}{\emph{\DUrole{n}{mapping}}}{}
Call a mapping function on all heads in all (nested) subexpressions.
The mapping is effectively carried out on the head (ie. maps strings)
Returns a new mapped Symbol. This routine is suitable for renaming
variables and terms within an AST. Example usage:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}heads}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{head}\PYG{p}{:} \PYG{n}{head}\PYG{o}{+}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+go}{xfoo(yfoo, 2)}
\end{sphinxVerbatim}

The mapping is unaware of the AST context, so you have to distinguish
between variables and terms yourself if you need to. See also
{\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_variables}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_variables()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_variables}}) for context\sphinxhyphen{}aware head mapping. Compare these
examples to the ones given for {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_variables}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_variables()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_variables}}):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n+nb}{map}\PYG{p}{,} \PYG{n}{y} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{k}{lambda} \PYG{n}{\PYGZus{}}\PYG{p}{:} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{o}{.}\PYG{n}{map\PYGZus{}heads}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{x}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} == y}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}heads}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{y}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}heads}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{y}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{y}\PYG{p}{(}\PYG{n}{y}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{True}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{map\_variables() (dda.ast.Symbol method)@\spxentry{map\_variables()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.map_variables}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{map\_variables}}}{\emph{\DUrole{n}{mapping}}, \emph{\DUrole{n}{returns\_symbol}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Calls a mapping function on all variables within the (nested) subexpressions.
The mapping is effectively carried out on the head (ie. maps strings). This
is a mixture between {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_heads}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_heads()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_heads}}) and {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_tails}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_tails()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_tails}}).

Returns a new mapped Symbol. This routine is suitable for renaming
variables but not terms within the AST. Examples:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n+nb}{map}\PYG{p}{,} \PYG{n}{y} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{k}{lambda} \PYG{n}{\PYGZus{}}\PYG{p}{:} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{y}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{True}
\end{sphinxVerbatim}

This function ignores non\sphinxhyphen{}symbols as they cannot be variables. This is the same
as {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_tails}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_tails()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_tails}}) does and is handy when you have numbers within your expressions:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{expr} \PYG{o}{=} \PYG{n}{x}\PYG{p}{(}\PYG{l+m+mi}{123}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{l+m+mf}{9.1}\PYG{p}{)}\PYG{p}{,} \PYG{n}{x}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{l+m+mf}{0.1}\PYG{p}{,} \PYG{n}{x}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{res1} \PYG{o}{=} \PYG{n}{expr}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{xx}\PYG{p}{:} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{res2} \PYG{o}{=} \PYG{n}{expr}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{xx}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{returns\PYGZus{}symbol}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{res1} \PYG{o}{==} \PYG{n}{res2}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{res1}
\PYG{g+go}{x(123, x(9.1), y, x(y, 0.1, y))}
\end{sphinxVerbatim}

If you want to use \sphinxcode{\sphinxupquote{map\_variables}} to change a variable to a term, and/or if your
mapping function does not return strings but Symbols, use \sphinxcode{\sphinxupquote{returns\_symbol=True}}:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{x}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+m+mi}{123}\PYG{p}{)}\PYG{p}{,} \PYG{n}{returns\PYGZus{}symbol}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+go}{y(123)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}variables}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{x}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+m+mi}{123}\PYG{p}{)}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} this won\PYGZsq{}t work}
\PYG{g+gt}{Traceback (most recent call last):}
\PYG{c}{...}
\PYG{g+gr}{TypeError}: \PYG{n}{Trying to initialize Symbol y(123) but head y(123) is a Symbol, not a String.}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{map\_tails() (dda.ast.Symbol method)@\spxentry{map\_tails()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.map_tails}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{map\_tails}}}{\emph{\DUrole{n}{mapping}}, \emph{\DUrole{n}{map\_root}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Calls a mapping function on all tails in all (nested) subexpressions.
The mapping is carried out on the tail symbols (ie. maps Symbols).
Returns a new mapped Symbol. The routine is suitable for AST walking,
adding/removing stuff in the tails while preserving the root symbol.
This could also be called \sphinxcode{\sphinxupquote{map\_symbols}}, c.f. {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_terms}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_terms()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_terms}}).

Example for recursively wrapping all function calls:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,y,z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{z}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{smb}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{(}\PYG{n}{smb}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{x(foo(y), foo(z(foo(x))), foo(x(foo(y))))}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{z}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{k}{lambda} \PYG{n}{smb}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{(}\PYG{n}{smb}\PYG{p}{)}\PYG{p}{,} \PYG{n}{map\PYGZus{}root}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+go}{foo(x(foo(y), foo(z(foo(x))), foo(x(foo(y)))))}
\end{sphinxVerbatim}

Example for recursively removing certain unary functions \sphinxcode{\sphinxupquote{z(x)}} for any \sphinxcode{\sphinxupquote{x}}:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{remover} \PYG{o}{=} \PYG{k}{lambda} \PYG{n}{head}\PYG{p}{:} \PYG{k}{lambda} \PYG{n}{x}\PYG{p}{:} \PYG{n}{x}\PYG{o}{.}\PYG{n}{tail}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{Symbol}\PYG{p}{)} \PYG{o+ow}{and} \PYG{n}{x}\PYG{o}{.}\PYG{n}{head}\PYG{o}{==}\PYG{n}{head} \PYG{k}{else} \PYG{n}{x}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,y,z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{z}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{z}\PYG{p}{(}\PYG{n}{y}\PYG{p}{)}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{n}{remover}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{x(y, x, x(y, x))}
\end{sphinxVerbatim}

The argument \sphinxcode{\sphinxupquote{map\_root}} decides whether the map is run on the
root node or not. It will be \sphinxcode{\sphinxupquote{map\_root=False}} in any recursive use.
In former instances of this code, it was always \sphinxcode{\sphinxupquote{map\_root=False}}.
Example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{p}{(}\PYG{n}{a}\PYG{p}{,} \PYG{n}{b}\PYG{p}{)}\PYG{p}{,} \PYG{n}{flip} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a,b}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{k}{lambda} \PYG{n}{smb}\PYG{p}{:} \PYG{n}{b} \PYG{k}{if} \PYG{n}{smb}\PYG{o}{.}\PYG{n}{head}\PYG{o}{==}\PYG{n}{a}\PYG{o}{.}\PYG{n}{head} \PYG{k}{else} \PYG{n}{a}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{n}{flip}\PYG{p}{,} \PYG{n}{map\PYGZus{}root}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+go}{b}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{n}{flip}\PYG{p}{,} \PYG{n}{map\PYGZus{}root}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}
\PYG{g+go}{a(a, b, a)}
\end{sphinxVerbatim}

Note how the \sphinxcode{\sphinxupquote{flip}} function cuts every tail and returns variables only.
Here is a variant which perserves any tail:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{p}{(}\PYG{n}{a}\PYG{p}{,} \PYG{n}{b}\PYG{p}{)} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a,b}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{flipper} \PYG{o}{=} \PYG{k}{lambda} \PYG{n}{smb}\PYG{p}{:} \PYG{p}{(}\PYG{n}{b} \PYG{k}{if} \PYG{n}{smb}\PYG{o}{.}\PYG{n}{head}\PYG{o}{==}\PYG{n}{a}\PYG{o}{.}\PYG{n}{head} \PYG{k}{else} \PYG{n}{a}\PYG{p}{)}\PYG{p}{(}\PYG{o}{*}\PYG{n}{smb}\PYG{o}{.}\PYG{n}{tail}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{n}{flipper}\PYG{p}{,} \PYG{n}{map\PYGZus{}root}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+go}{b(a, b, a)}
\end{sphinxVerbatim}

Here is another example which highlights how \sphinxcode{\sphinxupquote{map\_tails}} can convert terms to
variables:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n+nb}{map}\PYG{p}{,} \PYG{n}{y} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{k}{lambda} \PYG{n}{\PYGZus{}}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{,} \PYG{n}{map\PYGZus{}root}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}
\PYG{g+go}{x(y, y)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}tails}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{,} \PYG{n}{map\PYGZus{}root}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}
\PYG{g+go}{x(y, y)}
\end{sphinxVerbatim}

For real\sphinxhyphen{}life examples, study for instance the source code of \sphinxcode{\sphinxupquote{cpp\_exporter}} or
grep any DDA code for \sphinxcode{\sphinxupquote{map\_tails}}.

See also {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_heads}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_heads()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_heads}}) and {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_variables}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_variables()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_variables}}) for variants.

\end{fulllineitems}

\index{map\_terms() (dda.ast.Symbol method)@\spxentry{map\_terms()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.map_terms}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{map\_terms}}}{\emph{\DUrole{n}{mapping}}, \emph{\DUrole{n}{returns\_symbol}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Calls a mapping function on all terms within the (nested) subexpressions.
The mapping is effectively carried out on the term head (ie. maps strings).
See {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_variables}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_variables()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_variables}}) for the similar\sphinxhyphen{}minded antoganist as well as
{\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_heads}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_heads()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_heads}}) and {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_tails}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_tails()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_tails}}) for more \sphinxstyleemphasis{low level} minded variants.

Returns a new mapped Symbol. This routine is suitable for renaming terms
but not variables within the AST. Examples:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n+nb}{map}\PYG{p}{,} \PYG{n}{y} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{k}{lambda} \PYG{n}{\PYGZus{}}\PYG{p}{:} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{o}{.}\PYG{n}{map\PYGZus{}terms}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{x}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}terms}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{y}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{x}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{map\PYGZus{}terms}\PYG{p}{(}\PYG{n+nb}{map}\PYG{p}{)} \PYG{o}{==} \PYG{n}{y}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{True}
\end{sphinxVerbatim}

This function ignores non\sphinxhyphen{}symbols as they cannot be variables, similar to
{\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_variables}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{map\_variables()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_variables}}).

It is basically \sphinxcode{\sphinxupquote{map\_terms(map) = map\_tails(lambda smb: Symbol(map(smb.head))(smbl.tail) if symb.is\_variable() else smb)}}.

The argument \sphinxcode{\sphinxupquote{returns\_symbol}} allows to discriminate between mapping
functions which return strings (for symbol heads) or symbols. The later
allows for manipulating expressions.

\end{fulllineitems}

\index{draw\_graph() (dda.ast.Symbol method)@\spxentry{draw\_graph()}\spxextra{dda.ast.Symbol method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.Symbol.draw_graph}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{draw\_graph}}}{\emph{\DUrole{n}{graph}\DUrole{o}{=}\DUrole{default_value}{None}}}{}
Uses graphviz to draw the AST down from this symbol.

See also {\color{red}\bfseries{}:method:\textasciigrave{}State.draw\_dependency\_graph\textasciigrave{}} for similar draph
drawing code and notes on python library dependencies.

\begin{sphinxadmonition}{note}{Note:}
This method constructs the graph by drawing edges between similar
named symbols. This will \sphinxstyleemphasis{not} represent the abstract syntax tree if
a single symbol head, regardless of whether variable or term, appears
twice.

If you want to draw the actual AST with this function, you have to make
each symbol (head) unique by giving them distinct names.
\end{sphinxadmonition}

Simple usage example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,y,z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{expression} \PYG{o}{=} \PYG{n}{x}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{n}{z}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{graph} \PYG{o}{=} \PYG{n}{expression}\PYG{o}{.}\PYG{n}{draw\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{graph}\PYG{p}{)}  
\PYG{g+go}{digraph \PYGZdq{}DDA\PYGZhy{}Symbol\PYGZdq{} \PYGZob{}}
\PYG{g+go}{   node [shape=doublecircle]}
\PYG{g+go}{   x}
\PYG{g+go}{   node [shape=circle]}
\PYG{g+go}{   x \PYGZhy{}\PYGZgt{} 1}
\PYG{g+go}{   node [shape=doublecircle]}
\PYG{g+go}{   y}
\PYG{g+go}{   node [shape=circle]}
\PYG{g+go}{   x \PYGZhy{}\PYGZgt{} y}
\PYG{g+go}{   x \PYGZhy{}\PYGZgt{} 2}
\PYG{g+go}{   node [shape=doublecircle]}
\PYG{g+go}{   z}
\PYG{g+go}{   node [shape=circle]}
\PYG{g+go}{   z \PYGZhy{}\PYGZgt{} 3}
\PYG{g+go}{   z \PYGZhy{}\PYGZgt{} 4}
\PYG{g+go}{   x \PYGZhy{}\PYGZgt{} z}
\PYG{g+go}{\PYGZcb{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{graph}\PYG{o}{.}\PYG{n}{view}\PYG{p}{(}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} Call this to draw the graph  }
\end{sphinxVerbatim}

\end{fulllineitems}


\end{fulllineitems}

\index{is\_symbol() (in module dda.ast)@\spxentry{is\_symbol()}\spxextra{in module dda.ast}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.is_symbol}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.ast.}}\sphinxbfcode{\sphinxupquote{is\_symbol}}}{\emph{\DUrole{n}{smbl}}}{}
Convenience function

\end{fulllineitems}

\index{symbols() (in module dda.ast)@\spxentry{symbols()}\spxextra{in module dda.ast}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.symbols}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.ast.}}\sphinxbfcode{\sphinxupquote{symbols}}}{\emph{\DUrole{o}{*}\DUrole{n}{query}}}{}
Quickly make symbol objects. Usage similar to sympy’s symbol function:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{,} \PYG{n}{b} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{b}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{z} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x, y, z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{topological\_sort() (in module dda.ast)@\spxentry{topological\_sort()}\spxextra{in module dda.ast}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.topological_sort}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.ast.}}\sphinxbfcode{\sphinxupquote{topological\_sort}}}{\emph{\DUrole{n}{dependency\_pairs}}}{}
Sort a graph (given as edge list) subject to dependency constraints.
The result are two lists: One for the sorted nodes, one for the
unsortable (cyclically dependent) nodes.

Implementation shamelessly stolen from \sphinxurl{https://stackoverflow.com/a/42359401}

\end{fulllineitems}

\index{State (class in dda.ast)@\spxentry{State}\spxextra{class in dda.ast}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{dda.ast.}}\sphinxbfcode{\sphinxupquote{State}}}{\emph{\DUrole{n}{initialdata}\DUrole{o}{=}\DUrole{default_value}{\{\}}}, \emph{\DUrole{n}{type\_peacemaking}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{n}{default\_symbol}\DUrole{o}{=}\DUrole{default_value}{True}}}{}
A state is a dictionary which is by convention a mapping from variable
names (as \sphinxstyleemphasis{strings}) to their symbolic meaning, i.e. a \sphinxcode{\sphinxupquote{Symbol()}}.
We refer to the keys in the dictionary as the \sphinxstyleemphasis{Left Hand Side} (LHS) and
the values in the dictionary as the \sphinxstyleemphasis{Right Hand Side} (RHS), in analogy
to an Equation.

\begin{sphinxadmonition}{note}{Note:}
Since \sphinxcode{\sphinxupquote{Symbol()}} spawns an AST, a state is a list of variable definitions.    
A DDA file is a collection of equations. Therefore, a state holds the
content of a DDA file.
\end{sphinxadmonition}

This class collects a number of basic helper routines for dealing with
states.

In order to simplify writing DDA files in Python, this class extends
the dictionary idiom with the following optional features, which
are turned on by default (but can be disabled by constructor
arguments \sphinxcode{\sphinxupquote{type\_peacemaking}} and \sphinxcode{\sphinxupquote{default\_symbol}}).
\begin{itemize}
\item {} 
\sphinxstylestrong{Type peacemaking}: Query a \sphinxcode{\sphinxupquote{Symbol()}}, get translated to
\sphinxcode{\sphinxupquote{str()}}:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{\PYGZcb{}}\PYG{p}{)}\PYG{p}{[}\PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{]} \PYG{o}{==} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+go}{True}
\end{sphinxVerbatim}

\item {} 
\sphinxstylestrong{Default Symbol}: Automatically add an entry when unknown:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{State}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{==} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+go}{True}
\end{sphinxVerbatim}

\end{itemize}

\begin{sphinxadmonition}{note}{Note:}
By intention, the keys of the State are always strings, never Symbols.
This also should make sure you don’t use complex ASTs for keys,
such as \sphinxcode{\sphinxupquote{Symbol("foo", "bar")}}.
\end{sphinxadmonition}

As \sphinxcode{\sphinxupquote{State\textasciigrave{}}} extends \sphinxcode{\sphinxupquote{collections.UserDict}}, you can access the underlying
dictionary:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{y} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{add}\PYG{p}{,} \PYG{n}{integrate} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{add}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{integrate}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{eqs} \PYG{o}{=} \PYG{p}{\PYGZob{}} \PYG{n}{x}\PYG{p}{:} \PYG{n}{add}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}\PYG{p}{,} \PYG{n}{y}\PYG{p}{:} \PYG{n}{integrate}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)} \PYG{p}{\PYGZcb{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{n}{eqs}\PYG{p}{)}\PYG{p}{;} \PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: add(y, y), \PYGZsq{}y\PYGZsq{}: integrate(x)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{o}{.}\PYG{n}{data}
\PYG{g+go}{\PYGZob{}\PYGZsq{}x\PYGZsq{}: add(y, y), \PYGZsq{}y\PYGZsq{}: integrate(x)\PYGZcb{}}
\end{sphinxVerbatim}

\begin{sphinxadmonition}{warning}{Warning:}
Don’t be fooled by refering to the state while constructing the state. This
will end up in overly complex expressions. By rule of thumb, only use
\sphinxcode{\sphinxupquote{Symbols}} at the state definition (or in particular on the right hand side).
For instance, you do want to construct a state like

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{add}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{int}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: add(y, y), \PYGZsq{}y\PYGZsq{}: int(x)\PYGZcb{})}
\end{sphinxVerbatim}

In contrast, this is most likely not what you want:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{add}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{int}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: add(y, y), \PYGZsq{}y\PYGZsq{}: int(add(y, y))\PYGZcb{})}
\end{sphinxVerbatim}

This time, you did not exploit the definition of \sphinxcode{\sphinxupquote{state{[}"x"{]}}} by referencing
on DDA level but instead inserted the expression by referencing on Python
level. This is like \sphinxstyleemphasis{compile\sphinxhyphen{}time evaluation} versus \sphinxstyleemphasis{runtime evaluation},
when \sphinxstyleemphasis{compile\sphinxhyphen{}time} is at python and \sphinxstyleemphasis{runtime} is when evaluating the DDA
expressions in some time evolution code.

Summing up, the mistake above is to reference to \sphinxcode{\sphinxupquote{state}} while constructing7
the \sphinxcode{\sphinxupquote{state}}. You should not do that. You go best by defining the \sphinxcode{\sphinxupquote{Symbol}}
instances before and then only using them all over the place:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{add}\PYG{p}{,} \PYG{n+nb}{int} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x, y, add, int}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{n}{x}\PYG{p}{]} \PYG{o}{=} \PYG{n}{add}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{n}{y}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: add(y, y), \PYGZsq{}y\PYGZsq{}: int(x)\PYGZcb{})}
\end{sphinxVerbatim}
\end{sphinxadmonition}

\begin{sphinxadmonition}{note}{Note:}
Why the name? The class name \sphinxcode{\sphinxupquote{State}} seems arbitrary and quirky, \sphinxcode{\sphinxupquote{System}} may
be a better choice (given that the class instances hold an equation system).
However, one could also argue that the class instances hold the definition for
a system in a particular state. especially, \sphinxcode{\sphinxupquote{State.keys()}} are the state
variables which undergo a definition by their corresponding \sphinxcode{\sphinxupquote{State.values()}}.
Most CAS do not have a special class for collections of equations. Instead,
they typically have some \sphinxstyleemphasis{equation} type and equation systems are sets or lists
of equations. In PyDDA, we don’t have an equation type because the DDA domain
specific language (see \sphinxcode{\sphinxupquote{dsl}}) doesn’t provide advanced treatments of
equations but is basically only a lengthy definition of a set of equations,
which you could understand as a mapping/dictionary data type defining the state
of the system. That’s why \sphinxtitleref{State} is actually an enriched \sphinxtitleref{dict}.
\end{sphinxadmonition}
\index{from\_string() (dda.ast.State class method)@\spxentry{from\_string()}\spxextra{dda.ast.State class method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.from_string}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{classmethod }}\sphinxbfcode{\sphinxupquote{from\_string}}}{\emph{\DUrole{o}{*}\DUrole{n}{string\_or\_list\_of\_strings}}}{}
Shorthand for \sphinxcode{\sphinxupquote{dsl.read\_traditional\_dda()}}. Returns new instance.

\end{fulllineitems}

\index{to\_string() (dda.ast.State method)@\spxentry{to\_string()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.to_string}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{to\_string}}}{}{}
Shorthand for \sphinxcode{\sphinxupquote{dsl.to\_traditional\_dda()}}. Returns a string (representation).

\end{fulllineitems}

\index{update() (dda.ast.State method)@\spxentry{update()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.update}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{update}}}{\sphinxoptional{\emph{E}}, \emph{**F}}{{ $\rightarrow$ None.  Update D from mapping/iterable E and F.}}
If E present and has a .keys() method, does:     for k in E: D{[}k{]} = E{[}k{]}
If E present and lacks .keys() method, does:     for (k, v) in E: D{[}k{]} = v
In either case, this is followed by: for k, v in F.items(): D{[}k{]} = v

\end{fulllineitems}

\index{equation\_adder() (dda.ast.State method)@\spxentry{equation\_adder()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.equation_adder}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{equation\_adder}}}{}{}
Syntactic sugar for adding new equations to the system. Usage:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z}\PYG{p}{,}\PYG{n}{add}\PYG{p}{,}\PYG{n+nb}{int} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,y,z,add,int}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{eq} \PYG{o}{=} \PYG{n}{state}\PYG{o}{.}\PYG{n}{equation\PYGZus{}adder}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{eq}\PYG{p}{(}\PYG{n}{y}\PYG{o}{=}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{eq}\PYG{p}{(}\PYG{n}{x}\PYG{o}{=}\PYG{n}{add}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z}\PYG{p}{)}\PYG{p}{,} \PYG{n}{z}\PYG{o}{=}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mf}{0.1}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: add(y, z), \PYGZsq{}y\PYGZsq{}: int(x), \PYGZsq{}z\PYGZsq{}: int(x, 0, 0.1)\PYGZcb{})}
\end{sphinxVerbatim}

Known limitations: This doesn’t work any better then the \sphinxcode{\sphinxupquote{BreveState}}
below because keywords must not be variables, they will always resolve
to their string representation.

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{foo} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s1}\PYG{p}{,} \PYG{n}{s2} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{eq1} \PYG{o}{=} \PYG{n}{s1}\PYG{o}{.}\PYG{n}{equation\PYGZus{}adder}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{eq1}\PYG{p}{(}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mi}{42}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s2}\PYG{p}{[}\PYG{n}{foo}\PYG{p}{]} \PYG{o}{=} \PYG{l+m+mi}{42}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s1}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}foo\PYGZsq{}: 42\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s2}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}bar\PYGZsq{}: 42\PYGZcb{})}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{map\_tails() (dda.ast.State method)@\spxentry{map\_tails()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.map_tails}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{map\_tails}}}{\emph{\DUrole{n}{mapper}}, \emph{\DUrole{n}{map\_root}\DUrole{o}{=}\DUrole{default_value}{True}}}{}
Apply {\hyperref[\detokenize{dda/ast:dda.ast.Symbol.map_tails}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{Symbol.map\_tails()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.Symbol.map_tails}}) on all right hand sides.

\end{fulllineitems}

\index{map\_heads() (dda.ast.State method)@\spxentry{map\_heads()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.map_heads}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{map\_heads}}}{\emph{\DUrole{n}{mapper}}}{}
This function is suitable for renaming variables.
mapper is always executed on the string variable names (Symbol heads)

\end{fulllineitems}

\index{symbols() (dda.ast.State method)@\spxentry{symbols()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.symbols}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{symbols}}}{\emph{\DUrole{o}{*}\DUrole{n}{query}}}{}
Same as {\hyperref[\detokenize{dda/ast:dda.ast.symbols}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{symbols()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.symbols}}) above, but register at self (state)

\end{fulllineitems}

\index{constant\_validity() (dda.ast.State method)@\spxentry{constant\_validity()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.constant_validity}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{constant\_validity}}}{}{}
Check validity of numeric constants in the state.
Depending on context, values \sphinxhyphen{}1 \textless{} t \textless{} +1 are illegal.

(Not yet implemented!)

\end{fulllineitems}

\index{dependency\_graph() (dda.ast.State method)@\spxentry{dependency\_graph()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.dependency_graph}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{dependency\_graph}}}{}{}
Returns the edge list of the variable dependency graph of this state.
We can call {\hyperref[\detokenize{dda/ast:dda.ast.topological_sort}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{topological\_sort()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.topological_sort}}) on the result of this method.

A weird example including some corner cases:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s1} \PYG{o}{=} \PYG{n}{State}\PYG{o}{.}\PYG{n}{from\PYGZus{}string}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo = const(0.7)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar=mult(bar,baz)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{baz=f(bar)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s1}\PYG{o}{.}\PYG{n}{dependency\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{[(\PYGZsq{}bar\PYGZsq{}, \PYGZsq{}bar\PYGZsq{}), (\PYGZsq{}bar\PYGZsq{}, \PYGZsq{}baz\PYGZsq{}), (\PYGZsq{}baz\PYGZsq{}, \PYGZsq{}bar\PYGZsq{})]}
\end{sphinxVerbatim}

Another even more weird example which exploits raw value assignment,
something which is not following the \sphinxcode{\sphinxupquote{foo=call(bar)}} requirement for DDA
files:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{,}\PYG{n}{c}\PYG{p}{,}\PYG{n}{d}\PYG{p}{,}\PYG{n}{f} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a,b,c,d,f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s2} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{a}\PYG{p}{:} \PYG{n}{f}\PYG{p}{(}\PYG{l+m+mf}{0.7}\PYG{p}{)}\PYG{p}{,} \PYG{n}{b}\PYG{p}{:} \PYG{n}{c}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{b}\PYG{p}{)}\PYG{p}{,} \PYG{n}{c}\PYG{p}{:} \PYG{l+m+mi}{42}\PYG{p}{,} \PYG{n}{d}\PYG{p}{:} \PYG{n}{c} \PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s2}\PYG{o}{.}\PYG{n}{dependency\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{[(\PYGZsq{}b\PYGZsq{}, \PYGZsq{}b\PYGZsq{}), (\PYGZsq{}d\PYGZsq{}, \PYGZsq{}c\PYGZsq{})]}
\end{sphinxVerbatim}

Note that this function always returns list of tuples of strings. No more
symbols. See also {\hyperref[\detokenize{dda/ast:dda.ast.State.draw_dependency_graph}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{draw\_dependency\_graph()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State.draw_dependency_graph}}) for a quick way of exporting
or plotting this graph.

\end{fulllineitems}

\index{draw\_dependency\_graph() (dda.ast.State method)@\spxentry{draw\_dependency\_graph()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.draw_dependency_graph}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{draw\_dependency\_graph}}}{\emph{\DUrole{n}{export\_dot}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{n}{dot\_filename}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}test.dot\textquotesingle{}}}}{}
If you have \sphinxcode{\sphinxupquote{networkx}} and \sphinxcode{\sphinxupquote{pyGraphViz}} installed, you can use this method
to draw the \sphinxstyleemphasis{variable dependency graph} (see method {\hyperref[\detokenize{dda/ast:dda.ast.State.dependency_graph}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dependency\_graph()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State.dependency_graph}}))
with \sphinxcode{\sphinxupquote{Dot}}/\sphinxcode{\sphinxupquote{GraphViz}}. This method will return the \sphinxcode{\sphinxupquote{nx.DiGraph()}} instance.
If \sphinxcode{\sphinxupquote{export\_dot}} is set, it will also write a dotfile, call \sphinxcode{\sphinxupquote{dot}} to
render it to a bitmap and open that bitmap.

\begin{sphinxadmonition}{note}{Note:}
Your distribution package \sphinxcode{\sphinxupquote{python\sphinxhyphen{}graphviz}} is probably not \sphinxcode{\sphinxupquote{pygraphviz}}.
You are on the safe side if you run: \sphinxcode{\sphinxupquote{pip install pygraphviz}}
\end{sphinxadmonition}

\end{fulllineitems}

\index{name\_computing\_elements() (dda.ast.State method)@\spxentry{name\_computing\_elements()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.name_computing_elements}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{name\_computing\_elements}}}{\emph{\DUrole{n}{strict}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Name all computing elements / intermediate expressions. Returns
a new State which is \sphinxstyleemphasis{linearized} in a way that the numbering proposes a computing
order.

Linearization is an idempotent operation, i.e. for any
\sphinxcode{\sphinxupquote{lin = state.name\_computing\_elements()}} it is \sphinxcode{\sphinxupquote{lin == lin.name\_computing\_elements()}}.
Mathematically, it is a projection of the state on its linearized one.

Linearization means to define a evaluation order and to give unique names
to all terms occuring. Note that \sphinxstyleemphasis{all} depends on the strictness (\sphinxtitleref{strict=True} vs.
the default \sphinxtitleref{strict=False}):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n+nb}{sum}\PYG{p}{,} \PYG{n}{mult} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x, y, sum, mult}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ns} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{x}\PYG{p}{:} \PYG{n+nb}{sum}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,} \PYG{n+nb}{sum}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{mult}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{y}\PYG{p}{:} \PYG{n}{mult}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{ns}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to\PYGZus{}string}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}              
\PYG{g+go}{mult\PYGZus{}1 = mult(y, x)}
\PYG{g+go}{sum\PYGZus{}1 = sum(y, mult\PYGZus{}1)}
\PYG{g+go}{x = sum(x, y, sum\PYGZus{}1)}
\PYG{g+go}{y = mult(x)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{ns}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to\PYGZus{}string}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}   
\PYG{g+go}{mult\PYGZus{}1 = mult(y, x)}
\PYG{g+go}{mult\PYGZus{}2 = mult(x)}
\PYG{g+go}{sum\PYGZus{}1 = sum(y, mult\PYGZus{}1)}
\PYG{g+go}{sum\PYGZus{}2 = sum(x, y, sum\PYGZus{}1)}
\PYG{g+go}{x = sum\PYGZus{}2}
\PYG{g+go}{y = mult\PYGZus{}2}
\end{sphinxVerbatim}

Here, \sphinxstyleemphasis{strict} means that really \sphinxstyleemphasis{every} term is labeled, even if this yields in “dumb”
assignments such as \sphinxcode{\sphinxupquote{x = sum\_2}}. You want a strict naming when enumerating computing elements,
while a non\sphinxhyphen{}strict naming is preferable for brief evaluation. Also note that

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{const} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,const}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{x}\PYG{p}{:} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{42}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: const(42)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{x}\PYG{p}{:} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{42}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}const\PYGZus{}1\PYGZsq{}: const(42), \PYGZsq{}x\PYGZsq{}: const\PYGZus{}1\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{x}\PYG{p}{:} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{42}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)} 
\PYG{g+go}{/.../ast.py:819: UserWarning: State.named\PYGZus{}computing\PYGZus{}elements(): While counting const, I notice that  const\PYGZus{}1 is already part of the state. Maybe you want to run name\PYGZus{}computing\PYGZus{}elements(strict=False) for idempotence.}
\PYG{g+go}{  warnings.warn(...)}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}const\PYGZus{}1\PYGZsq{}: const\PYGZus{}1\PYGZus{}, \PYGZsq{}const\PYGZus{}1\PYGZus{}\PYGZsq{}: const(42), \PYGZsq{}x\PYGZsq{}: const\PYGZus{}1\PYGZcb{})}
\end{sphinxVerbatim}

On this mini example, one especially sees that idempotence is only given when \sphinxcode{\sphinxupquote{strict=False}}. 
It is \sphinxcode{\sphinxupquote{state.name\_computing\_elements(True) == state.name\_computing\_elements(s{[}0{]}).name\_computing\_elements(s{[}1{]})....name\_computing\_elements(s{[}n{]})}}
when \sphinxcode{\sphinxupquote{s}} is a boolean array of \sphinxcode{\sphinxupquote{len(s)==n}} and \sphinxcode{\sphinxupquote{sum(s) == 1}}, i.e. only one
occurence of \sphinxcode{\sphinxupquote{strict=True}} and all other \sphinxcode{\sphinxupquote{False}}.

The linearized state only has entries of a \sphinxstyleemphasis{normal form} \sphinxcode{\sphinxupquote{state{[}f\_i{]} = f(v1,v2,...)}}
for a function (term) \sphinxcode{\sphinxupquote{f}} and some variables \sphinxcode{\sphinxupquote{v\_j}}. Furthermore note how even
\sphinxcode{\sphinxupquote{x = sum\_2}} in the above example indirects the former assignment of \sphinxcode{\sphinxupquote{x = sum(x,y...)}}.
Again, for any value in the linearized state, the tail only contains variables,
no terms. This is handy for many things, such as circuit drawing, imperative
evaluation (in combination with {\hyperref[\detokenize{dda/ast:dda.ast.State.variable_ordering}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{variable\_ordering()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State.variable_ordering}}), cf. \sphinxcode{\sphinxupquote{cpp\_exporter}})
and determination of integrands/actual variables. For instance

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s} \PYG{o}{=} \PYG{n}{State}\PYG{o}{.}\PYG{n}{from\PYGZus{}string}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo = const(0.7)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{baz=mult(bar,bar)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar = neg(int(neg(baz), foo, 0.3))}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}bar\PYGZsq{}: neg(int(neg(baz), foo, 0.3)), \PYGZsq{}baz\PYGZsq{}: mult(bar, bar), \PYGZsq{}foo\PYGZsq{}: const(0.7)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{s}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to\PYGZus{}string}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}    
\PYG{g+go}{bar = neg\PYGZus{}2}
\PYG{g+go}{baz = mult\PYGZus{}1}
\PYG{g+go}{const\PYGZus{}1 = const(0.7)}
\PYG{g+go}{foo = const\PYGZus{}1}
\PYG{g+go}{int\PYGZus{}1 = int(neg\PYGZus{}1, foo, 0.3)}
\PYG{g+go}{mult\PYGZus{}1 = mult(bar, bar)}
\PYG{g+go}{neg\PYGZus{}1 = neg(baz)}
\PYG{g+go}{neg\PYGZus{}2 = neg(int\PYGZus{}1)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{s}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to\PYGZus{}string}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}    
\PYG{g+go}{bar = neg(int\PYGZus{}1)}
\PYG{g+go}{baz = mult(bar, bar)}
\PYG{g+go}{foo = const(0.7)}
\PYG{g+go}{int\PYGZus{}1 = int(neg\PYGZus{}1, foo, 0.3)}
\PYG{g+go}{neg\PYGZus{}1 = neg(baz)}
\end{sphinxVerbatim}

Here one sees immediately that \sphinxcode{\sphinxupquote{int\_1}} is the actual integral solution while
\sphinxcode{\sphinxupquote{bar}} is only a derived quantity. Calls like \sphinxcode{\sphinxupquote{const(float)}} remain unchanged
since they are already in the normal form \sphinxcode{\sphinxupquote{f(v1,v2,...)}}.

Here is a more complex example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{computing\PYGZus{}elements} \PYG{k+kn}{import} \PYG{n}{neg}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{,}\PYG{n}{mult}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.005}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.005}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{variable\PYGZus{}ordering}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{where\PYGZus{}is} 
\PYG{g+go}{\PYGZob{}\PYGZsq{}x\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{\PYGZsq{}mult\PYGZus{}1\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{\PYGZsq{}neg\PYGZus{}2\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{\PYGZsq{}neg\PYGZus{}1\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{\PYGZsq{}int\PYGZus{}1\PYGZsq{}: \PYGZsq{}vars.evolved\PYGZsq{},}
\PYG{g+go}{\PYGZsq{}int\PYGZus{}2\PYGZsq{}: \PYGZsq{}vars.evolved\PYGZsq{}\PYGZcb{}}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{variable\_ordering() (dda.ast.State method)@\spxentry{variable\_ordering()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.variable_ordering}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{variable\_ordering}}}{}{}
Will perform an analysis of all variables occuring in this state (especially in the RHS).
This is based on the linarized variant of this state (see {\hyperref[\detokenize{dda/ast:dda.ast.State.name_computing_elements}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{name\_computing\_elements()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State.name_computing_elements}})).

The return value is an object (actually a types.SimpleNamespace instance) which contains
lists of variable names (as strings). The properties (categories) are primarly
\begin{itemize}
\item {} 
explicit constants: Any entry \sphinxcode{\sphinxupquote{state{[}"foo"{]} = const(1.234)}}

\item {} 
State variables/evolved variables: Any outcome of a time integration, i.e. \sphinxcode{\sphinxupquote{int(...)}},
i.e. \sphinxcode{\sphinxupquote{Symbol("int")}}. This can be as simple as \sphinxcode{\sphinxupquote{state{[}"foo"{]} = int(Symbol("foo"),...)}}.
Complex terms such as \sphinxcode{\sphinxupquote{state{[}"foo"{]} = mult(int(foo), int(bar))}} will result in
intermediate variables called like \sphinxcode{\sphinxupquote{int\_0}}, {\color{red}\bfseries{}\textasciigrave{}\textasciigrave{}}int\_1\textasciigrave{}\textasciigrave{}(see {\hyperref[\detokenize{dda/ast:dda.ast.State.name_computing_elements}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{name\_computing\_elements()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State.name_computing_elements}})
for the code which invents these names), which are the actual evolved variables.

\item {} 
Auxilliary variables: Any other variables which are required to compute evolved
variables.

\end{itemize}

By intention, we \sphinxstylestrong{sort only the aux. variables}. One should check that they DO NOT have any
cyclic dependency, because feedback loops are only useful on integrators at this level
of circuit modeling.

We differntiate the auxilliaries further into:
\begin{itemize}
\item {} 
\sphinxcode{\sphinxupquote{sorted\_aux\_vars}}: Auxilliaries required to compute the state variable changes

\item {} 
\sphinxcode{\sphinxupquote{cyclic\_aux\_vars}}: Auxilliaries which have a cyclic dependency on each other
(this should not happen as it won’t lead to a stable circuit)

\item {} 
\sphinxcode{\sphinxupquote{unneeded\_auxers}}: Auxilliaries which are not required to compute the state.
These are probably used in postprocessing. If they depend on the state variables,
further work is neccessary.

\end{itemize}

Given an ODE problem \sphinxcode{\sphinxupquote{dq/dt = f(q)}}, an imperative code for evolving the state
\sphinxcode{\sphinxupquote{q}} in time  should compute all auxillairy variables in the respective order
before computing the actual \sphinxcode{\sphinxupquote{dq/dt}}. The dependency is basically, in pseudo code:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{aux}  \PYG{o}{=} \PYG{n}{function\PYGZus{}of}\PYG{p}{(}\PYG{n}{aux}\PYG{p}{,} \PYG{n}{state}\PYG{p}{)}                    
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dqdt} \PYG{o}{=} \PYG{n}{function\PYGZus{}of}\PYG{p}{(}\PYG{n}{aux}\PYG{p}{,} \PYG{n}{state}\PYG{p}{)}                    
\end{sphinxVerbatim}

and in the numerical integration schema step

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{function\PYGZus{}of}\PYG{p}{(}\PYG{n}{dqdt}\PYG{p}{)}                         
\end{sphinxVerbatim}

This method returns a namespace object, which is basically a fancy dictionary. It
is used over a simple dictionary just for shorter syntax.

The following examples demonstrate a deeply nested corner case, i.e. a 
compute graph consisting of a single “long” Euler cycle. By breaking up this
cycle at the integrations, \sphinxcode{\sphinxupquote{variable\_ordering()}} can linearize these cycles
correctly. This works both for non\sphinxhyphen{}strict and strict element naming.

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{computing\PYGZus{}elements} \PYG{k+kn}{import} \PYG{n}{neg}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{,}\PYG{n}{mult}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.005}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.005}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{c+c1}{\PYGZsh{} variable ordering is made based on non\PYGZhy{}strict naming:}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)} 
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}int\PYGZus{}1\PYGZsq{}: int(neg\PYGZus{}1),}
\PYG{g+go}{       \PYGZsq{}int\PYGZus{}2\PYGZsq{}: int(neg\PYGZus{}2),}
\PYG{g+go}{       \PYGZsq{}mult\PYGZus{}1\PYGZsq{}: mult(1, x),}
\PYG{g+go}{       \PYGZsq{}neg\PYGZus{}1\PYGZsq{}: neg(mult\PYGZus{}1, 0.005, 1),}
\PYG{g+go}{       \PYGZsq{}neg\PYGZus{}2\PYGZsq{}: neg(int\PYGZus{}1, 0.005, 0),}
\PYG{g+go}{       \PYGZsq{}x\PYGZsq{}: neg(int\PYGZus{}2)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)} 
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}int\PYGZus{}1\PYGZsq{}: int(neg\PYGZus{}1),}
\PYG{g+go}{\PYGZsq{}int\PYGZus{}2\PYGZsq{}: int(neg\PYGZus{}2),}
\PYG{g+go}{\PYGZsq{}mult\PYGZus{}1\PYGZsq{}: mult(1, x),}
\PYG{g+go}{\PYGZsq{}neg\PYGZus{}1\PYGZsq{}: neg(mult\PYGZus{}1, 0.005, 1),}
\PYG{g+go}{\PYGZsq{}neg\PYGZus{}2\PYGZsq{}: neg(int\PYGZus{}1, 0.005, 0),}
\PYG{g+go}{\PYGZsq{}neg\PYGZus{}3\PYGZsq{}: neg(int\PYGZus{}2),}
\PYG{g+go}{\PYGZsq{}x\PYGZsq{}: neg\PYGZus{}3\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{c+c1}{\PYGZsh{} This is how the full output looks like}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state}\PYG{o}{.}\PYG{n}{variable\PYGZus{}ordering}\PYG{p}{(}\PYG{p}{)}  
\PYG{g+go}{namespace(aux=namespace(all=[\PYGZsq{}mult\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}2\PYGZsq{}, \PYGZsq{}x\PYGZsq{}],}
\PYG{g+go}{                        sorted=[\PYGZsq{}x\PYGZsq{}, \PYGZsq{}mult\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}2\PYGZsq{}, \PYGZsq{}neg\PYGZus{}1\PYGZsq{}],}
\PYG{g+go}{                        cyclic=[],}
\PYG{g+go}{                        unneeded=set()),}
\PYG{g+go}{          evolved=[\PYGZsq{}int\PYGZus{}1\PYGZsq{}, \PYGZsq{}int\PYGZus{}2\PYGZsq{}],}
\PYG{g+go}{          explicit\PYGZus{}constants=[],}
\PYG{g+go}{          all=[\PYGZsq{}int\PYGZus{}1\PYGZsq{}, \PYGZsq{}int\PYGZus{}2\PYGZsq{}, \PYGZsq{}mult\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}2\PYGZsq{}, \PYGZsq{}x\PYGZsq{}],}
\PYG{g+go}{          ordering=OrderedDict([(\PYGZsq{}vars.explicit\PYGZus{}constants\PYGZsq{}, []),}
\PYG{g+go}{                                (\PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{                                 [\PYGZsq{}x\PYGZsq{}, \PYGZsq{}mult\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}2\PYGZsq{}, \PYGZsq{}neg\PYGZus{}1\PYGZsq{}]),}
\PYG{g+go}{                                (\PYGZsq{}vars.aux.cyclic\PYGZsq{}, []),}
\PYG{g+go}{                                (\PYGZsq{}vars.evolved\PYGZsq{}, [\PYGZsq{}int\PYGZus{}1\PYGZsq{}, \PYGZsq{}int\PYGZus{}2\PYGZsq{}]),}
\PYG{g+go}{                                (\PYGZsq{}vars.aux.unneeded\PYGZsq{}, set())]),}
\PYG{g+go}{          where\PYGZus{}is=\PYGZob{}\PYGZsq{}int\PYGZus{}1\PYGZsq{}: \PYGZsq{}vars.evolved\PYGZsq{},}
\PYG{g+go}{                    \PYGZsq{}int\PYGZus{}2\PYGZsq{}: \PYGZsq{}vars.evolved\PYGZsq{},}
\PYG{g+go}{                    \PYGZsq{}mult\PYGZus{}1\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{                    \PYGZsq{}neg\PYGZus{}1\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{                    \PYGZsq{}neg\PYGZus{}2\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{},}
\PYG{g+go}{                    \PYGZsq{}x\PYGZsq{}: \PYGZsq{}vars.aux.sorted\PYGZsq{}\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{c+c1}{\PYGZsh{} Compare the strict and nonstrict orderings:}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{for} \PYG{n}{k}\PYG{p}{,} \PYG{n}{v} \PYG{o+ow}{in} \PYG{n}{dda\PYGZus{}state}\PYG{o}{.}\PYG{n}{variable\PYGZus{}ordering}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{ordering}\PYG{o}{.}\PYG{n}{items}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{k}\PYG{l+s+si}{:}\PYG{l+s+s2}{25s}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{: }\PYG{l+s+si}{\PYGZob{}}\PYG{n}{v}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+go}{vars.explicit\PYGZus{}constants  : []}
\PYG{g+go}{vars.aux.sorted          : [\PYGZsq{}x\PYGZsq{}, \PYGZsq{}mult\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}2\PYGZsq{}, \PYGZsq{}neg\PYGZus{}1\PYGZsq{}]}
\PYG{g+go}{vars.aux.cyclic          : []}
\PYG{g+go}{vars.evolved             : [\PYGZsq{}int\PYGZus{}1\PYGZsq{}, \PYGZsq{}int\PYGZus{}2\PYGZsq{}]}
\PYG{g+go}{vars.aux.unneeded        : set()}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{for} \PYG{n}{k}\PYG{p}{,} \PYG{n}{v} \PYG{o+ow}{in} \PYG{n}{dda\PYGZus{}state}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{n}{strict}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}\PYG{o}{.}\PYG{n}{variable\PYGZus{}ordering}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{ordering}\PYG{o}{.}\PYG{n}{items}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{k}\PYG{l+s+si}{:}\PYG{l+s+s2}{25s}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{: }\PYG{l+s+si}{\PYGZob{}}\PYG{n}{v}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+go}{vars.explicit\PYGZus{}constants  : []}
\PYG{g+go}{vars.aux.sorted          : [\PYGZsq{}neg\PYGZus{}3\PYGZsq{}, \PYGZsq{}x\PYGZsq{}, \PYGZsq{}mult\PYGZus{}1\PYGZsq{}, \PYGZsq{}neg\PYGZus{}2\PYGZsq{}, \PYGZsq{}neg\PYGZus{}1\PYGZsq{}]}
\PYG{g+go}{vars.aux.cyclic          : []}
\PYG{g+go}{vars.evolved             : [\PYGZsq{}int\PYGZus{}1\PYGZsq{}, \PYGZsq{}int\PYGZus{}2\PYGZsq{}]}
\PYG{g+go}{vars.aux.unneeded        : set()}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{remove\_duplicates() (dda.ast.State method)@\spxentry{remove\_duplicates()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.remove_duplicates}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{remove\_duplicates}}}{}{}
Assuming a linearized state, this function simplifies the system by removing/resolving
duplicate entries. No further renaming takes place: Always the first encounter of a
term determines the name for all equivalent terms.

Returns a new state.

\end{fulllineitems}

\index{term\_statistics() (dda.ast.State method)@\spxentry{term\_statistics()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.term_statistics}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{term\_statistics}}}{}{}
Assuming a linearized state, tells how much each term occurs within this state.
Returns instance of \sphinxcode{\sphinxupquote{collections.Counter}}. For simplicity, the term heads
are returned as strings.

Typical usage is like \sphinxcode{\sphinxupquote{state.name\_computing\_elements().remove\_duplicates().term\_statistics()}}

\end{fulllineitems}

\index{export() (dda.ast.State method)@\spxentry{export()}\spxextra{dda.ast.State method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.State.export}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{export}}}{\emph{\DUrole{n}{to}}, \emph{\DUrole{o}{**}\DUrole{n}{passed\_args}}}{}
Syntactic sugar for dda.export(), for convenience

\end{fulllineitems}


\end{fulllineitems}

\index{BreveState (class in dda.ast)@\spxentry{BreveState}\spxextra{class in dda.ast}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/ast:dda.ast.BreveState}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{dda.ast.}}\sphinxbfcode{\sphinxupquote{BreveState}}}{\emph{\DUrole{n}{initialdata}\DUrole{o}{=}\DUrole{default_value}{\{\}}}, \emph{\DUrole{n}{type\_peacemaking}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{n}{default\_symbol}\DUrole{o}{=}\DUrole{default_value}{True}}}{}
This subclass of a state adds \sphinxstyleemphasis{syntactic sugar} by allowing attribute/member access
notation. Instead of \sphinxcode{\sphinxupquote{state{[}"foo"{]}}} you can write \sphinxcode{\sphinxupquote{state.foo}} on instances of
this class. Example usage:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,y,z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{BreveState}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{o}{.}\PYG{n}{x} \PYG{o}{=} \PYG{n}{x}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,}\PYG{n}{z}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{o}{.}\PYG{n}{y} \PYG{o}{=} \PYG{n}{y}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{z}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{o}{.}\PYG{n}{z} \PYG{o}{=} \PYG{n}{z}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}
\PYG{g+go}{BreveState(\PYGZob{}\PYGZsq{}x\PYGZsq{}: x(y, z), \PYGZsq{}y\PYGZsq{}: y(x, z), \PYGZsq{}z\PYGZsq{}: z(x, y)\PYGZcb{})}
\end{sphinxVerbatim}

\begin{sphinxadmonition}{warning}{Warning:}
Known limitations:
\begin{itemize}
\item {} 
Breaks Python class introspection (for instance tab completion in \sphinxstyleemphasis{iPython})

\item {} 
Of course users cannot add any non\sphinxhyphen{}data related attribute (or method)

\end{itemize}
\end{sphinxadmonition}

See also {\hyperref[\detokenize{dda/ast:dda.ast.State.equation_adder}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{State.equation\_adder()}}}}} (\autopageref*{\detokenize{dda/ast:dda.ast.State.equation_adder}}) for similar sugar which might have
unexpected effects:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s}\PYG{p}{,} \PYG{n}{b} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{n}{BreveState}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{foo} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} in this context, similar to a string foo = \PYGZdq{}bar\PYGZdq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s}\PYG{p}{[}\PYG{n}{foo}\PYG{p}{]} \PYG{o}{=} \PYG{l+m+mi}{42}         \PYG{c+c1}{\PYGZsh{} foo resolves to string represntation \PYGZdq{}bar\PYGZdq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{b}\PYG{o}{.}\PYG{n}{foo} \PYG{o}{=} \PYG{l+m+mi}{42}          \PYG{c+c1}{\PYGZsh{} equals b[\PYGZdq{}foo\PYGZdq{}], thus has nothing to do with variable foo}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{s}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}bar\PYGZsq{}: 42\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{b}
\PYG{g+go}{BreveState(\PYGZob{}\PYGZsq{}foo\PYGZsq{}: 42\PYGZcb{})}
\end{sphinxVerbatim}

If you find this class useful, you also might like \sphinxcode{\sphinxupquote{types.SimpleNamespace}} or
\sphinxcode{\sphinxupquote{collections.namedtuple}}. Both are basically immutable, while this object type
is mutable by intention.

\end{fulllineitems}



\subsection{The DDA Domain Specific Language}
\label{\detokenize{dda/dsl:module-dda.dsl}}\label{\detokenize{dda/dsl:the-dda-domain-specific-language}}\label{\detokenize{dda/dsl:dsl}}\label{\detokenize{dda/dsl::doc}}\index{module@\spxentry{module}!dda.dsl@\spxentry{dda.dsl}}\index{dda.dsl@\spxentry{dda.dsl}!module@\spxentry{module}}
The DDA domain specific language, also refered to as “traditional dda”,
is the C\sphinxhyphen{}like language invented by Bernd for his Perl’ish dda code.

It basically reads as the following snippet:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZsh{} Single\PYGZhy{}line comments are written like this}

\PYG{n}{dt} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mf}{0.5}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} constants are defined like this}
\PYG{n}{y0} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)}

\PYG{n}{z} \PYG{o}{=} \PYG{n}{mult}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{y}\PYG{p}{)}
\PYG{n}{y} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{y0}\PYG{p}{)}
\end{sphinxVerbatim}

As you see, variables do not even have to be introduced and can be
used in any order. There is only one data type, the \sphinxstyleemphasis{analog line signal}
which is basically a real number within a fixed interval.

\begin{sphinxadmonition}{note}{Note:}
Interestingly, traditional DDA files are a python subset and thus can
be easily parsed and generated by python syntax. That’s why the code
of this PyDDA module is so short. That’s also a primary reason why
DDA was rewritten in Python.
\end{sphinxadmonition}

Demonstration usage of this module:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{traditional\PYGZus{}dda\PYGZus{}document}\PYG{o}{=}\PYG{l+s+s1}{\PYGZsq{}\PYGZsq{}\PYGZsq{}}
\PYG{g+gp}{... }\PYG{l+s+s1}{\PYGZsh{} Single\PYGZhy{}line comments are written like this}
\PYG{g+gp}{... }
\PYG{g+gp}{... }\PYG{l+s+s1}{dt = const(0.5)  \PYGZsh{} constants are defined like this}
\PYG{g+gp}{... }\PYG{l+s+s1}{y0 = const(1)}
\PYG{g+gp}{... }
\PYG{g+gp}{... }\PYG{l+s+s1}{z = mult(y, y)}
\PYG{g+gp}{... }\PYG{l+s+s1}{y = int(y, dt, y0)}
\PYG{g+gp}{... }\PYG{l+s+s1}{\PYGZsq{}\PYGZsq{}\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{read\PYGZus{}traditional\PYGZus{}dda}\PYG{p}{(}\PYG{n}{traditional\PYGZus{}dda\PYGZus{}document}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}dt\PYGZsq{}: const(0.5), \PYGZsq{}y\PYGZsq{}: int(y, dt, y0), \PYGZsq{}y0\PYGZsq{}: const(1), \PYGZsq{}z\PYGZsq{}: mult(y, y)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{to\PYGZus{}traditional\PYGZus{}dda}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}\PYG{p}{)}   
\PYG{g+go}{\PYGZsh{} Canonical DDA file generated by PyDDA}

\PYG{g+go}{dt = const(0.5)}
\PYG{g+go}{y = int(y, dt, y0)}
\PYG{g+go}{y0 = const(1)}
\PYG{g+go}{z = mult(y, y)}
\end{sphinxVerbatim}
\index{to\_traditional\_dda() (in module dda.dsl)@\spxentry{to\_traditional\_dda()}\spxextra{in module dda.dsl}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/dsl:dda.dsl.to_traditional_dda}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.dsl.}}\sphinxbfcode{\sphinxupquote{to\_traditional\_dda}}}{\emph{\DUrole{n}{state}}, \emph{\DUrole{n}{cleanup}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{n}{prefix}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}\# Canonical DDA file generated by PyDDA\textbackslash{}n\textquotesingle{}}}, \emph{\DUrole{n}{suffix}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}\textbackslash{}n\textquotesingle{}}}}{}
Export state to canonical dda file format (i.e. without all the python).

Returns the generated DDA file as string

\end{fulllineitems}

\index{read\_traditional\_dda() (in module dda.dsl)@\spxentry{read\_traditional\_dda()}\spxextra{in module dda.dsl}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/dsl:dda.dsl.read_traditional_dda}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.dsl.}}\sphinxbfcode{\sphinxupquote{read\_traditional\_dda}}}{\emph{\DUrole{n}{content}}, \emph{\DUrole{n}{return\_ordered\_dict}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Read some traditional dda file. We use the Python parser (\sphinxcode{\sphinxupquote{ast}} builtin)
for this job. This is possible because the DDA syntax is a python subset and
the parser doesn’t care about semantics, only syntax.

Thanks to the \sphinxcode{\sphinxupquote{ast}} builtin package, we can just transform the python AST to
the Symbolic/State class data structures used in this module.

\begin{sphinxadmonition}{note}{Note:}
If some of the assertions fail, you can debug your DDA file by inspecting
the output of ast.parse(content) on iPython. You can also run the Python
debugger (pdb) on this function, for instance in iPython:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{o}{\PYGZpc{}}\PYG{n}{pdb}                                                  
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{read\PYGZus{}traditional\PYGZus{}dda}\PYG{p}{(}\PYG{n}{file}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo.dda}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}          
\end{sphinxVerbatim}
\end{sphinxadmonition}

Returns a state instance or OrderedDict, on preference.

\end{fulllineitems}

\index{read\_traditional\_dda\_file() (in module dda.dsl)@\spxentry{read\_traditional\_dda\_file()}\spxextra{in module dda.dsl}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/dsl:dda.dsl.read_traditional_dda_file}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.dsl.}}\sphinxbfcode{\sphinxupquote{read\_traditional\_dda\_file}}}{\emph{\DUrole{n}{filename}}, \emph{\DUrole{o}{**}\DUrole{n}{kwargs}}}{}
Syntactic sugar for {\hyperref[\detokenize{dda/dsl:dda.dsl.read_traditional_dda}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{read\_traditional\_dda()}}}}} (\autopageref*{\detokenize{dda/dsl:dda.dsl.read_traditional_dda}}), so users can directly pass a filename
if the have their DDA code in a file.

\end{fulllineitems}

\index{cli\_exporter() (in module dda.dsl)@\spxentry{cli\_exporter()}\spxextra{in module dda.dsl}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/dsl:dda.dsl.cli_exporter}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.dsl.}}\sphinxbfcode{\sphinxupquote{cli\_exporter}}}{}{}
A Command Line Interface (CLI) for PyDDA.

This CLI API does mainly what the old dda2c.pl script did, i.e.
translating a (traditional) DDA file to C code. There are fewer
options, because \textendash{}iterations, \textendash{}modulus and \textendash{}variables are
now runtime options for the generated C program.

However, we can generate much more then C. Output is always text.

Invocation is either \sphinxcode{\sphinxupquote{python \sphinxhyphen{}m dda \sphinxhyphen{}\sphinxhyphen{}help}} or \sphinxcode{\sphinxupquote{python \sphinxhyphen{}m dda.dsl \sphinxhyphen{}\sphinxhyphen{}help}}
anywhere from the system. \sphinxcode{\sphinxupquote{setup.py}} probably also installed a
\sphinxcode{\sphinxupquote{pydda}} binary somewhere calling the same. You can also just
call \sphinxcode{\sphinxupquote{./dsl.py \sphinxhyphen{}\sphinxhyphen{}help}}.

\end{fulllineitems}



\subsection{DDA Computing elements}
\label{\detokenize{dda/computing_elements:module-dda.computing_elements}}\label{\detokenize{dda/computing_elements:dda-computing-elements}}\label{\detokenize{dda/computing_elements:computing-elements}}\label{\detokenize{dda/computing_elements::doc}}\index{module@\spxentry{module}!dda.computing\_elements@\spxentry{dda.computing\_elements}}\index{dda.computing\_elements@\spxentry{dda.computing\_elements}!module@\spxentry{module}}
The DDA language is built around the analog computing elements (or primitives).
These are basically electrical block circuits implementing basic arithmetics
such as summation and multiplication, but also integration. These are also
special elements for clipping, exponentials, square roots, and many more.

The DDA domain specific language is agnostic for function names. Host languages
such as Python or C are not. Many of the function names are reserved words in
these languages. Examples are:
\begin{itemize}
\item {} 
\sphinxcode{\sphinxupquote{const}}: Reserved word in C/C++ for constant variables

\item {} 
\sphinxcode{\sphinxupquote{int}}: Type name in C, overwritable in python

\item {} 
\sphinxcode{\sphinxupquote{sum}}: Builtin in python

\item {} 
\sphinxcode{\sphinxupquote{div}}: Function in \sphinxcode{\sphinxupquote{stdlib.h}} in C, which can cause clashes in slightly
more complex C codes.

\end{itemize}

When it comes to exporting to languages such as C, we rewrite these keywords.
In Python, we don’t have to, because none of the well known DDA function names 
is really \sphinxstyleemphasis{reserved}. The primitive builtins can always be recovered by
\sphinxcode{\sphinxupquote{from builtins import int, sum}}, etc.


\subsubsection{Different ways to access the well\sphinxhyphen{}known DDA computing elements in Python}
\label{\detokenize{dda/computing_elements:different-ways-to-access-the-well-known-dda-computing-elements-in-python}}
If you write

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{computing\PYGZus{}elements} \PYG{k+kn}{import} \PYG{o}{*}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{int}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{,}\PYG{n+nb}{sum}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} Make use of the imported Symbols}
\PYG{g+go}{int(int, sum)}
\end{sphinxVerbatim}

you will load a bunch of names such as \sphinxcode{\sphinxupquote{int}} and \sphinxcode{\sphinxupquote{sum}} in your local
namespace.

You can also just call

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{computing\PYGZus{}elements} \PYG{k+kn}{import} \PYG{n}{dda\PYGZus{}functions}\PYG{p}{,} \PYG{n}{dda\PYGZus{}symbols}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{dda\PYGZus{}symbols}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{floor}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} will print a Symbol()}
\PYG{g+go}{floor}
\end{sphinxVerbatim}

You can use the symbols dictionary to populate your namespace at whish:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{globals}\PYG{p}{(}\PYG{p}{)}\PYG{o}{.}\PYG{n}{update}\PYG{p}{(}\PYG{n}{dda\PYGZus{}symbols}\PYG{p}{)}
\end{sphinxVerbatim}

Note that Python globals are module\sphinxhyphen{}local, so we cannot provide this line
as a function.

Last but not least, you can also just use the namespaced version with
prefixes, which leaves you on a safe footing:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda}\PYG{o}{.}\PYG{n}{floor}\PYG{p}{(}\PYG{n}{dda}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{)}
\PYG{g+go}{floor(sum)}
\end{sphinxVerbatim}


\subsubsection{Definition/Implementation of the primitives}
\label{\detokenize{dda/computing_elements:definition-implementation-of-the-primitives}}
Once we have a pure\sphinxhyphen{}Python DDA evolution code (probably using scipy), we will
have a python implementation of the DDA functions. Otherwise I could avoid that.
This module also contains a C++ implementation of the primitives, which resides
as a string (\sphinxcode{\sphinxupquote{cpp\_impl}}).


\subsection{DDA C++ code generator}
\label{\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}}\label{\detokenize{dda/cpp-codegen:dda-c-code-generator}}\label{\detokenize{dda/cpp-codegen:cpp-codegen}}\label{\detokenize{dda/cpp-codegen::doc}}\index{module@\spxentry{module}!dda.cpp\_exporter@\spxentry{dda.cpp\_exporter}}\index{dda.cpp\_exporter@\spxentry{dda.cpp\_exporter}!module@\spxentry{module}}
C++ code generation is a major feature of the PyDDA code. The generated
code is built from a string template and has the following features:
\begin{itemize}
\item {} 
Standalone code: No further dependencies (beyond standard libc, lm and STL).

\item {} 
Lightweight object oriented: Uses classes (structures) to hold the
different variables (basically AoS instead of SoA approach). Little
C++ templating.

\item {} 
Organization in a few functions which allows to edit the generated 
C++ code manually afterwards without going mad.

\item {} 
CSV or binary output, or no output at all. Output is always made
to stdout. Information messages are always sent to stderr.

\item {} 
Debugging facilities built right into the code for setting NaNs and
abortion in case of floating point exceptions.

\item {} 
Runtime arguments via the commandline (argv): Parsing and passing.

\end{itemize}

\begin{sphinxadmonition}{note}{Note:}
\sphinxstylestrong{C++17} is required for building the C++ code. This is because
we use variadic templates.
\end{sphinxadmonition}

For the C++ runtime arguments, we support so far:
\begin{itemize}
\item {} 
\sphinxstyleemphasis{Simulation steering}: Selection of number of integration iterations
and frequency of dumping the solution.

\item {} 
\sphinxstyleemphasis{Query based plotting}: Selection which variables shall be outputted
at runtime.

\item {} 
Further \sphinxstyleemphasis{Flags} and \sphinxstyleemphasis{Numeric arguments} as well as a useful \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}help}}
message.

\item {} 
\sphinxstyleemphasis{Initial data} and \sphinxstyleemphasis{time step sizes} can also be chosen at run time.

\item {} 
\sphinxstyleemphasis{Introspection capabilities}, for instance one can ask the binary
about the evolution quantities built in.

\end{itemize}

Basically the equation structure is the only thing left hardcoded at
C++ code generation time.
\index{to\_cpp() (in module dda.cpp\_exporter)@\spxentry{to\_cpp()}\spxextra{in module dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.to_cpp}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{to\_cpp}}}{\emph{\DUrole{n}{state}}, \emph{\DUrole{n}{number\_precision}\DUrole{o}{=}\DUrole{default_value}{inf}}, \emph{\DUrole{n}{constexpr\_consts}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Given a state, returns standalone C++ code as string.

This code can be written to a file, compiled with a recent 
C++ compiler and then solves the differential equation system when executed.

The algorithm is basically:
\begin{enumerate}
\sphinxsetlistlabels{\arabic}{enumi}{enumii}{}{.}%
\item {} 
linearize the state (this can raise)

\item {} 
determine all the C++ template fields

\item {} 
Return the filled out template

\end{enumerate}

We plan to add logging for non\sphinxhyphen{}fatal information about the C++ code quality
(see TODOs in the code).

The argument \sphinxcode{\sphinxupquote{number\_precision}} currently has no effect.

\end{fulllineitems}

\index{compile() (in module dda.cpp\_exporter)@\spxentry{compile()}\spxextra{in module dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.compile}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{compile}}}{\emph{\DUrole{n}{code}}, \emph{\DUrole{n}{c\_filename}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}generated.cc\textquotesingle{}}}, \emph{\DUrole{n}{compiler}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}g++\textquotesingle{}}}, \emph{\DUrole{n}{compiler\_output}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}./a.out\textquotesingle{}}}, \emph{\DUrole{n}{options}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}\sphinxhyphen{}\sphinxhyphen{}std=c++17 \sphinxhyphen{}Wall\textquotesingle{}}}}{}
Small helper function to compile C++ code from python.

Write string \sphinxstyleemphasis{code} to \sphinxstyleemphasis{c\_filename} and run the \sphinxstyleemphasis{compiler} on that, afterwards.
Will raise an error if compilation fails.

\end{fulllineitems}

\index{runproc() (in module dda.cpp\_exporter)@\spxentry{runproc()}\spxextra{in module dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.runproc}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{runproc}}}{\emph{\DUrole{n}{command}}, \emph{\DUrole{n}{decode}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Helper to run external command and slurp its output to a binary array

\end{fulllineitems}

\index{list\_all\_variables() (in module dda.cpp\_exporter)@\spxentry{list\_all\_variables()}\spxextra{in module dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.list_all_variables}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{list\_all\_variables}}}{\emph{\DUrole{n}{command}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}./a.out\textquotesingle{}}}}{}
in order to know which fields have been read, slurp all variables

\end{fulllineitems}

\index{run() (in module dda.cpp\_exporter)@\spxentry{run()}\spxextra{in module dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.run}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{run}}}{\emph{\DUrole{n}{command}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}./a.out\textquotesingle{}}}, \emph{\DUrole{n}{binary}\DUrole{o}{=}\DUrole{default_value}{False}}, \emph{\DUrole{n}{arguments}\DUrole{o}{=}\DUrole{default_value}{\{\}}}, \emph{\DUrole{n}{fields\_to\_export}\DUrole{o}{=}\DUrole{default_value}{{[}{]}}}}{}
Small helper function to execute a code generated by this module.

Runs \sphinxcode{\sphinxupquote{command}} on the command line, with given dict \sphinxcode{\sphinxupquote{arguments}} in \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}foo=bar}}
fashion and \sphinxcode{\sphinxupquote{fields\_to\_export}} just as a sequential argument list. If no
\sphinxcode{\sphinxupquote{fields\_to\_export}} is given, \sphinxcode{\sphinxupquote{command \sphinxhyphen{}\sphinxhyphen{}list\_all\_variables}} will be run to query
all default fields.

Pipes stdout to a string, which is returned. Stderr will just be passed.
The function will return once the binary finished or raise in case of error.

If you set \sphinxcode{\sphinxupquote{binary=True}}, raw data instead of CSV files will be passed between the spawned
command and this python program. This decreases the runtime significantly if you write a lot
of data (since CSV generating and parsing overload is gone).

Example usage:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda} \PYG{k+kn}{import} \PYG{o}{*}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{int}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{neg}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}x\PYGZsq{}: int(neg(x), 0.2, 1)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{cpp\PYGZus{}code} \PYG{o}{=} \PYG{n}{to\PYGZus{}cpp}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{cpp\PYGZus{}code}\PYG{p}{)}  
\PYG{g+go}{// This code was generated by PyDDA.}
\PYG{g+go}{\PYGZsh{}include \PYGZlt{}cmath\PYGZgt{} /* don\PYGZsq{}t forget \PYGZhy{}lm for linking */}
\PYG{g+go}{\PYGZsh{}include \PYGZlt{}cfenv\PYGZgt{} /* for feraisexcept and friends */}
\PYG{g+go}{\PYGZsh{}include \PYGZlt{}limits\PYGZgt{} /* for signaling NAN */}
\PYG{g+go}{\PYGZsh{}include \PYGZlt{}vector\PYGZgt{}}
\PYG{g+go}{....}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{compile}\PYG{p}{(}\PYG{n}{cpp\PYGZus{}code}\PYG{p}{,} \PYG{n}{compiler\PYGZus{}output}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo.exe}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{res} \PYG{o}{=} \PYG{n}{run}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{./foo.exe}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{arguments}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{max\PYGZus{}iterations}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{:}\PYG{l+m+mi}{10}\PYG{p}{\PYGZcb{}}\PYG{p}{,} \PYG{n}{fields\PYGZus{}to\PYGZus{}export}\PYG{o}{=}\PYG{p}{[}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{x}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)} 
\PYG{g+go}{Running: ./foo.exe \PYGZhy{}\PYGZhy{}max\PYGZus{}iterations=10 x}
\PYG{g+go}{TODO: Doctesting this doesn\PYGZsq{}t work good due to stderr (cf https://stackoverflow.com/a/61533524)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{res}\PYG{p}{)} 
\PYG{g+go}{x}
\PYG{g+go}{1.2}
\PYG{g+go}{1.44}
\PYG{g+go}{1.728}
\PYG{g+go}{2.0736}
\PYG{g+go}{2.48832}
\PYG{g+go}{2.98598}
\PYG{g+go}{3.58318}
\PYG{g+go}{4.29982}
\PYG{g+go}{5.15978}
\PYG{g+go}{6.19174}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{numpy\_read() (in module dda.cpp\_exporter)@\spxentry{numpy\_read()}\spxextra{in module dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.numpy_read}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{numpy\_read}}}{\emph{\DUrole{n}{stdout}}, \emph{\DUrole{n}{binary}\DUrole{o}{=}\DUrole{default_value}{False}}, \emph{\DUrole{n}{return\_ndarray}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{n}{return\_recarray}\DUrole{o}{=}\DUrole{default_value}{False}}, \emph{\DUrole{n}{fields\_to\_export}\DUrole{o}{=}\DUrole{default_value}{{[}{]}}}}{}
Postprocessing to fill the gap between the C++ output and a suitable numpy array.
In order to so, this function has to know whether your output was binary or text.
Furthermore, you need to tell him how many fields you had. You can use {\hyperref[\detokenize{dda/cpp-codegen:dda.cpp_exporter.list_all_variables}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{list\_all\_variables()}}}}} (\autopageref*{\detokenize{dda/cpp-codegen:dda.cpp_exporter.list_all_variables}})

Old Text:

This option only makes real sense if
you set (the default) \sphinxcode{\sphinxupquote{return\_ndarray=True}}. Note that if you don’t pass the  \sphinxcode{\sphinxupquote{fields\_to\_export}}
option but set \sphinxcode{\sphinxupquote{binary=True}}, in the moment the returned array is one\sphinxhyphen{}dimensional (a warning
will be printed). If you like even more structured data be returned, turn on \sphinxcode{\sphinxupquote{return\_recarray=True}}.
It will return a numpy.recarray, the same data type which you get when you read CSV data
with column headers. \sphinxcode{\sphinxupquote{return\_recarray=True}} implies \sphinxcode{\sphinxupquote{return\_ndarray=True}}.

\end{fulllineitems}

\index{Solver (class in dda.cpp\_exporter)@\spxentry{Solver}\spxextra{class in dda.cpp\_exporter}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.Solver}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{dda.cpp\_exporter.}}\sphinxbfcode{\sphinxupquote{Solver}}}{\emph{\DUrole{n}{dda\_state\_or\_code}}, \emph{\DUrole{o}{*}\DUrole{n}{runtime\_fields\_to\_export}}, \emph{\DUrole{n}{constexpr\_consts}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{o}{**}\DUrole{n}{runtime\_arguments}}}{}
Syntactic sugar for a more concise OOP feeling. Instead of calling \sphinxcode{\sphinxupquote{export(to="C")}},
\sphinxcode{\sphinxupquote{compile()}} and \sphinxcode{\sphinxupquote{run()}} you can just write \sphinxcode{\sphinxupquote{Solver(state, runtime\_arguments)}}.
This object will even clean up after running.
\index{run() (dda.cpp\_exporter.Solver method)@\spxentry{run()}\spxextra{dda.cpp\_exporter.Solver method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.Solver.run}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{run}}}{\emph{\DUrole{o}{*}\DUrole{n}{runtime\_fields\_to\_export}}, \emph{\DUrole{n}{binary}\DUrole{o}{=}\DUrole{default_value}{False}}, \emph{\DUrole{n}{cleanup}\DUrole{o}{=}\DUrole{default_value}{True}}, \emph{\DUrole{o}{**}\DUrole{n}{runtime\_arguments}}}{}
Chaining and Syntactic sugar for delayed argument setting/overwriting

\end{fulllineitems}

\index{as\_ndarray() (dda.cpp\_exporter.Solver method)@\spxentry{as\_ndarray()}\spxextra{dda.cpp\_exporter.Solver method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.Solver.as_ndarray}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{as\_ndarray}}}{}{}
Return run results as a \sphinxcode{\sphinxupquote{np.ndarray}} (i.e. like a table without headers, typically 2D data)

\end{fulllineitems}

\index{as\_recarray() (dda.cpp\_exporter.Solver method)@\spxentry{as\_recarray()}\spxextra{dda.cpp\_exporter.Solver method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cpp-codegen:dda.cpp_exporter.Solver.as_recarray}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{as\_recarray}}}{}{}
Return run results as a \sphinxcode{\sphinxupquote{np.recarray}} (i.e. like CSV table with named headers)

\end{fulllineitems}


\end{fulllineitems}



\subsection{DDA SciPy interface (to generic ODE solvers)}
\label{\detokenize{dda/scipy:module-dda.scipy}}\label{\detokenize{dda/scipy:dda-scipy-interface-to-generic-ode-solvers}}\label{\detokenize{dda/scipy:dda-scipy}}\label{\detokenize{dda/scipy::doc}}\index{module@\spxentry{module}!dda.scipy@\spxentry{dda.scipy}}\index{dda.scipy@\spxentry{dda.scipy}!module@\spxentry{module}}
The \sphinxcode{\sphinxupquote{dda.scipy}} module allows in\sphinxhyphen{}python evaluation of DDA systems
as well as their solution with ODE Integrators in Python,
such as \sphinxhref{https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html}{scipy.integrate}%
\begin{footnote}[48]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html}
%
\end{footnote}.
For the usage and examples, see the main class {\hyperref[\detokenize{dda/scipy:dda.scipy.to_scipy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{to\_scipy}}}}} (\autopageref*{\detokenize{dda/scipy:dda.scipy.to_scipy}}).

\begin{sphinxadmonition}{note}{Note:}
In order to run this code, you need, obviously, \sphinxhref{https://www.scipy.org/}{SciPy}%
\begin{footnote}[49]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.scipy.org/}
%
\end{footnote} next 
to \sphinxhref{https://numpy.org/}{NumPy}%
\begin{footnote}[50]\sphinxAtStartFootnote
\sphinxnolinkurl{https://numpy.org/}
%
\end{footnote}.
\end{sphinxadmonition}

\begin{sphinxadmonition}{warning}{Warning:}
This module exposes a solver of a DDA system which is quite different to the
\sphinxcode{\sphinxupquote{cpp\_exporter}}. In particular,
\begin{itemize}
\item {} 
The solver is required to be told the solution time span or final time in
time units, not iteration indices.

\item {} 
The solver only spills out the evolved (integration) quantities and not any
derived quantities. You can recompute them at any timestep, but there is currently
no code helping you in order to archieve this result. This can result in confusion
when you cannot query the fields you asked for (in particular in the CLI frontend).

\item {} 
The SciPy time integrator tries to find an optimal (and minimal) time step, yielding
in a quite “rough” solution. You can turn on \sphinxstyleemphasis{dense output} in order to tell the
SciPy solver to integrate between these time steps, yielding a more smooth output
with more datapoints.

\end{itemize}
\end{sphinxadmonition}
\index{evaluate\_values() (in module dda.scipy)@\spxentry{evaluate\_values()}\spxextra{in module dda.scipy}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.evaluate_values}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.scipy.}}\sphinxbfcode{\sphinxupquote{evaluate\_values}}}{\emph{\DUrole{n}{smbl}}, \emph{\DUrole{n}{values}}}{}
Evaluate a symbol within the context of an already evaluated values dictionary given.

\end{fulllineitems}

\index{to\_scipy (class in dda.scipy)@\spxentry{to\_scipy}\spxextra{class in dda.scipy}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{dda.scipy.}}\sphinxbfcode{\sphinxupquote{to\_scipy}}}{\emph{\DUrole{n}{state}}}{}
The SciPy exporter. When initializing this class with your DDA system, it will setup
a function \sphinxcode{\sphinxupquote{f(y)}} which can be evaluated as any right hand side in the ordinary
differential equation (ODE) system \sphinxcode{\sphinxupquote{dy/dt = f(y)}}. Here, \sphinxcode{\sphinxupquote{y}} are the evolution
quantities, i.e. a vector which is composed automatically from the linearized DDA system
(see \sphinxcode{\sphinxupquote{ast.State.name\_computing\_elements()}} and \sphinxcode{\sphinxupquote{ast.State.variable\_ordering()}}).
Furthermore, this class prepares the initial values \sphinxcode{\sphinxupquote{y0}} for the integration.

You can evaluate these quantities in any python context, i.e. with any scientific python
ODE solver library. For the time being, this class provides a convenience method
{\hyperref[\detokenize{dda/scipy:dda.scipy.to_scipy.solve}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{solve()}}}}} (\autopageref*{\detokenize{dda/scipy:dda.scipy.to_scipy.solve}}) which calls \sphinxhref{https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve\_ivp.html}{scipy.integrate.solve\_ivp}%
\begin{footnote}[51]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve\_ivp.html}
%
\end{footnote}.
There is no other scipy dependence in this code.

Usage example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{computing\PYGZus{}elements} \PYG{k+kn}{import} \PYG{n}{neg}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{,}\PYG{n}{mult}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda} \PYG{k+kn}{import} \PYG{n}{State}\PYG{p}{,} \PYG{n}{symbols}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{z} \PYG{o}{=} \PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x, y, z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dda\PYGZus{}state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}}\PYG{n}{x}\PYG{p}{:} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{,} \PYG{n}{y}\PYG{p}{:} \PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{,} \PYG{n}{z}\PYG{p}{:} \PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{z}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{py\PYGZus{}state} \PYG{o}{=} \PYG{n}{to\PYGZus{}scipy}\PYG{p}{(}\PYG{n}{dda\PYGZus{}state}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{state} \PYG{c+c1}{\PYGZsh{} state has been linearized before processing}
\PYG{g+go}{State(\PYGZob{}\PYGZsq{}int\PYGZus{}1\PYGZsq{}: Int(z), \PYGZsq{}x\PYGZsq{}: Int(y), \PYGZsq{}y\PYGZsq{}: mult(2, x), \PYGZsq{}z\PYGZsq{}: neg(int\PYGZus{}1)\PYGZcb{})}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{vars}\PYG{o}{.}\PYG{n}{evolved} \PYG{c+c1}{\PYGZsh{} evolved variables are therefore not [x,z] but [int\PYGZus{}1,x]}
\PYG{g+go}{[\PYGZsq{}int\PYGZus{}1\PYGZsq{}, \PYGZsq{}x\PYGZsq{}]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{y0}  \PYG{c+c1}{\PYGZsh{} initial values}
\PYG{g+go}{array([\PYGZhy{}1,  1])}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{dt} \PYG{c+c1}{\PYGZsh{} same timestep for all integrals (but see note below)}
\PYG{g+go}{1}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{rhs}\PYG{p}{(}\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{y0}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} evaluation of f(y) on y0}
\PYG{g+go}{array([\PYGZhy{}1, \PYGZhy{}2])}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{y1} \PYG{o}{=} \PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{rhs}\PYG{p}{(}\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{y0}\PYG{p}{)} \PYG{o}{*} \PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{dt}  \PYG{c+c1}{\PYGZsh{} a single Euler integration timestep, for instance}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{y1}
\PYG{g+go}{array([\PYGZhy{}1, \PYGZhy{}2])}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{sol} \PYG{o}{=} \PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{solve}\PYG{p}{(}\PYG{l+m+mi}{10}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} ODE integration with SciPy}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{sol}\PYG{o}{.}\PYG{n}{t}  \PYG{c+c1}{\PYGZsh{} integration went from 0\PYGZhy{}\PYGZgt{}10 with 17 timesteps     }
\PYG{g+go}{array([ 0.        , ..., 10.        ])}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{sol}\PYG{o}{.}\PYG{n}{y}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{]} \PYG{c+c1}{\PYGZsh{} the first solution is \PYGZti{}exp(+t)\PYGZhy{}\PYGZgt{}inf, the second exp(\PYGZhy{}t)\PYGZhy{}\PYGZgt{}0}
\PYG{g+go}{array([\PYGZhy{}2.20269685e+04,  1.94334984e\PYGZhy{}08])}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{pylab} \PYG{k+kn}{import} \PYG{n}{plot}\PYG{p}{,} \PYG{n}{legend}\PYG{p}{,} \PYG{n}{show}  \PYG{c+c1}{\PYGZsh{} plotting example   }
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{fieldname} \PYG{o+ow}{in} \PYG{n+nb}{enumerate}\PYG{p}{(}\PYG{n}{py\PYGZus{}state}\PYG{o}{.}\PYG{n}{vars}\PYG{o}{.}\PYG{n}{evolved}\PYG{p}{)}\PYG{p}{:}       
\PYG{g+go}{        plot(sol.t, sol.y[i], label=fieldname)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{legend}\PYG{p}{(}\PYG{p}{)}\PYG{p}{;} \PYG{n}{show}\PYG{p}{(}\PYG{p}{)}                                           
\end{sphinxVerbatim}

\begin{sphinxadmonition}{warning}{Warning:}
Due to the way how widespread ODE integrators work, the per\sphinxhyphen{}integral
step size \sphinxcode{\sphinxupquote{dt}} is required to be the same for every integration which is part
of the DDA system. That is, the following generates an error:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda} \PYG{k+kn}{import} \PYG{n}{dda}\PYG{p}{,} \PYG{n}{symbols}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{o}{=}\PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a,b}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{a}\PYG{p}{:} \PYG{n}{dda}\PYG{o}{.}\PYG{n}{int}\PYG{p}{(}\PYG{n}{a}\PYG{p}{,} \PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{)}\PYG{p}{,} \PYG{n}{b}\PYG{p}{:} \PYG{n}{dda}\PYG{o}{.}\PYG{n}{int}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,} \PYG{l+m+mf}{0.5}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{to\PYGZus{}scipy}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}
\PYG{g+gt}{Traceback (most recent call last):}
\PYG{c}{...}
\PYG{g+gr}{ValueError}: \PYG{n}{Scipy requires all timesteps to be the same, however dt\PYGZus{}([\PYGZsq{}a\PYGZsq{}, \PYGZsq{}b\PYGZsq{}]) = [0.2 0.5]}
\end{sphinxVerbatim}

Most high\sphinxhyphen{}level integrators available in scientific Python toolkits (such as scipy)
assume the overall system to have a single timestep size \sphinxcode{\sphinxupquote{Δt}} (which is also quite
natural from a mathematical perspective). The signature \sphinxcode{\sphinxupquote{dda.int(f,dt,ic)}} is thus
quirky from a mathematical or numerical viewpoint. It is written in such a way because
analog computing integrators have a tunable time scale \sphinxcode{\sphinxupquote{k\_0 \textasciitilde{}= 1/dt}} which however
can also be consumed in the integrand itself: \sphinxcode{\sphinxupquote{dda.int(f,1/k\_0,ic) == dda.int(f/k\_0,1,ic)}}.

Furthermore, most high\sphinxhyphen{}level integrators do adaptive timestepping anyway. The fine\sphinxhyphen{}tuning
of timestep sizes is something which is only paid respect to in the \sphinxcode{\sphinxupquote{cpp\_exporter}}
module.
\end{sphinxadmonition}
\index{evaluate\_const() (dda.scipy.to\_scipy method)@\spxentry{evaluate\_const()}\spxextra{dda.scipy.to\_scipy method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy.evaluate_const}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{evaluate\_const}}}{\emph{\DUrole{n}{var}}}{}
Translate \sphinxcode{\sphinxupquote{const(foo)}} by stripping foo or some bar by looking up if it is an explicit constant.
Dynamical variables are not allowed here. This is somewhat similar but different to
\sphinxcode{\sphinxupquote{cpp\_exporter.lookup\_const(var)}}.

\end{fulllineitems}

\index{evaluate\_state() (dda.scipy.to\_scipy method)@\spxentry{evaluate\_state()}\spxextra{dda.scipy.to\_scipy method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy.evaluate_state}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{evaluate\_state}}}{\emph{\DUrole{n}{evolution\_vector}}, \emph{\DUrole{n}{copy}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Recomputes the full state from the evolution state vector.
Returns a dictionary with same keys as \sphinxcode{\sphinxupquote{self.state}} and scalars (floats) as
values.

This will especially compute the aux variables, while for the evaluation
variables the RHS of \sphinxcode{\sphinxupquote{dy / dt = f(y)}} is computed.

\begin{sphinxadmonition}{note}{Note:}
As a user, you most likely want to call {\hyperref[\detokenize{dda/scipy:dda.scipy.to_scipy.reconstruct_state}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{reconstruct\_state()}}}}} (\autopageref*{\detokenize{dda/scipy:dda.scipy.to_scipy.reconstruct_state}}) or
{\hyperref[\detokenize{dda/scipy:dda.scipy.to_scipy.rhs}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{rhs()}}}}} (\autopageref*{\detokenize{dda/scipy:dda.scipy.to_scipy.rhs}}) instead of this function.
\end{sphinxadmonition}

For optimization purpose, numerical state evaluation is always carried
out on the \sphinxcode{\sphinxupquote{evaluation\_default\_values}} member (which also hold the initial
values for the first \sphinxcode{\sphinxupquote{rhs}} evaluation). If you set \sphinxcode{\sphinxupquote{copy=True}},
a shallow copy (which is equal to a deep copy for a dict holding floats)
is returned. In external calls, you should probably always set \sphinxcode{\sphinxupquote{copy=True}}.

\begin{sphinxadmonition}{note}{Note:}
The implementation of this function currently evaluates the (prepared) DDA 
sytem by recursive calls with the help of a variable assignment directory. This is
basically a \sphinxstyleemphasis{run\sphinxhyphen{}time compilation} (JIT/VM) in pure python. Needless to say, this
won’t give a great performance!

There are plenty of low\sphinxhyphen{}hanging fruits to provide optimized versions of this code:
One could call the efficient (but still scalar) C++ implementation which
\sphinxcode{\sphinxupquote{cpp\_exporter}} provides by \sphinxhref{https://cython.readthedocs.io/en/latest/src/userguide/external\_C\_code.html}{methods provided by Cython}%
\begin{footnote}[52]\sphinxAtStartFootnote
\sphinxnolinkurl{https://cython.readthedocs.io/en/latest/src/userguide/external\_C\_code.html}
%
\end{footnote}.
One could also map the DDA abstract syntax tree (AST) to the python one and
use some unparser code to evaluate the DDA code as pure python
(see for instance
\sphinxhref{https://stackoverflow.com/questions/768634/parse-a-py-file-read-the-ast-modify-it-then-write-back-the-modified-source-c}{Python: Modify AST and write back python code}%
\begin{footnote}[53]\sphinxAtStartFootnote
\sphinxnolinkurl{https://stackoverflow.com/questions/768634/parse-a-py-file-read-the-ast-modify-it-then-write-back-the-modified-source-c}
%
\end{footnote}).

For the time being, this code remains as a pure demonstration code.
Thanks to using the linearized state, there should be no troubles with call stack
overflows, however cyclic dependencies may not be properly resolved
and can result in infinite recursions (stack overflow).
\end{sphinxadmonition}

\end{fulllineitems}

\index{reconstruct\_state() (dda.scipy.to\_scipy method)@\spxentry{reconstruct\_state()}\spxextra{dda.scipy.to\_scipy method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy.reconstruct_state}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{reconstruct\_state}}}{\emph{\DUrole{n}{evolution\_vector}}, \emph{\DUrole{n}{copy}\DUrole{o}{=}\DUrole{default_value}{True}}}{}
Given the evolution vector sizes, this computes the full state. That is, this function
differs from \sphinxcode{\sphinxupquote{evaluate()}} at all evaluation quantities where the values of the
evolution vector itself are put in place.

\end{fulllineitems}

\index{rhs() (dda.scipy.to\_scipy method)@\spxentry{rhs()}\spxextra{dda.scipy.to\_scipy method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy.rhs}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{rhs}}}{\emph{\DUrole{n}{evolution\_vector}}}{}
The ODE \sphinxstyleemphasis{right hand side} in \sphinxcode{\sphinxupquote{dy / dt = f(y)}}. \sphinxcode{\sphinxupquote{y}} is a numpy vector,
and \sphinxcode{\sphinxupquote{f(y)}} returns a similarly sized (numpy) vector which we call \sphinxcode{\sphinxupquote{rhs}} here:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ode} \PYG{o}{=} \PYG{n}{to\PYGZus{}scipy}\PYG{p}{(}\PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{:} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{int}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{(}\PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,}\PYG{l+m+mf}{0.1}\PYG{p}{,}\PYG{l+m+mi}{1}\PYG{p}{)} \PYG{p}{\PYGZcb{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{y1} \PYG{o}{=} \PYG{n}{ode}\PYG{o}{.}\PYG{n}{y0} \PYG{o}{+} \PYG{n}{ode}\PYG{o}{.}\PYG{n}{rhs}\PYG{p}{(}\PYG{n}{ode}\PYG{o}{.}\PYG{n}{y0}\PYG{p}{)} \PYG{o}{*} \PYG{n}{ode}\PYG{o}{.}\PYG{n}{dt}   \PYG{c+c1}{\PYGZsh{} perform some euler integration step}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{y1}
\PYG{g+go}{array([0.9])}
\end{sphinxVerbatim}

Usually, you want to pass this function to some scipy integrator. See
also \sphinxcode{\sphinxupquote{ft()}}.

\end{fulllineitems}

\index{rhst() (dda.scipy.to\_scipy method)@\spxentry{rhst()}\spxextra{dda.scipy.to\_scipy method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy.rhst}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{rhst}}}{\emph{\DUrole{n}{t}}, \emph{\DUrole{n}{evolution\_vector}}}{}
Syntactic sugar for scipy integrators who want a signature \sphinxcode{\sphinxupquote{rhst(t,y)}}. Will
just call \sphinxcode{\sphinxupquote{rhs(y)}} instead.

\end{fulllineitems}

\index{solve() (dda.scipy.to\_scipy method)@\spxentry{solve()}\spxextra{dda.scipy.to\_scipy method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.to_scipy.solve}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{solve}}}{\emph{\DUrole{n}{tfinal}}, \emph{\DUrole{o}{**}\DUrole{n}{kwargs}}}{}
Basically passes all arguments to \sphinxcode{\sphinxupquote{scipy.integrate.solve\_ivp}}. See
documentation for {\hyperref[\detokenize{dda/scipy:dda.scipy.to_scipy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{to\_scipy}}}}} (\autopageref*{\detokenize{dda/scipy:dda.scipy.to_scipy}}) for usage example.

Currently, it is hardcodedly \sphinxcode{\sphinxupquote{tspan={[}0,tfinal{]}}}. All other (keyword) arguments
are passed to \sphinxcode{\sphinxupquote{solve\_ivp}}.

\end{fulllineitems}


\end{fulllineitems}

\index{cli\_scipy() (in module dda.scipy)@\spxentry{cli\_scipy()}\spxextra{in module dda.scipy}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/scipy:dda.scipy.cli_scipy}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.scipy.}}\sphinxbfcode{\sphinxupquote{cli\_scipy}}}{}{}
A Command Line Interface (CLI) for {\hyperref[\detokenize{dda/scipy:module-dda.scipy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.scipy}}}}} (\autopageref*{\detokenize{dda/scipy:module-dda.scipy}}).

This CLI API basically solves a DDA file (see {\hyperref[\detokenize{dda/dsl:module-dda.dsl}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.dsl}}}}} (\autopageref*{\detokenize{dda/dsl:module-dda.dsl}}) for the syntax).
This is a different approach then using the {\hyperref[\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.cpp\_exporter}}}}} (\autopageref*{\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}}) Instead
of code generation (and the need for a C++ compiler), this evaluates the
DDA file within python. The disadvantage is that this is damned slow, the
advantage is that the time integrator is much better then the selfmade one
in the {\hyperref[\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.cpp\_exporter}}}}} (\autopageref*{\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}}) module. And there is no need for a C++
compiler at all, all is (more or less) pure python.

Invocation is like  \sphinxcode{\sphinxupquote{python \sphinxhyphen{}m dda.scipy \sphinxhyphen{}\sphinxhyphen{}help}} anywhere from the system.
Run this to explore the usage of this command line interface.

The output will be CSV (file or stdout), in terms of one line per integration
step (called \sphinxstyleemphasis{dense solution} in scipy ODESolver language).

\end{fulllineitems}



\subsection{Computer Algebra Interfaces}
\label{\detokenize{dda/cas:computer-algebra-interfaces}}\label{\detokenize{dda/cas:cas}}\label{\detokenize{dda/cas::doc}}
DDA implements a few parts of computer algebra system (CAS), especially with it’s {\hyperref[\detokenize{dda/ast:abstract-syntax-tree}]{\sphinxcrossref{\DUrole{std,std-ref}{Abstract Syntax tree}}}} (\autopageref*{\detokenize{dda/ast:abstract-syntax-tree}}).
Since we don’t want to reinvent the wheel, we interface with common computer algebra systems.
There are at least two popular for the Python ecosystem available:
\begin{itemize}
\item {} 
\sphinxhref{https://www.sympy.org/}{SymPy}%
\begin{footnote}[54]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.sympy.org/}
%
\end{footnote}, bundled within the \sphinxhref{https://www.scipy.org/}{SciPy}%
\begin{footnote}[55]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.scipy.org/}
%
\end{footnote} package,
can be easily used as a pure python library.

\item {} 
\sphinxhref{https://www.sagemath.org/}{Sagemath}%
\begin{footnote}[56]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.sagemath.org/}
%
\end{footnote}, which is more of a monolithic software.
The symbolic foundation of sage is provided by \sphinxhref{https://ginac.de/}{Ginac}%
\begin{footnote}[57]\sphinxAtStartFootnote
\sphinxnolinkurl{https://ginac.de/}
%
\end{footnote} and
\sphinxhref{http://pynac.org/}{Pynac}%
\begin{footnote}[58]\sphinxAtStartFootnote
\sphinxnolinkurl{http://pynac.org/}
%
\end{footnote}, respectively. Many open source computer algebra systems are bundled
with sage, such as \sphinxhref{http://maxima.sourceforge.net/}{Maxima}%
\begin{footnote}[59]\sphinxAtStartFootnote
\sphinxnolinkurl{http://maxima.sourceforge.net/}
%
\end{footnote} and
\sphinxhref{https://www.gnu.org/software/octave/}{Octave}%
\begin{footnote}[60]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.gnu.org/software/octave/}
%
\end{footnote}. Furthermore, interfaces to many others such as
\sphinxhref{https://maplesoft.com/}{Maple}%
\begin{footnote}[61]\sphinxAtStartFootnote
\sphinxnolinkurl{https://maplesoft.com/}
%
\end{footnote}, \sphinxhref{https://www.mathworks.com/discovery/mupad.html}{Mupad}%
\begin{footnote}[62]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.mathworks.com/discovery/mupad.html}
%
\end{footnote} or
\sphinxhref{https://www.wolfram.com/mathematica/}{Mathematica}%
\begin{footnote}[63]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.wolfram.com/mathematica/}
%
\end{footnote} are part of sage.

\end{itemize}

So far, we had quick success with adopting SymPy (see next section).


\subsubsection{SymPy module API reference}
\label{\detokenize{dda/cas:module-dda.sympy}}\label{\detokenize{dda/cas:sympy-module-api-reference}}\index{module@\spxentry{module}!dda.sympy@\spxentry{dda.sympy}}\index{dda.sympy@\spxentry{dda.sympy}!module@\spxentry{module}}
This module provides interplay with the SymPy package. SymPy is a lightweight
pure\sphinxhyphen{}python computer algebra system which is bundled with SciPy.
An adapter to/from SymPy allows to use powerful Computer Algebra basic
functions such as expression simplification.

We use this currently to provide a lean latex representation for the
cumbersome DDA expressions.
\index{from\_sympy() (in module dda.sympy)@\spxentry{from\_sympy()}\spxextra{in module dda.sympy}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cas:dda.sympy.from_sympy}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.sympy.}}\sphinxbfcode{\sphinxupquote{from\_sympy}}}{\emph{\DUrole{n}{sympy\_equation\_list}}}{}
Import a state from a set of equations from SymPy.

This function expects a python list of sympy equations where there
is a single sympy symbol on one hand and an expression on the other
hand (see examples below).

The mapping basically follows the \sphinxhref{https://docs.sympy.org/latest/tutorial/manipulation.html\#args}{SymPy key invariant}%
\begin{footnote}[64]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.sympy.org/latest/tutorial/manipulation.html\#args}
%
\end{footnote}:
“Every well\sphinxhyphen{}formed SymPy expression must either have empty \sphinxcode{\sphinxupquote{args}}
or satisfy \sphinxcode{\sphinxupquote{expr == expr.func(*expr.args)}}”.

Therefore we basically map a sympy expression \sphinxcode{\sphinxupquote{(expr.func,
expr.args)}} to the DDA \sphinxcode{\sphinxupquote{(head, tail)}} notation. While the heads
are easy to map (for instance, \sphinxcode{\sphinxupquote{sympy.Mul}} equals \sphinxcode{\sphinxupquote{dda.mult}}),
special attention must be given to the tails, for instance SymPys
\sphinxcode{\sphinxupquote{Mul(a,b,c)}} translates to DDAs \sphinxcode{\sphinxupquote{mult(mult(a,b),c)}} (in DDA
we always assume commutative real\sphinxhyphen{}valued variables). Also in DDA
there is \sphinxcode{\sphinxupquote{neg(x)}} or \sphinxcode{\sphinxupquote{div(x,y)}} which is represented in SymPy as
\sphinxcode{\sphinxupquote{Mul(Integer(\sphinxhyphen{}1), x)}} and \sphinxcode{\sphinxupquote{Mul(Symbol(\textquotesingle{}x\textquotesingle{}), Pow(Symbol(\textquotesingle{}y\textquotesingle{}), Integer(\sphinxhyphen{}1)))}},
respectively.

\end{fulllineitems}

\index{to\_sympy() (in module dda.sympy)@\spxentry{to\_sympy()}\spxextra{in module dda.sympy}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cas:dda.sympy.to_sympy}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.sympy.}}\sphinxbfcode{\sphinxupquote{to\_sympy}}}{\emph{state}, \emph{symbol\_mapper=\textless{}function \textless{}lambda\textgreater{}\textgreater{}}, \emph{round\_n=15}}{}
Export a state to a set of equations for SymPy.
Returns a list of \sphinxcode{\sphinxupquote{sympy.Eq}} objects.
Of course it requires Sympy installed/available.

\begin{sphinxadmonition}{note}{Note:}
The heart of this function is a mapping from \sphinxcode{\sphinxupquote{ast.Symbol}}
terms (functions) to Sympy functions, for instance by mapping
\sphinxcode{\sphinxupquote{Symbol("int")(...)}} to \sphinxcode{\sphinxupquote{\sphinxhyphen{}sympy.Integral(sympy.Add(...), t)}}.

Thanks to the ease of the computing elements, this mapping does
not require pattern matching but can be performed on a basic
level. However, not all terms are yet supported.
\end{sphinxadmonition}

The argument \sphinxtitleref{symbol\_mapper} allows to apply another mapping
on the DDA Symbol heads. By default, it is the identity
function.

With Sympy, you can do all funny things, such as:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{dda} \PYG{k+kn}{import} \PYG{o}{*}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{,}\PYG{n}{neg}\PYG{o}{=}\PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,int,neg}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{x}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{:} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{to\PYGZus{}sympy}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}
\PYG{g+go}{[Eq(x, \PYGZhy{}Integral(1.2 \PYGZhy{} x, t))]}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{to\_latex() (in module dda.sympy)@\spxentry{to\_latex()}\spxextra{in module dda.sympy}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/cas:dda.sympy.to_latex}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.sympy.}}\sphinxbfcode{\sphinxupquote{to\_latex}}}{\emph{\DUrole{n}{state}}, \emph{\DUrole{n}{chunk\_n}\DUrole{o}{=}\DUrole{default_value}{None}}}{}
Export to latex, using sympy.

This mostly differs from \sphinxcode{\sphinxupquote{sympy.latex}} for large equation
systems where we use the align latex environment instead of
a single equation. For the above example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{sympy}\PYG{o}{,} \PYG{n+nn}{dda}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x}\PYG{p}{,}\PYG{n+nb}{int}\PYG{p}{,}\PYG{n}{neg}\PYG{o}{=}\PYG{n}{dda}\PYG{o}{.}\PYG{n}{symbols}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x,int,neg}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{state} \PYG{o}{=} \PYG{n}{dda}\PYG{o}{.}\PYG{n}{State}\PYG{p}{(}\PYG{p}{\PYGZob{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{x}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{:} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{,} \PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{sympy}\PYG{o}{.}\PYG{n}{latex}\PYG{p}{(}\PYG{n}{to\PYGZus{}sympy}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}  
\PYG{g+go}{\PYGZbs{}left[ x = \PYGZhy{} \PYGZbs{}int \PYGZbs{}left(1.2 \PYGZhy{} x\PYGZbs{}right)\PYGZbs{}, dt\PYGZbs{}right]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{to\PYGZus{}latex}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}\PYG{p}{)}               
\PYG{g+go}{\PYGZbs{}begin\PYGZob{}align\PYGZcb{}}
\PYG{g+go}{x \PYGZam{}= \PYGZhy{} \PYGZbs{}int \PYGZbs{}left(1.2 \PYGZhy{} x\PYGZbs{}right)\PYGZbs{}, dt}
\PYG{g+go}{\PYGZbs{}end\PYGZob{}align\PYGZcb{}}
\end{sphinxVerbatim}

\end{fulllineitems}



\subsection{The DDA module}
\label{\detokenize{dda/package:the-dda-module}}\label{\detokenize{dda/package:intro}}\label{\detokenize{dda/package::doc}}
(The following documentation is about the module itself and not very
useful in the moment)

\phantomsection\label{\detokenize{dda/package:module-dda}}\index{module@\spxentry{module}!dda@\spxentry{dda}}\index{dda@\spxentry{dda}!module@\spxentry{module}}
PyDDA is a small library to write and generate DDA code in Python.
DDA stands for \sphinxstyleemphasis{digital differential analyzer}. In this context, it is
a code for solving ordinary differential equations given in a domain
specific language description (i.e. an electrical circuit).

For further details, please see the \sphinxcode{\sphinxupquote{doc/}} directory (Sphinx
documentation).
\index{export() (in module dda)@\spxentry{export()}\spxextra{in module dda}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/package:dda.export}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.}}\sphinxbfcode{\sphinxupquote{export}}}{\emph{\DUrole{n}{state}}, \emph{\DUrole{n}{to}}, \emph{\DUrole{o}{**}\DUrole{n}{kw}}}{}
Convenience function to export (transform) a state to some other
programming language.

Possible formats (allowed values for \sphinxcode{\sphinxupquote{to}}) supported so far are:
\begin{itemize}
\item {} 
C/C++ (via {\hyperref[\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.cpp\_exporter}}}}} (\autopageref*{\detokenize{dda/cpp-codegen:module-dda.cpp_exporter}}))

\item {} 
DDA   (via {\hyperref[\detokenize{dda/dsl:module-dda.dsl}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.dsl}}}}} (\autopageref*{\detokenize{dda/dsl:module-dda.dsl}}))

\item {} 
SymPy (via {\hyperref[\detokenize{dda/cas:module-dda.sympy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.sympy}}}}} (\autopageref*{\detokenize{dda/cas:module-dda.sympy}}))

\item {} 
Latex (via {\hyperref[\detokenize{dda/cas:module-dda.sympy}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.sympy}}}}} (\autopageref*{\detokenize{dda/cas:module-dda.sympy}}))

\end{itemize}

This function shall be nice, so it accepts many spelling/notation
of these language names.

The return value are typically strings or tuples, dicts. There should
be no side effects.

\end{fulllineitems}

\index{clean() (in module dda)@\spxentry{clean()}\spxextra{in module dda}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{dda/package:dda.clean}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{dda.}}\sphinxbfcode{\sphinxupquote{clean}}}{\emph{\DUrole{n}{thing}}, \emph{\DUrole{n}{target}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}C\textquotesingle{}}}}{}
Cleans an identifier for being compatible with the \sphinxtitleref{target} language. This can be something like
\sphinxtitleref{C}, \sphinxtitleref{python} or \sphinxtitleref{dda} (cf. languages supported by {\hyperref[\detokenize{dda/package:dda.export}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{dda.export()}}}}} (\autopageref*{\detokenize{dda/package:dda.export}})) or also \sphinxtitleref{latex}.

It will basically try to transliterate all Unicode to ASCII and then try to ensure that the
identifier is a valid C variable name (i.e. don’t start with numbers, etc.).

This function is nice, if you pass a \sphinxcode{\sphinxupquote{dda.State}} or \sphinxcode{\sphinxupquote{dda.Symbol}}, it will
map the whole State/Symbol. Otherwise, it expects a string.

Examples:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{clean}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}f}\PYG{l+s+s2}{rac}\PYG{l+s+si}{\PYGZob{}x\PYGZcb{}}\PYG{l+s+si}{\PYGZob{}y\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} backslashes are just removed   }
\PYG{g+go}{\PYGZsq{}fracxy\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{clean}\PYG{p}{(}\PYG{l+s+sa}{r}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{a\PYGZca{}}\PYG{l+s+s1}{\PYGZob{}}\PYG{l+s+s1}{\PYGZhy{}1\PYGZcb{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{\PYGZsq{}a\PYGZus{}\PYGZus{}1\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{clean}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{a\PYGZca{}b\PYGZus{}c\PYGZca{}}\PYG{l+s+si}{\PYGZob{}ef\PYGZcb{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{\PYGZsq{}a\PYGZus{}b\PYGZus{}c\PYGZus{}ef\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{clean}\PYG{p}{(}\PYG{l+s+sa}{u}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{µ\(\sp{\text{2}}\)}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{)}   \PYG{c+c1}{\PYGZsh{} only if python package \PYGZdq{}unidecode\PYGZdq{} is installed }
\PYG{g+go}{\PYGZsq{}u2\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{clean}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{77}\PYG{l+s+si}{\PYGZpc{}a}\PYG{l+s+s1}{lc}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{)}   \PYG{c+c1}{\PYGZsh{} well, you can use numbers at the beginning of strings}
\PYG{g+go}{\PYGZsq{}\PYGZus{}77alc\PYGZsq{}}
\end{sphinxVerbatim}

\end{fulllineitems}



\section{Example circuits for DDA}
\label{\detokenize{dda/examples:example-circuits-for-dda}}\label{\detokenize{dda/examples:dda-examples}}\label{\detokenize{dda/examples::doc}}
We have a number of example circuits written in either
\begin{itemize}
\item {} 
traditional DDA language (can be run with any DDA compiler)

\item {} 
pythonic DDA (requires the PyDDA code but can be translated
also to traditional DDA files)

\item {} 
Jupyter/IPython notebook files (i.e. pythonic DDA but within
a rich\sphinxhyphen{}text document)

\end{itemize}

These files are located in the \sphinxtitleref{examples/} directory and are there for
being explored by interested users. A couple of files are gone into detail
in the following.


\subsection{Traditional DDA circuits}
\label{\detokenize{dda/examples:traditional-dda-circuits}}\begin{description}
\item[{\sphinxcode{\sphinxupquote{chua.dda}}}] \leavevmode
A traditional DDA code, implementing the Chua attractor from
chapter 6.15 from Bernds new book (ap2.pdf). We have both a scaled
and unscaled version along with a plotting code available in this
repository. For plotting, we also have capabilities to do a
high\sphinxhyphen{}quality “phase space” histogram based on massive binary output of the
C++ integrator.

\item[{\sphinxcode{\sphinxupquote{double\sphinxhyphen{}pendulum.dda}}}] \leavevmode
Another traditional DDA code, implementing a planar coupled gravity pendulum
in classical small\sphinxhyphen{}angle approximation and in a formulation with two
angles as degrees of freedom. The example stems from section 6.25 in
Bernds new book (ap2.pdf). Again, we have a small Python code for plotting
the results.

\end{description}


\subsection{Command line DDA usage}
\label{\detokenize{dda/examples:command-line-dda-usage}}

\subsubsection{An example on how to use PyDDA from command line: Gradiend descent}
\label{\detokenize{dda/shell-example:an-example-on-how-to-use-pydda-from-command-line-gradiend-descent}}\label{\detokenize{dda/shell-example:shell-exmaple}}\label{\detokenize{dda/shell-example::doc}}
This example is a go\sphinxhyphen{}throught of how using PyDDA from the Unix (Linux or Mac OS X)
command line. We use the \sphinxhref{https://en.wikipedia.org/wiki/Rosenbrock\_function}{Rosenbrock function}%
\begin{footnote}[65]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Rosenbrock\_function}
%
\end{footnote}
as an example for \sphinxhref{https://en.wikipedia.org/wiki/Gradient\_descent}{Gradient descent}%
\begin{footnote}[66]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Gradient\_descent}
%
\end{footnote}.

The file \sphinxcode{\sphinxupquote{rosenbrock.dda}} is given with the following content:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZsh{} Gradient descent on Rosenbrock problem with continous\PYGZhy{}time analog computing}
\PYG{c+c1}{\PYGZsh{} f(x,y) = (a\PYGZhy{}x)**2 + b*(y \PYGZhy{} x**2)**2}

\PYG{n}{a} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{b} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{100}\PYG{p}{)}

\PYG{c+c1}{\PYGZsh{} Initial conditions are starting points for optimization}

\PYG{n}{ic\PYGZus{}x}  \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} x(t0)}
\PYG{n}{ic\PYGZus{}my} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} \PYGZhy{}y(t0)}

\PYG{c+c1}{\PYGZsh{} timestep size is more for the numerical integrator}
\PYG{n}{dt} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mf}{0.01}\PYG{p}{)}

\PYG{c+c1}{\PYGZsh{} next lines are the gradient}
\PYG{c+c1}{\PYGZsh{} D[f,x] = \PYGZhy{}2 (a \PYGZhy{} x) \PYGZhy{} 4 b x (\PYGZhy{}x\PYGZca{}2 + y)}
\PYG{c+c1}{\PYGZsh{} D[f,y] = 2 b (\PYGZhy{}x\PYGZca{}2 + y)}
\PYG{c+c1}{\PYGZsh{} written in DDA notation.}
\PYG{c+c1}{\PYGZsh{} Keep the negating sums and integrals in mind! Sum[x,y] == neg(sum(x,y))}

\PYG{n}{x} \PYG{o}{=} \PYG{n}{neg}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{n+nb}{sum}\PYG{p}{(}\PYG{n}{a}\PYG{p}{,}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n+nb}{sum}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{ic\PYGZus{}x}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{y} \PYG{o}{=} \PYG{n}{neg}\PYG{p}{(}\PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{n+nb}{sum}\PYG{p}{(}\PYG{n}{neg}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{ic\PYGZus{}my}\PYG{p}{)}\PYG{p}{)}
\end{sphinxVerbatim}

It can now be run on the shell by running the following commands:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{python} \PYG{o}{\PYGZhy{}}\PYG{n}{m} \PYG{n}{dda} \PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{dda} \PYG{n}{c} \PYG{o}{\PYGZgt{}} \PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{cpp}
\PYG{n}{g}\PYG{o}{+}\PYG{o}{+} \PYG{o}{\PYGZhy{}}\PYG{n}{std}\PYG{o}{=}\PYG{n}{c}\PYG{o}{+}\PYG{o}{+}\PYG{l+m+mi}{17} \PYG{o}{\PYGZhy{}}\PYG{n}{o} \PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{o} \PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{cpp}
\PYG{o}{.}\PYG{o}{/}\PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{o} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{dt}\PYG{p}{:}\PYG{n}{int\PYGZus{}1}\PYG{o}{=}\PYG{l+m+mf}{0.0001} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{dt}\PYG{p}{:}\PYG{n}{int\PYGZus{}2}\PYG{o}{=}\PYG{l+m+mf}{0.0001}  \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{max\PYGZus{}iterations}\PYG{o}{=}\PYG{l+m+mi}{100000} \PYG{n}{x} \PYG{n}{y} \PYG{o}{|} \PYG{n}{tee} \PYG{n}{output}\PYG{o}{.}\PYG{n}{txt}
\end{sphinxVerbatim}

You can now plot the output for instance with gnuplot:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n+nb}{set} \PYG{n}{key} \PYG{n}{top} \PYG{n}{left} \PYG{n}{autotitle} \PYG{n}{columnhead}
\PYG{n+nb}{set} \PYG{n}{logscale} \PYG{n}{x}
\PYG{n}{plot} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{output.txt}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{0}\PYG{p}{:}\PYG{l+m+mi}{1} \PYG{n}{w} \PYG{n}{l}
\PYG{n}{replot} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{output.txt}\PYG{l+s+s2}{\PYGZdq{}} \PYG{n}{using} \PYG{l+m+mi}{0}\PYG{p}{:}\PYG{l+m+mi}{2} \PYG{n}{w} \PYG{n}{l}
\end{sphinxVerbatim}

Or do anything else on the CSV data.


\paragraph{Inspecting the command line interface of the C++ ODE solver}
\label{\detokenize{dda/shell-example:inspecting-the-command-line-interface-of-the-c-ode-solver}}
Run the executable with \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}help}} to see all possible options:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{Usage}\PYG{p}{:} \PYG{o}{.}\PYG{o}{/}\PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{o} \PYG{p}{[}\PYG{n}{arguments}\PYG{p}{]} \PYG{o}{\PYGZlt{}}\PYG{n}{variables\PYGZus{}to\PYGZus{}print}\PYG{o}{\PYGZgt{}}
\PYG{n}{This} \PYG{o+ow}{is} \PYG{n}{an} \PYG{n}{ODE} \PYG{n}{integrator} \PYG{n}{generated} \PYG{n}{by} \PYG{n}{PyDDA}\PYG{o}{.}

\PYG{o}{*} \PYG{n}{Boolean} \PYG{n}{arguments} \PYG{p}{(}\PYG{n}{Usage} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{foo} \PYG{o+ow}{or} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mi}{1} \PYG{o+ow}{or} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{)}
  \PYG{n}{always\PYGZus{}compute\PYGZus{}aux\PYGZus{}before\PYGZus{}printing} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{)}
  \PYG{n}{binary\PYGZus{}output} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{0}\PYG{p}{)}
  \PYG{n}{debug} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{0}\PYG{p}{)}
  \PYG{n}{list\PYGZus{}all\PYGZus{}variables} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{0}\PYG{p}{)}
  \PYG{n}{skip\PYGZus{}header} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{0}\PYG{p}{)}
  \PYG{n}{write\PYGZus{}initial\PYGZus{}conditions} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{0}\PYG{p}{)}
\PYG{o}{*} \PYG{n}{Numeric} \PYG{n}{arguments}\PYG{p}{:} \PYG{p}{(}\PYG{n}{Usage} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mi}{123}\PYG{p}{)}
  \PYG{n}{max\PYGZus{}iterations} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{100}\PYG{p}{)}
  \PYG{n}{modulo\PYGZus{}progress} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{)}
  \PYG{n}{modulo\PYGZus{}write} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{)}
  \PYG{n}{number\PYGZus{}precision} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{5}\PYG{p}{)}
  \PYG{n}{rk\PYGZus{}order} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{o}{*} \PYG{n}{Overwrite} \PYG{n}{initial} \PYG{n}{conditions} \PYG{p}{(}\PYG{n}{initial} \PYG{n}{data}\PYG{p}{)}\PYG{p}{:} \PYG{p}{(}\PYG{n}{Usage} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{initial}\PYG{p}{:}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mf}{1.23}\PYG{p}{)}
  \PYG{n}{int\PYGZus{}1} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{2}\PYG{p}{)}
  \PYG{n}{int\PYGZus{}2} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mi}{2}\PYG{p}{)}
\PYG{o}{*} \PYG{n}{Overwrite} \PYG{p}{(}\PYG{n}{per}\PYG{o}{\PYGZhy{}}\PYG{n}{variable}\PYG{p}{)} \PYG{n}{time} \PYG{n}{step} \PYG{n}{size}\PYG{p}{:} \PYG{p}{(}\PYG{n}{Usage} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{dt}\PYG{p}{:}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mf}{0.001} \PYG{o+ow}{or} \PYG{n}{even} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{dt}\PYG{p}{:}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mf}{1e\PYGZhy{}6}\PYG{p}{)}
  \PYG{n}{int\PYGZus{}1} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mf}{0.01}\PYG{p}{)}
  \PYG{n}{int\PYGZus{}2} \PYG{p}{(}\PYG{n}{default} \PYG{n}{value}\PYG{p}{:} \PYG{l+m+mf}{0.01}\PYG{p}{)}
\PYG{o}{*} \PYG{n}{Overwrite} \PYG{n}{constants}\PYG{p}{:} \PYG{n}{Not} \PYG{n}{possible} \PYG{n}{since} \PYG{n}{compiled} \PYG{k}{as} \PYG{n+nb}{compile} \PYG{n}{time} \PYG{n}{constants}\PYG{o}{.}
\PYG{o}{*} \PYG{n}{Query} \PYG{n}{fields}\PYG{p}{:} \PYG{p}{(}\PYG{k}{if} \PYG{n}{none} \PYG{n}{given}\PYG{p}{,} \PYG{n+nb}{all} \PYG{n}{are} \PYG{n}{dumped}\PYG{p}{)}
  \PYG{n}{a}\PYG{p}{,} \PYG{n}{b}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{ic\PYGZus{}my}\PYG{p}{,} \PYG{n}{ic\PYGZus{}x}\PYG{p}{,}
  \PYG{n}{int\PYGZus{}1}\PYG{p}{,} \PYG{n}{int\PYGZus{}2}\PYG{p}{,} \PYG{n}{mult\PYGZus{}1}\PYG{p}{,} \PYG{n}{mult\PYGZus{}2}\PYG{p}{,} \PYG{n}{mult\PYGZus{}3}\PYG{p}{,}
  \PYG{n}{mult\PYGZus{}4}\PYG{p}{,} \PYG{n}{mult\PYGZus{}5}\PYG{p}{,} \PYG{n}{mult\PYGZus{}6}\PYG{p}{,} \PYG{n}{mult\PYGZus{}7}\PYG{p}{,} \PYG{n}{mult\PYGZus{}8}\PYG{p}{,}
  \PYG{n}{neg\PYGZus{}1}\PYG{p}{,} \PYG{n}{neg\PYGZus{}2}\PYG{p}{,} \PYG{n}{neg\PYGZus{}3}\PYG{p}{,} \PYG{n}{neg\PYGZus{}4}\PYG{p}{,} \PYG{n}{sum\PYGZus{}1}\PYG{p}{,}
  \PYG{n}{sum\PYGZus{}2}\PYG{p}{,} \PYG{n}{sum\PYGZus{}3}\PYG{p}{,} \PYG{n}{x}\PYG{p}{,} \PYG{n}{y}

\PYG{n}{Exemplaric} \PYG{n}{usage}\PYG{p}{:}
  \PYG{o}{.}\PYG{o}{/}\PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{o} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{foo}\PYG{o}{=}\PYG{l+m+mi}{1} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{bar}\PYG{o}{=}\PYG{l+m+mi}{0} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{baz}\PYG{o}{=}\PYG{l+m+mi}{7} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{ic}\PYG{p}{:}\PYG{n}{var1}\PYG{o}{=}\PYG{l+m+mf}{0.5} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{dt}\PYG{p}{:}\PYG{n}{var2}\PYG{o}{=}\PYG{l+m+mf}{0.01} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{const}\PYG{p}{:}\PYG{n}{something}\PYG{o}{=}\PYG{l+m+mi}{42} \PYG{n}{var1} \PYG{n}{var2} \PYG{n}{var3}

\PYG{n}{For} \PYG{n}{more} \PYG{n}{options} \PYG{o+ow}{and} \PYG{n}{help}\PYG{p}{,} \PYG{n}{see} \PYG{n}{the} \PYG{n}{PyDDA} \PYG{n}{code} \PYG{n}{documentation} \PYG{n}{at} \PYG{n}{https}\PYG{p}{:}\PYG{o}{/}\PYG{o}{/}\PYG{n}{pyanalog}\PYG{o}{.}\PYG{n}{readthedocs}\PYG{o}{.}\PYG{n}{io}\PYG{o}{/}
\end{sphinxVerbatim}


\paragraph{But I want a better ODE Solver!}
\label{\detokenize{dda/shell-example:but-i-want-a-better-ode-solver}}
The C++ based solver is really very basic. It allows to introspect all the quantities
in a dense output, but for instance does not have adaptive time step size. Time to use
something more mature, such as the \sphinxhref{https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve\_ivp.html}{mature ODE/IVP solvers by scipy}%
\begin{footnote}[67]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve\_ivp.html}
%
\end{footnote}
(which used to be a frontend for ODEPACK). There is a DDA interface to Scipy (see
package \sphinxcode{\sphinxupquote{dda.scipy}}) and it can also be used from command line:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{python} \PYG{o}{\PYGZhy{}}\PYG{n}{m} \PYG{n}{dda}\PYG{o}{.}\PYG{n}{scipy}  \PYG{o}{\PYGZhy{}}\PYG{n}{t} \PYG{l+m+mi}{10} \PYG{n}{rosenbrock}\PYG{o}{.}\PYG{n}{dda} \PYG{o}{|} \PYG{n}{tee} \PYG{n}{output2}\PYG{o}{.}\PYG{n}{txt}
\end{sphinxVerbatim}

Note that in this example, \sphinxcode{\sphinxupquote{output.txt}} and \sphinxcode{\sphinxupquote{output2.txt}} hold similar data, since
in the C++ solver case, the solver was run until \sphinxcode{\sphinxupquote{t\_final = dt * N = 0.0001 * 100000 = 10}},
the same as in the scipy solver case. However, by convention, the C++ solver does not include
a time column (you have to generate it by yourself with \sphinxcode{\sphinxupquote{t=int(const(1), dt, 0)}} if you need
one).


\subsection{Python DDA circuits}
\label{\detokenize{dda/examples:python-dda-circuits}}\begin{description}
\item[{\sphinxcode{\sphinxupquote{N\sphinxhyphen{}body.py}}}] \leavevmode
is an example python file which generates traditional DDA code.
It implements N\sphinxhyphen{}body physics with an inverse square law force
(Coulomb/Newton like); the initial data show two particles in a two
dimensional simulation domain on a circular orbit.

The code is written having in mind to compare the old dda2c.pl and
the novel PyDDA implementation, therefore it has no coupling to
the PyDDA code. It is in general not recommended to write PyDDA
code like that.

\item[{\sphinxcode{\sphinxupquote{md\_water\_toy.py}}}] \leavevmode
A minimal molecular dynamics water toy simulation, basically an
application of the N\sphinxhyphen{}body paradigm. This is a good and running example of
a prototypical PyDDA application in science. It requires \sphinxcode{\sphinxupquote{numpy}}
because it compiles vector/matrix like quantities. It is also
equipped with a plotting/visualization of the simulation after
being run with a generated C++ code.

\end{description}


\subsection{Jupyter/IPython Notebooks}
\label{\detokenize{dda/examples:jupyter-ipython-notebooks}}
The notebooks are embedded within this documentation.


\subsubsection{DDA walkthrought example: Chua attractor}
\label{\detokenize{examples/chua:DDA-walkthrought-example:-Chua-attractor}}\label{\detokenize{examples/chua::doc}}
What follows is an example of the Chua attractor. It is described in the \sphinxhref{http://analogparadigm.com/downloads/alpaca\_3.pdf}{Analog Paradigm Application Note 3}%
\begin{footnote}[68]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/downloads/alpaca\_3.pdf}
%
\end{footnote} as well as in section 6.15 in Bernd’s new book (Analog Programming II). The attractor is described by a coupled set of three ordinary differential equations,
\begin{equation*}
\begin{split}\dot x = c_1 (y-x-f(x)) \\
\dot y = c_2 (x-y+z) \\
\dot z = -c_3 y\end{split}
\end{equation*}
with \(f(x)\) a simple function decribing the Chua diode (given algebraically) and a number of parameters \(c_{1,2,3}\). What follows is the scaling of these equations. The resulting set of equations is slightly more verbose. It’s implementation is given in the following \sphinxstyleemphasis{traditional DDA} file:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[1]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{o}{!}cat chua.dda
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\#
\# Copyright (c) 2020 anabrid GmbH
\# Contact: https://www.anabrid.com/licensing/
\#
\# This file is part of the examples of the PyAnalog toolkit.
\#
\# ANABRID\_BEGIN\_LICENSE:GPL
\# Commercial License Usage
\# Licensees holding valid commercial anabrid licenses may use this file in
\# accordance with the commercial license agreement provided with the
\# Software or, alternatively, in accordance with the terms contained in
\# a written agreement between you and Anabrid GmbH. For licensing terms
\# and conditions see https://www.anabrid.com/licensing. For further
\# information use the contact form at https://www.anabrid.com/contact.
\#
\# GNU General Public License Usage
\# Alternatively, this file may be used under the terms of the GNU
\# General Public License version 3 as published by the Free Software
\# Foundation and appearing in the file LICENSE.GPL3 included in the
\# packaging of this file. Please review the following information to
\# ensure the GNU General Public License version 3 requirements
\# will be met: https://www.gnu.org/licenses/gpl-3.0.html.
\# ANABRID\_END\_LICENSE
\#


\# Chua attractor, chapter 6.15 from Bernds book ap2.pdf
\# Below is the scaled version (equations 6.40-6.51)

x0 = const(0.1)
x1 = mult(-10, neg(sum(x, fx)))
x2 = neg(sum(y, mult(0.5, x1)))
x  = neg(sum(mult(3.12, neg(int(x2, dt, 0))), x0))

y1 = neg(sum(z, neg(mult(0.125, y))))
y2 = neg(sum(mult(1.25, x), mult(2, y1)))
y  = mult(4, neg(int(y2, dt, 0)))

z  = int(mult(3.5, y), dt, 0)

f1 = abs(sum(mult(0.7143,x),  0.2857))
f2 = abs(sum(mult(0.7143,x), -0.2857))
f3 = neg(sum(f1, neg(f2)))
fx = sum(mult(0.714, x), mult(0.3003, f3))

dt = const(0.001)
\end{sphinxVerbatim}
}

In the following, we use the PyDDA library to read in this DDA file and demonstrate the internal representation.

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[2]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{dsl} \PYG{k+kn}{import} \PYG{n}{read\PYGZus{}traditional\PYGZus{}dda}
\PYG{n}{chua\PYGZus{}text} \PYG{o}{=} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{chua.dda}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{state} \PYG{o}{=} \PYG{n}{read\PYGZus{}traditional\PYGZus{}dda}\PYG{p}{(}\PYG{n}{chua\PYGZus{}text}\PYG{p}{)}
\PYG{n}{state}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[2]:\,\hspace{\fboxrule}\hspace{\fboxsep}}State(\{'dt': const(0.001),
 'f1': abs(sum(mult(0.7143, x), 0.2857)),
 'f2': abs(sum(mult(0.7143, x), -0.2857)),
 'f3': neg(sum(f1, neg(f2))),
 'fx': sum(mult(0.714, x), mult(0.3003, f3)),
 'x': neg(sum(mult(3.12, neg(int(x2, dt, 0))), x0)),
 'x0': const(0.1),
 'x1': mult(-10, neg(sum(x, fx))),
 'x2': neg(sum(y, mult(0.5, x1))),
 'y': mult(4, neg(int(y2, dt, 0))),
 'y1': neg(sum(z, neg(mult(0.125, y)))),
 'y2': neg(sum(mult(1.25, x), mult(2, y1))),
 'z': int(mult(3.5, y), dt, 0)\})
\end{sphinxVerbatim}
}


\paragraph{Syntax trees: Down into the rabbit hole}
\label{\detokenize{examples/chua:Syntax-trees:-Down-into-the-rabbit-hole}}
Obviously, the output of the internal data structure \sphinxstyleemphasis{state} and the DDA file itself does not differ so much. That is by intention, both look quite pythonic. The state itself is basically a dictionary (mapping) from strings (the left hand sides in the DDA file) to the expressions (their right hand sides). Let’s inspect such an expression.

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[3]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[3]:\,\hspace{\fboxrule}\hspace{\fboxsep}}int(mult(3.5, y), dt, 0)
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[4]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n+nb}{type}\PYG{p}{(}\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[4]:\,\hspace{\fboxrule}\hspace{\fboxsep}}dda.ast.Symbol
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[5]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{head}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{tail}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
int
(mult(3.5, y), dt, 0)
\end{sphinxVerbatim}
}

What we are actually looking at is the PyDDA\sphinxhyphen{}representation of a mathematical expression tree. We can visualize this tree:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[6]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{draw\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\savebox\nbsphinxpromptbox[0pt][r]{\color{nbsphinxout}\Verb|\strut{[6]:}\,|}

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=3328\sphinxpxdimen,height=3760\sphinxpxdimen]{{examples_chua_10_0}.pdf}

\end{nbsphinxfancyoutput}

Given this, we can compute the dependencies of all variables in the sytem:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[7]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{graph} \PYG{o}{=} \PYG{n}{state}\PYG{o}{.}\PYG{n}{draw\PYGZus{}dependency\PYGZus{}graph}\PYG{p}{(}\PYG{n}{export\PYGZus{}dot}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}
\PYG{n}{graph}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[7]:\,\hspace{\fboxrule}\hspace{\fboxsep}}<networkx.classes.digraph.DiGraph at 0x7f431c5df3d0>
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[9]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{c+c1}{\PYGZsh{} Draw the graph with matlotlib}
\PYG{k+kn}{import} \PYG{n+nn}{networkx} \PYG{k}{as} \PYG{n+nn}{nx}
\PYG{k+kn}{from} \PYG{n+nn}{networkx}\PYG{n+nn}{.}\PYG{n+nn}{drawing}\PYG{n+nn}{.}\PYG{n+nn}{nx\PYGZus{}agraph} \PYG{k+kn}{import} \PYG{n}{graphviz\PYGZus{}layout}
\PYG{n}{pos} \PYG{o}{=} \PYG{n}{graphviz\PYGZus{}layout}\PYG{p}{(}\PYG{n}{graph}\PYG{p}{)}
\PYG{n}{nx}\PYG{o}{.}\PYG{n}{draw}\PYG{p}{(}\PYG{n}{graph}\PYG{p}{,} \PYG{n}{pos}\PYG{o}{=}\PYG{n}{pos}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=446\sphinxpxdimen,height=302\sphinxpxdimen]{{examples_chua_13_0}.png}

\end{nbsphinxfancyoutput}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[10]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{c+c1}{\PYGZsh{} draw the graph with graphviz (requires pydot,graphviz)}
\PYG{k+kn}{from} \PYG{n+nn}{networkx}\PYG{n+nn}{.}\PYG{n+nn}{drawing}\PYG{n+nn}{.}\PYG{n+nn}{nx\PYGZus{}pydot} \PYG{k+kn}{import} \PYG{n}{to\PYGZus{}pydot}
\PYG{k+kn}{from} \PYG{n+nn}{graphviz} \PYG{k+kn}{import} \PYG{n}{Source}
\PYG{n}{nx2dot} \PYG{o}{=} \PYG{k}{lambda} \PYG{n}{graph}\PYG{p}{:} \PYG{n}{Source}\PYG{p}{(}\PYG{n}{to\PYGZus{}pydot}\PYG{p}{(}\PYG{n}{graph}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to\PYGZus{}string}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[11]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{nx2dot}\PYG{p}{(}\PYG{n}{graph}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\savebox\nbsphinxpromptbox[0pt][r]{\color{nbsphinxout}\Verb|\strut{[11]:}\,|}

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=3904\sphinxpxdimen,height=12224\sphinxpxdimen]{{examples_chua_15_0}.pdf}

\end{nbsphinxfancyoutput}

Based on this dependency analysis, one can \sphinxstyleemphasis{linearize} the state, that is, define an ordering how to compute the state numerically:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[12]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n+nb}{vars} \PYG{o}{=} \PYG{n}{state}\PYG{o}{.}\PYG{n}{variable\PYGZus{}ordering}\PYG{p}{(}\PYG{p}{)}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[13]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{The evolved variables are:}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n+nb}{vars}\PYG{o}{.}\PYG{n}{evolved}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Auxilliary variables are:}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n+nb}{vars}\PYG{o}{.}\PYG{n}{aux}\PYG{o}{.}\PYG{n}{all}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
The evolved variables are: ['int\_1', 'int\_2', 'z']
Auxilliary variables are: ['f1', 'f2', 'f3', 'fx', 'mult\_10', 'mult\_6', 'mult\_9', 'sum\_1', 'sum\_2', 'sum\_3', 'sum\_4', 'sum\_5', 'sum\_6', 'sum\_7', 'sum\_8', 'x', 'x1', 'x2', 'y', 'y1', 'y2']
\end{sphinxVerbatim}
}

One sees a number of new variables. They were introduced by \sphinxstyleemphasis{naming} all \sphinxstyleemphasis{intermediate} expressions. What are these intermediates? Let’s review again the variable \sphinxstyleemphasis{z}:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[14]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{draw\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\savebox\nbsphinxpromptbox[0pt][r]{\color{nbsphinxout}\Verb|\strut{[14]:}\,|}

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=3328\sphinxpxdimen,height=3760\sphinxpxdimen]{{examples_chua_20_0}.pdf}

\end{nbsphinxfancyoutput}

Here, the left most child is an intermediate expression, since it computes \sphinxcode{\sphinxupquote{mult(3.5, y)}}. We can give this intermediate result a concrete name and replace the whole subtree with this name:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[15]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state}\PYG{o}{.}\PYG{n}{name\PYGZus{}computing\PYGZus{}elements}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{z}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{draw\PYGZus{}graph}\PYG{p}{(}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\savebox\nbsphinxpromptbox[0pt][r]{\color{nbsphinxout}\Verb|\strut{[15]:}\,|}

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=3264\sphinxpxdimen,height=2768\sphinxpxdimen]{{examples_chua_22_0}.pdf}

\end{nbsphinxfancyoutput}


\paragraph{Simulating a circuit}
\label{\detokenize{examples/chua:Simulating-a-circuit}}
In the following, we use the C++ code generator to simulate this simple ordinary differential equation:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[29]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{cpp\PYGZus{}code} \PYG{o}{=} \PYG{n}{state}\PYG{o}{.}\PYG{n}{export}\PYG{p}{(}\PYG{n}{to}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{C}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{cpp\PYGZus{}code}\PYG{p}{[}\PYG{p}{:}\PYG{l+m+mi}{1000}\PYG{p}{]}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{// ... (in total }\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{cpp\PYGZus{}code}\PYG{o}{.}\PYG{n}{count}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{ lines of C/C++ code) ...}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
// This code was generated by PyDDA.

\#include <cmath> /* don't forget -lm for linking */
\#include <cfenv> /* for feraisexcept and friends */
\#include <limits> /* for signaling NAN */
\#include <vector>
\#include <string>
\#include <sstream>
\#include <algorithm>
\#include <map>
\#include <cstdio>
\#include <iostream>
\#include <fstream>

bool debug;
constexpr double \_nan\_ = std::numeric\_limits<double>::signaling\_NaN();

namespace dda \{

/* if you use an old C++ compiler, just remove the newer features */
\#define A constexpr double            /* constexpr requires C++11 */
\#define D template<typename{\ldots} T> A   /* Variadic templates require C++17 */

// Known limitations for div(int, double): If certain arguments appear as integer
// in the code (i.e. 1 instead of 1.0), there is div(int,int) kicking in from
// cstdlib. TODO: Should rename div to Div; following int->Int.

A neg(double a) \{ return -a; \}
A div(double a, double b) \{ return a/b; \}
D Int(T{\ldots} a) \{ return -(a + {\ldots}); \} // int() is res
// {\ldots} (in total  481  lines of C/C++ code) {\ldots}
\end{sphinxVerbatim}
}

We printed the generated C++ code, which is in fact just a string in python, in the cell above. Next come some shortcut functions which call the system C++ compiler and run the binary, all externally on the system shell. The return value is slurped in as CSV data with numpy, so we readily have it for plotting.

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[30]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{cpp\PYGZus{}exporter} \PYG{k+kn}{import} \PYG{n+nb}{compile}\PYG{p}{,} \PYG{n}{run}
\PYG{n+nb}{compile}\PYG{p}{(}\PYG{n}{cpp\PYGZus{}code}\PYG{p}{)}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[31]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{c+c1}{\PYGZsh{} This shows the stdout of the binary generated by the above C++ code:}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{run}\PYG{p}{(}\PYG{n}{arguments}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{max\PYGZus{}iterations}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:}\PYG{l+m+mi}{10}\PYG{p}{\PYGZcb{}}\PYG{p}{,} \PYG{n}{fields\PYGZus{}to\PYGZus{}export}\PYG{o}{=}\PYG{n+nb}{list}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{xyz}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{return\PYGZus{}ndarray}\PYG{o}{=}\PYG{k+kc}{False}\PYG{p}{)}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
Running: ./a.out --max\_iterations=10 x y z
x       y       z
0.100223        0.0005  0
0.100448        0.00100062      -1.75e-06
0.100675        0.00150184      -5.25215e-06
0.100905        0.00200368      -1.05086e-05
0.101136        0.00250611      -1.75215e-05
0.10137 0.00300915      -2.62929e-05
0.101605        0.00351277      -3.68249e-05
0.101843        0.00401699      -4.91196e-05
0.102082        0.0045218       -6.3179e-05
0.102324        0.00502718      -7.90053e-05

\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[32]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{c+c1}{\PYGZsh{} We can slurp in the CSV data directly to a numpy recarray:}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{run}\PYG{p}{(}\PYG{n}{arguments}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{max\PYGZus{}iterations}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:}\PYG{l+m+mi}{1000}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{modulo\PYGZus{}write}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:}\PYG{l+m+mi}{10}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
Running: ./a.out --max\_iterations=1000 --modulo\_write=10
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[33]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{result}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[33]:\,\hspace{\fboxrule}\hspace{\fboxsep}}array([0.100223, 0.102568, 0.105126, 0.107902, 0.110904, 0.114137,
       0.11761 , 0.121327, 0.125297, 0.129525, 0.134019, 0.138785,
       0.143831, 0.149164, 0.154792, 0.16072 , 0.166958, 0.173512,
       0.180391, 0.187603, 0.195156, 0.203058, 0.211319, 0.219946,
       0.22895 , 0.23834 , 0.248125, 0.258317, 0.268924, 0.279959,
       0.291432, 0.303354, 0.315739, 0.328597, 0.341943, 0.355789,
       0.370149, 0.385039, 0.400471, 0.415958, 0.430975, 0.445545,
       0.459687, 0.473419, 0.486757, 0.499714, 0.512304, 0.524535,
       0.536418, 0.54796 , 0.559167, 0.570045, 0.580597, 0.590828,
       0.600738, 0.61033 , 0.619603, 0.628559, 0.637196, 0.645513,
       0.653509, 0.661182, 0.668528, 0.675547, 0.682235, 0.688589,
       0.694606, 0.700283, 0.705617, 0.710605, 0.715244, 0.719531,
       0.723464, 0.727041, 0.730258, 0.733115, 0.73561 , 0.737741,
       0.739508, 0.74091 , 0.741947, 0.742621, 0.742931, 0.742879,
       0.742467, 0.741697, 0.740573, 0.739097, 0.737275, 0.735109,
       0.732606, 0.729772, 0.726611, 0.723132, 0.719342, 0.715248,
       0.710859, 0.706184, 0.701233, 0.696016])
\end{sphinxVerbatim}
}

The above cell output shows a NumPy array, which is a Python\sphinxhyphen{}internal representation of the CSV file printed in the cell above. NumPy arrays are suitable for plotting, as we do next.

What is actually called by \sphinxcode{\sphinxupquote{cpp\_exporter.run()}} is \sphinxhref{https://numpy.org/doc/stable/reference/generated/numpy.genfromtxt.html}{np.genfromtxt()}%
\begin{footnote}[69]\sphinxAtStartFootnote
\sphinxnolinkurl{https://numpy.org/doc/stable/reference/generated/numpy.genfromtxt.html}
%
\end{footnote}. As our CSV file has a header row with column names, it creates a \sphinxhref{https://numpy.org/doc/stable/reference/generated/numpy.recarray.html}{numpy recarray}%
\begin{footnote}[70]\sphinxAtStartFootnote
\sphinxnolinkurl{https://numpy.org/doc/stable/reference/generated/numpy.recarray.html}
%
\end{footnote}. Therefore, we can address the column \sphinxcode{\sphinxupquote{x}} by writing \sphinxcode{\sphinxupquote{result{[}"x"{]}}}.

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[34]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k+kn}{import} \PYG{n+nn}{matplotlib}\PYG{n+nn}{.}\PYG{n+nn}{pyplot} \PYG{k}{as} \PYG{n+nn}{plt}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[35]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{result}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{result}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{time (iterations)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{field values}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[35]:\,\hspace{\fboxrule}\hspace{\fboxsep}}<matplotlib.legend.Legend at 0x7f42f5dd2820>
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=386\sphinxpxdimen,height=262\sphinxpxdimen]{{examples_chua_32_1}.png}

\end{nbsphinxfancyoutput}

The above plot shows the time evolution of the quantity \sphinxstyleemphasis{x} and \sphinxstyleemphasis{y}. The plot is not very meaningful, but at least we see that the values are well within the analog computer bounds \([-1,1]\).

Let’s run the simulation a bit longer and display a \sphinxstyleemphasis{phase space} plot of \sphinxstyleemphasis{x} and \sphinxstyleemphasis{y}:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[78]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{result} \PYG{o}{=} \PYG{n}{run}\PYG{p}{(}\PYG{n}{arguments}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{max\PYGZus{}iterations}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:}\PYG{l+m+mi}{30000}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{modulo\PYGZus{}write}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:}\PYG{l+m+mi}{50}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{;} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{result}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{result}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{y}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{o\PYGZhy{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
Running: ./a.out --max\_iterations=30000 --modulo\_write=50
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[78]:\,\hspace{\fboxrule}\hspace{\fboxsep}}[<matplotlib.lines.Line2D at 0x7f12dd23d580>]
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=394\sphinxpxdimen,height=262\sphinxpxdimen]{{examples_chua_34_2}.png}

\end{nbsphinxfancyoutput}

That’s it for the moment. If you want to see even more advanced plotting, inspect the \sphinxcode{\sphinxupquote{run\sphinxhyphen{}chua.py}} file in the directory of this notebook file (i.a. in the \sphinxcode{\sphinxupquote{experiments/}} directory).


\subsubsection{Heat\sphinxhyphen{}equation in 1D and 2D with DDA}
\label{\detokenize{examples/Heat-Equation:Heat-equation-in-1D-and-2D-with-DDA}}\label{\detokenize{examples/Heat-Equation::doc}}
The \sphinxhref{https://en.wikipedia.org/wiki/Heat\_equation}{heat equation}%
\begin{footnote}[71]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Heat\_equation}
%
\end{footnote} is a partial differential equation (PDE). Being an elliptical equation with a Laplace operator, so second order in space, first order in time, it is one of the typical text\sphinxhyphen{}book introductions. It describes the fate of a given field \(u=u(\vec x, t)\), and is given by
\begin{equation*}
\begin{split}\frac{\partial u}{\partial t} = \alpha \nabla^2 u\end{split}
\end{equation*}
where \(\nabla^2\) is the Laplace operator \(\nabla^2 = \sum_{i=1}^d \partial^2 / \partial^2 x_i\) in \(d\) spatial dimensions and \(\alpha\) is a constant for driving the coupling/gain.

The aim of this notebook is to demonstrate how to solve the heat\sphinxhyphen{}equation in one and two spatial dimensions with DDA or an analog computer, respectively. To do so, we use the \sphinxhref{https://en.wikipedia.org/wiki/Method\_of\_lines}{method of lines}%
\begin{footnote}[72]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Method\_of\_lines}
%
\end{footnote} to convert the PDE in a set of ordinary differential equations (ODEs), which itself are spatially discretized with \sphinxhref{https://en.wikipedia.org/wiki/Finite\_difference}{central finite differences}%
\begin{footnote}[73]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Finite\_difference}
%
\end{footnote}.

This example follows the \sphinxhref{http://analogparadigm.com/downloads/alpaca\_24.pdf}{Analog Paradigm Application Notes 24}%
\begin{footnote}[74]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/downloads/alpaca\_24.pdf}
%
\end{footnote}, where a circuit and further comments on symmetries can be found.

For initial data, we will always model a singular peak \(u_0(\vec x) = \delta(\vec x_0)\) at some position \(\vec x_0\). Discretized, this translates to having all \(u_i=0\) for all \(i\) except one where \(u_i=1\).

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[1]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k+kn}{from} \PYG{n+nn}{numpy} \PYG{k+kn}{import} \PYG{o}{*}
\PYG{k+kn}{from} \PYG{n+nn}{dda} \PYG{k+kn}{import} \PYG{o}{*}
\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{computing\PYGZus{}elements} \PYG{k+kn}{import} \PYG{o}{*}
\PYG{k+kn}{from} \PYG{n+nn}{dda}\PYG{n+nn}{.}\PYG{n+nn}{cpp\PYGZus{}exporter} \PYG{k+kn}{import} \PYG{n+nb}{compile}\PYG{p}{,} \PYG{n}{run}
\PYG{k+kn}{from} \PYG{n+nn}{matplotlib}\PYG{n+nn}{.}\PYG{n+nn}{pyplot} \PYG{k+kn}{import} \PYG{o}{*}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[2]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{alpha} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}
\end{sphinxVerbatim}
}


\paragraph{1D Heat equation}
\label{\detokenize{examples/Heat-Equation:1D-Heat-equation}}
For the beginning, we solve the heat equation in one temporal and one spatial dimension.

First, we define the symbols \(u\) and \(u0\) and the initial data:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[3]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} start with a fresh state}

\PYG{n}{N} \PYG{o}{=} \PYG{l+m+mi}{10} \PYG{c+c1}{\PYGZsh{} supporting points}
\PYG{n}{u} \PYG{o}{=} \PYG{p}{[} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)} \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{N}\PYG{p}{)}  \PYG{p}{]}

\PYG{c+c1}{\PYGZsh{} Initial conditions:}
\PYG{n}{u0} \PYG{o}{=} \PYG{p}{[} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{ic\PYGZus{}u}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)} \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{N}\PYG{p}{)} \PYG{p}{]}

\PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{N}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{state}\PYG{p}{[}\PYG{n}{u0}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{p}{]} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{)}

\PYG{n}{state}\PYG{p}{[} \PYG{n}{u0}\PYG{p}{[}\PYG{l+m+mi}{5}\PYG{p}{]} \PYG{p}{]} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} our candle at the boundary :\PYGZhy{}D}

\PYG{c+c1}{\PYGZsh{} Time step}
\PYG{n}{dt} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{dt}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{state}\PYG{p}{[}\PYG{n}{dt}\PYG{p}{]} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mf}{0.01}\PYG{p}{)}

\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{We have defined:}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{u} \PYG{l+s+si}{= \PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{u0} \PYG{l+s+si}{= \PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{state} \PYG{l+s+si}{= \PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
We have defined:
u = [u0, u1, u2, u3, u4, u5, u6, u7, u8, u9]
u0 = [ic\_u0, ic\_u1, ic\_u2, ic\_u3, ic\_u4, ic\_u5, ic\_u6, ic\_u7, ic\_u8, ic\_u9]
state = State(\{'dt': const(0.01),
 'ic\_u0': const(0),
 'ic\_u1': const(0),
 'ic\_u2': const(0),
 'ic\_u3': const(0),
 'ic\_u4': const(0),
 'ic\_u5': const(1),
 'ic\_u6': const(0),
 'ic\_u7': const(0),
 'ic\_u8': const(0),
 'ic\_u9': const(0)\})
\end{sphinxVerbatim}
}

In 1D, we approximate the Laplace operator by the central finite difference
\begin{equation*}
\begin{split}\nabla^2 u = u_{i-1} + u_{i+1} - 2u_i\end{split}
\end{equation*}
We implement \sphinxhref{https://en.wikipedia.org/wiki/Periodic\_boundary\_conditions}{periodic boundary conditions}%
\begin{footnote}[75]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Periodic\_boundary\_conditions}
%
\end{footnote}, so \(u_N=u_0\).

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[4]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{N}\PYG{p}{)}\PYG{p}{:}
    \PYG{c+c1}{\PYGZsh{} compute i\PYGZhy{}1 and i+1 with proper boundary conditions:}
    \PYG{n}{im1} \PYG{o}{=} \PYG{n}{i}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1} \PYG{k}{if} \PYG{n}{i}\PYG{o}{\PYGZgt{}}\PYG{l+m+mi}{0} \PYG{k}{else} \PYG{n}{N}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}
    \PYG{n}{ip1} \PYG{o}{=} \PYG{n}{i}\PYG{o}{+}\PYG{l+m+mi}{1} \PYG{k}{if} \PYG{n}{i}\PYG{o}{!=}\PYG{n}{N}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1} \PYG{k}{else} \PYG{l+m+mi}{0}
    \PYG{n}{helper} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u\PYGZus{}intermediate\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
    \PYG{n}{state}\PYG{p}{[}\PYG{n}{helper}\PYG{p}{]} \PYG{o}{=} \PYG{n}{neg}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{n}{u}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
    \PYG{n}{state}\PYG{p}{[} \PYG{n}{u}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]} \PYG{p}{]} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{alpha}\PYG{p}{,}\PYG{n+nb}{sum}\PYG{p}{(}\PYG{n}{u}\PYG{p}{[}\PYG{n}{im1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{u}\PYG{p}{[}\PYG{n}{ip1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{helper}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{u0}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

Let’s inspect our state built so far:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[5]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[5]:\,\hspace{\fboxrule}\hspace{\fboxsep}}State(\{'dt': const(0.01),
 'ic\_u0': const(0),
 'ic\_u1': const(0),
 'ic\_u2': const(0),
 'ic\_u3': const(0),
 'ic\_u4': const(0),
 'ic\_u5': const(1),
 'ic\_u6': const(0),
 'ic\_u7': const(0),
 'ic\_u8': const(0),
 'ic\_u9': const(0),
 'u0': int(mult(const(4), sum(u9, u1, u\_intermediate\_0)), dt, ic\_u0),
 'u1': int(mult(const(4), sum(u0, u2, u\_intermediate\_1)), dt, ic\_u1),
 'u2': int(mult(const(4), sum(u1, u3, u\_intermediate\_2)), dt, ic\_u2),
 'u3': int(mult(const(4), sum(u2, u4, u\_intermediate\_3)), dt, ic\_u3),
 'u4': int(mult(const(4), sum(u3, u5, u\_intermediate\_4)), dt, ic\_u4),
 'u5': int(mult(const(4), sum(u4, u6, u\_intermediate\_5)), dt, ic\_u5),
 'u6': int(mult(const(4), sum(u5, u7, u\_intermediate\_6)), dt, ic\_u6),
 'u7': int(mult(const(4), sum(u6, u8, u\_intermediate\_7)), dt, ic\_u7),
 'u8': int(mult(const(4), sum(u7, u9, u\_intermediate\_8)), dt, ic\_u8),
 'u9': int(mult(const(4), sum(u8, u0, u\_intermediate\_9)), dt, ic\_u9),
 'u\_intermediate\_0': neg(mult(2, u0)),
 'u\_intermediate\_1': neg(mult(2, u1)),
 'u\_intermediate\_2': neg(mult(2, u2)),
 'u\_intermediate\_3': neg(mult(2, u3)),
 'u\_intermediate\_4': neg(mult(2, u4)),
 'u\_intermediate\_5': neg(mult(2, u5)),
 'u\_intermediate\_6': neg(mult(2, u6)),
 'u\_intermediate\_7': neg(mult(2, u7)),
 'u\_intermediate\_8': neg(mult(2, u8)),
 'u\_intermediate\_9': neg(mult(2, u9))\})
\end{sphinxVerbatim}
}

or as latex:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[28]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k+kn}{from} \PYG{n+nn}{IPython}\PYG{n+nn}{.}\PYG{n+nn}{display} \PYG{k+kn}{import} \PYG{n}{display}\PYG{p}{,} \PYG{n}{Markdown}\PYG{p}{,} \PYG{n}{Latex}
\PYG{n}{display}\PYG{p}{(}\PYG{n}{Latex}\PYG{p}{(}\PYG{n}{state}\PYG{o}{.}\PYG{n}{export}\PYG{p}{(}\PYG{n}{to}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{latex}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}
\begin{align}
dt &= 0.01 \\
ic_{u0} &= 0 \\
ic_{u1} &= 0 \\
ic_{u2} &= 0 \\
ic_{u3} &= 0 \\
ic_{u4} &= 0 \\
ic_{u5} &= 1.0 \\
ic_{u6} &= 0 \\
ic_{u7} &= 0 \\
ic_{u8} &= 0 \\
ic_{u9} &= 0 \\
u_{0} &= - \int \left(dt + ic_{u0} - 4 u_{1} - 4 u_{9} - 4 u_{intermediate 0}\right)\, dt \\
u_{1} &= - \int \left(dt + ic_{u1} - 4 u_{0} - 4 u_{2} - 4 u_{intermediate 1}\right)\, dt \\
u_{2} &= - \int \left(dt + ic_{u2} - 4 u_{1} - 4 u_{3} - 4 u_{intermediate 2}\right)\, dt \\
u_{3} &= - \int \left(dt + ic_{u3} - 4 u_{2} - 4 u_{4} - 4 u_{intermediate 3}\right)\, dt \\
u_{4} &= - \int \left(dt + ic_{u4} - 4 u_{3} - 4 u_{5} - 4 u_{intermediate 4}\right)\, dt \\
u_{5} &= - \int \left(dt + ic_{u5} - 4 u_{4} - 4 u_{6} - 4 u_{intermediate 5}\right)\, dt \\
u_{6} &= - \int \left(dt + ic_{u6} - 4 u_{5} - 4 u_{7} - 4 u_{intermediate 6}\right)\, dt \\
u_{7} &= - \int \left(dt + ic_{u7} - 4 u_{6} - 4 u_{8} - 4 u_{intermediate 7}\right)\, dt \\
u_{8} &= - \int \left(dt + ic_{u8} - 4 u_{7} - 4 u_{9} - 4 u_{intermediate 8}\right)\, dt \\
u_{9} &= - \int \left(dt + ic_{u9} - 4 u_{0} - 4 u_{8} - 4 u_{intermediate 9}\right)\, dt \\
u_{intermediate 0} &= - 2.0 u_{0} \\
u_{intermediate 1} &= - 2.0 u_{1} \\
u_{intermediate 2} &= - 2.0 u_{2} \\
u_{intermediate 3} &= - 2.0 u_{3} \\
u_{intermediate 4} &= - 2.0 u_{4} \\
u_{intermediate 5} &= - 2.0 u_{5} \\
u_{intermediate 6} &= - 2.0 u_{6} \\
u_{intermediate 7} &= - 2.0 u_{7} \\
u_{intermediate 8} &= - 2.0 u_{8} \\
u_{intermediate 9} &= - 2.0 u_{9}
\end{align}
\end{nbsphinxfancyoutput}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[6]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{c\PYGZus{}code} \PYG{o}{=} \PYG{n}{state}\PYG{o}{.}\PYG{n}{export}\PYG{p}{(}\PYG{n}{to}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{C}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{compile}\PYG{p}{(}\PYG{n}{c\PYGZus{}code}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{heateq.cc}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

If you want, you can print the generated c\_code or inspect it with a text editor.

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[7]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{data} \PYG{o}{=} \PYG{n}{run}\PYG{p}{(}\PYG{n}{arguments}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{max\PYGZus{}iterations}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{:}\PYG{l+m+mi}{400}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
Running: ./a.out --max\_iterations=400
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[12]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{rcParams}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{figure.figsize}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mi}{20}\PYG{p}{,}\PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{N}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{plot}\PYG{p}{(}\PYG{n}{data}\PYG{p}{[}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{)}

\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Evolution time (arbitrary indices)}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Field values of the supporting points}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{title}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Time evolution of the 1D heat equation supporting points}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[12]:\,\hspace{\fboxrule}\hspace{\fboxsep}}Text(0.5, 1.0, 'Time evolution of the 1D heat equation supporting points')
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=1167\sphinxpxdimen,height=604\sphinxpxdimen]{{examples_Heat-Equation_14_1}.png}

\end{nbsphinxfancyoutput}

In the following, we reconstruct the higher\sphinxhyphen{}dimensional data and display it color encoded:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[17]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{heat} \PYG{o}{=} \PYG{n}{array}\PYG{p}{(}\PYG{p}{[}\PYG{n}{data}\PYG{p}{[}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{k}{for} \PYG{n}{i} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{N}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[27]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{rcParams}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{figure.figsize}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mi}{40}\PYG{p}{,}\PYG{l+m+mi}{20}\PYG{p}{)}
\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{heat}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{:}\PYG{l+m+mi}{90}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[27]:\,\hspace{\fboxrule}\hspace{\fboxsep}}<matplotlib.image.AxesImage at 0x7f3f68cbc7f0>
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=2259\sphinxpxdimen,height=279\sphinxpxdimen]{{examples_Heat-Equation_17_1}.png}

\end{nbsphinxfancyoutput}

What you can see in the above plot is on the x\sphinxhyphen{}axis again the evolution time and on the y\sphinxhyphen{}axis the physical coordinate. Of course the whole image is pretty discretized. You see the initial data (one cell has value 1, all others value 0) and the equilibration of energy amongst all cells.


\paragraph{2D Heat Equation}
\label{\detokenize{examples/Heat-Equation:2D-Heat-Equation}}
We now solve the heat equation in two spatial and one temporal dimension, which is more similar to what is done in \sphinxurl{http://analogparadigm.com/downloads/alpaca\_24.pdf}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[30]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state} \PYG{o}{=} \PYG{n}{State}\PYG{p}{(}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} restart with a clean state}

\PYG{n}{N} \PYG{o}{=} \PYG{l+m+mi}{10} \PYG{c+c1}{\PYGZsh{} supporting points}
\PYG{n}{NN} \PYG{o}{=} \PYG{p}{(}\PYG{n}{N}\PYG{p}{,} \PYG{n}{N}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} shape in two dimensions}

\PYG{n}{u} \PYG{o}{=} \PYG{n}{array}\PYG{p}{(}\PYG{p}{[} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u\PYGZus{}}\PYG{l+s+si}{\PYGZpc{}d}\PYG{l+s+s2}{\PYGZus{}}\PYG{l+s+si}{\PYGZpc{}d}\PYG{l+s+s2}{\PYGZdq{}}\PYG{o}{\PYGZpc{}}\PYG{p}{(}\PYG{n}{i}\PYG{p}{,}\PYG{n}{j}\PYG{p}{)}\PYG{p}{)} \PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{j} \PYG{o+ow}{in} \PYG{n}{ndindex}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)} \PYG{p}{]}\PYG{p}{)}\PYG{o}{.}\PYG{n}{reshape}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)}
\PYG{n}{u}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[30]:\,\hspace{\fboxrule}\hspace{\fboxsep}}array([[u\_0\_0, u\_0\_1, u\_0\_2, u\_0\_3, u\_0\_4, u\_0\_5, u\_0\_6, u\_0\_7, u\_0\_8,
        u\_0\_9],
       [u\_1\_0, u\_1\_1, u\_1\_2, u\_1\_3, u\_1\_4, u\_1\_5, u\_1\_6, u\_1\_7, u\_1\_8,
        u\_1\_9],
       [u\_2\_0, u\_2\_1, u\_2\_2, u\_2\_3, u\_2\_4, u\_2\_5, u\_2\_6, u\_2\_7, u\_2\_8,
        u\_2\_9],
       [u\_3\_0, u\_3\_1, u\_3\_2, u\_3\_3, u\_3\_4, u\_3\_5, u\_3\_6, u\_3\_7, u\_3\_8,
        u\_3\_9],
       [u\_4\_0, u\_4\_1, u\_4\_2, u\_4\_3, u\_4\_4, u\_4\_5, u\_4\_6, u\_4\_7, u\_4\_8,
        u\_4\_9],
       [u\_5\_0, u\_5\_1, u\_5\_2, u\_5\_3, u\_5\_4, u\_5\_5, u\_5\_6, u\_5\_7, u\_5\_8,
        u\_5\_9],
       [u\_6\_0, u\_6\_1, u\_6\_2, u\_6\_3, u\_6\_4, u\_6\_5, u\_6\_6, u\_6\_7, u\_6\_8,
        u\_6\_9],
       [u\_7\_0, u\_7\_1, u\_7\_2, u\_7\_3, u\_7\_4, u\_7\_5, u\_7\_6, u\_7\_7, u\_7\_8,
        u\_7\_9],
       [u\_8\_0, u\_8\_1, u\_8\_2, u\_8\_3, u\_8\_4, u\_8\_5, u\_8\_6, u\_8\_7, u\_8\_8,
        u\_8\_9],
       [u\_9\_0, u\_9\_1, u\_9\_2, u\_9\_3, u\_9\_4, u\_9\_5, u\_9\_6, u\_9\_7, u\_9\_8,
        u\_9\_9]], dtype=object)
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[31]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{c+c1}{\PYGZsh{} Symbols for initial conditions:}
\PYG{n}{u0} \PYG{o}{=} \PYG{n}{array}\PYG{p}{(}\PYG{p}{[} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{uinitial\PYGZus{}}\PYG{l+s+si}{\PYGZpc{}d}\PYG{l+s+s2}{\PYGZus{}}\PYG{l+s+si}{\PYGZpc{}d}\PYG{l+s+s2}{\PYGZdq{}}\PYG{o}{\PYGZpc{}}\PYG{p}{(}\PYG{n}{i}\PYG{p}{,}\PYG{n}{j}\PYG{p}{)}\PYG{p}{)} \PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{j} \PYG{o+ow}{in} \PYG{n}{ndindex}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)} \PYG{p}{]}\PYG{p}{)}\PYG{o}{.}\PYG{n}{reshape}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)}
\PYG{n}{u0}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[31]:\,\hspace{\fboxrule}\hspace{\fboxsep}}array([[uinitial\_0\_0, uinitial\_0\_1, uinitial\_0\_2, uinitial\_0\_3,
        uinitial\_0\_4, uinitial\_0\_5, uinitial\_0\_6, uinitial\_0\_7,
        uinitial\_0\_8, uinitial\_0\_9],
       [uinitial\_1\_0, uinitial\_1\_1, uinitial\_1\_2, uinitial\_1\_3,
        uinitial\_1\_4, uinitial\_1\_5, uinitial\_1\_6, uinitial\_1\_7,
        uinitial\_1\_8, uinitial\_1\_9],
       [uinitial\_2\_0, uinitial\_2\_1, uinitial\_2\_2, uinitial\_2\_3,
        uinitial\_2\_4, uinitial\_2\_5, uinitial\_2\_6, uinitial\_2\_7,
        uinitial\_2\_8, uinitial\_2\_9],
       [uinitial\_3\_0, uinitial\_3\_1, uinitial\_3\_2, uinitial\_3\_3,
        uinitial\_3\_4, uinitial\_3\_5, uinitial\_3\_6, uinitial\_3\_7,
        uinitial\_3\_8, uinitial\_3\_9],
       [uinitial\_4\_0, uinitial\_4\_1, uinitial\_4\_2, uinitial\_4\_3,
        uinitial\_4\_4, uinitial\_4\_5, uinitial\_4\_6, uinitial\_4\_7,
        uinitial\_4\_8, uinitial\_4\_9],
       [uinitial\_5\_0, uinitial\_5\_1, uinitial\_5\_2, uinitial\_5\_3,
        uinitial\_5\_4, uinitial\_5\_5, uinitial\_5\_6, uinitial\_5\_7,
        uinitial\_5\_8, uinitial\_5\_9],
       [uinitial\_6\_0, uinitial\_6\_1, uinitial\_6\_2, uinitial\_6\_3,
        uinitial\_6\_4, uinitial\_6\_5, uinitial\_6\_6, uinitial\_6\_7,
        uinitial\_6\_8, uinitial\_6\_9],
       [uinitial\_7\_0, uinitial\_7\_1, uinitial\_7\_2, uinitial\_7\_3,
        uinitial\_7\_4, uinitial\_7\_5, uinitial\_7\_6, uinitial\_7\_7,
        uinitial\_7\_8, uinitial\_7\_9],
       [uinitial\_8\_0, uinitial\_8\_1, uinitial\_8\_2, uinitial\_8\_3,
        uinitial\_8\_4, uinitial\_8\_5, uinitial\_8\_6, uinitial\_8\_7,
        uinitial\_8\_8, uinitial\_8\_9],
       [uinitial\_9\_0, uinitial\_9\_1, uinitial\_9\_2, uinitial\_9\_3,
        uinitial\_9\_4, uinitial\_9\_5, uinitial\_9\_6, uinitial\_9\_7,
        uinitial\_9\_8, uinitial\_9\_9]], dtype=object)
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[32]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{c+c1}{\PYGZsh{} imprint the initial conditions:}

\PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{j} \PYG{o+ow}{in} \PYG{n}{ndindex}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{state}\PYG{p}{[}\PYG{n}{u0}\PYG{p}{[}\PYG{n}{i}\PYG{p}{,}\PYG{n}{j}\PYG{p}{]}\PYG{p}{]} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{)}

\PYG{n}{state}\PYG{p}{[} \PYG{n}{u0}\PYG{p}{[}\PYG{l+m+mi}{5}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]} \PYG{p}{]} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} our candle in the very center}

\PYG{c+c1}{\PYGZsh{} Time step}
\PYG{n}{dt} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{dt}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{state}\PYG{p}{[}\PYG{n}{dt}\PYG{p}{]} \PYG{o}{=} \PYG{n}{const}\PYG{p}{(}\PYG{l+m+mf}{0.01}\PYG{p}{)}

\PYG{c+c1}{\PYGZsh{} Let\PYGZsq{}s see what we made}
\PYG{n}{state}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[32]:\,\hspace{\fboxrule}\hspace{\fboxsep}}State(\{'dt': const(0.01),
 'uinitial\_0\_0': const(0),
 'uinitial\_0\_1': const(0),
 'uinitial\_0\_2': const(0),
 'uinitial\_0\_3': const(0),
 'uinitial\_0\_4': const(0),
 'uinitial\_0\_5': const(0),
 'uinitial\_0\_6': const(0),
 'uinitial\_0\_7': const(0),
 'uinitial\_0\_8': const(0),
 'uinitial\_0\_9': const(0),
 'uinitial\_1\_0': const(0),
 'uinitial\_1\_1': const(0),
 'uinitial\_1\_2': const(0),
 'uinitial\_1\_3': const(0),
 'uinitial\_1\_4': const(0),
 'uinitial\_1\_5': const(0),
 'uinitial\_1\_6': const(0),
 'uinitial\_1\_7': const(0),
 'uinitial\_1\_8': const(0),
 'uinitial\_1\_9': const(0),
 'uinitial\_2\_0': const(0),
 'uinitial\_2\_1': const(0),
 'uinitial\_2\_2': const(0),
 'uinitial\_2\_3': const(0),
 'uinitial\_2\_4': const(0),
 'uinitial\_2\_5': const(0),
 'uinitial\_2\_6': const(0),
 'uinitial\_2\_7': const(0),
 'uinitial\_2\_8': const(0),
 'uinitial\_2\_9': const(0),
 'uinitial\_3\_0': const(0),
 'uinitial\_3\_1': const(0),
 'uinitial\_3\_2': const(0),
 'uinitial\_3\_3': const(0),
 'uinitial\_3\_4': const(0),
 'uinitial\_3\_5': const(0),
 'uinitial\_3\_6': const(0),
 'uinitial\_3\_7': const(0),
 'uinitial\_3\_8': const(0),
 'uinitial\_3\_9': const(0),
 'uinitial\_4\_0': const(0),
 'uinitial\_4\_1': const(0),
 'uinitial\_4\_2': const(0),
 'uinitial\_4\_3': const(0),
 'uinitial\_4\_4': const(0),
 'uinitial\_4\_5': const(0),
 'uinitial\_4\_6': const(0),
 'uinitial\_4\_7': const(0),
 'uinitial\_4\_8': const(0),
 'uinitial\_4\_9': const(0),
 'uinitial\_5\_0': const(0),
 'uinitial\_5\_1': const(0),
 'uinitial\_5\_2': const(0),
 'uinitial\_5\_3': const(0),
 'uinitial\_5\_4': const(0),
 'uinitial\_5\_5': const(1),
 'uinitial\_5\_6': const(0),
 'uinitial\_5\_7': const(0),
 'uinitial\_5\_8': const(0),
 'uinitial\_5\_9': const(0),
 'uinitial\_6\_0': const(0),
 'uinitial\_6\_1': const(0),
 'uinitial\_6\_2': const(0),
 'uinitial\_6\_3': const(0),
 'uinitial\_6\_4': const(0),
 'uinitial\_6\_5': const(0),
 'uinitial\_6\_6': const(0),
 'uinitial\_6\_7': const(0),
 'uinitial\_6\_8': const(0),
 'uinitial\_6\_9': const(0),
 'uinitial\_7\_0': const(0),
 'uinitial\_7\_1': const(0),
 'uinitial\_7\_2': const(0),
 'uinitial\_7\_3': const(0),
 'uinitial\_7\_4': const(0),
 'uinitial\_7\_5': const(0),
 'uinitial\_7\_6': const(0),
 'uinitial\_7\_7': const(0),
 'uinitial\_7\_8': const(0),
 'uinitial\_7\_9': const(0),
 'uinitial\_8\_0': const(0),
 'uinitial\_8\_1': const(0),
 'uinitial\_8\_2': const(0),
 'uinitial\_8\_3': const(0),
 'uinitial\_8\_4': const(0),
 'uinitial\_8\_5': const(0),
 'uinitial\_8\_6': const(0),
 'uinitial\_8\_7': const(0),
 'uinitial\_8\_8': const(0),
 'uinitial\_8\_9': const(0),
 'uinitial\_9\_0': const(0),
 'uinitial\_9\_1': const(0),
 'uinitial\_9\_2': const(0),
 'uinitial\_9\_3': const(0),
 'uinitial\_9\_4': const(0),
 'uinitial\_9\_5': const(0),
 'uinitial\_9\_6': const(0),
 'uinitial\_9\_7': const(0),
 'uinitial\_9\_8': const(0),
 'uinitial\_9\_9': const(0)\})
\end{sphinxVerbatim}
}

The Laplace operator is discretized as the following:
\begin{equation*}
\begin{split}\dot u_{i,j} = \alpha ( u_{i-1,j} + u_{i+1,j} + u_{i,j-1} + u_{i,j+1} - 4 u_{i,j} )\end{split}
\end{equation*}
{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[34]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{j} \PYG{o+ow}{in} \PYG{n}{ndindex}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)}\PYG{p}{:}
    \PYG{c+c1}{\PYGZsh{} compute i\PYGZhy{}1 and i+1 with proper boundary conditions:}
    \PYG{n}{im1} \PYG{o}{=} \PYG{n}{i}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1} \PYG{k}{if} \PYG{n}{i}\PYG{o}{\PYGZgt{}}\PYG{l+m+mi}{0} \PYG{k}{else} \PYG{n}{N}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}
    \PYG{n}{ip1} \PYG{o}{=} \PYG{n}{i}\PYG{o}{+}\PYG{l+m+mi}{1} \PYG{k}{if} \PYG{n}{i}\PYG{o}{!=}\PYG{n}{N}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1} \PYG{k}{else} \PYG{l+m+mi}{0}

    \PYG{c+c1}{\PYGZsh{} compute j\PYGZhy{}1 and j+1 with proper boundary conditions:}
    \PYG{n}{jm1} \PYG{o}{=} \PYG{n}{j}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1} \PYG{k}{if} \PYG{n}{j}\PYG{o}{\PYGZgt{}}\PYG{l+m+mi}{0} \PYG{k}{else} \PYG{n}{N}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}
    \PYG{n}{jp1} \PYG{o}{=} \PYG{n}{j}\PYG{o}{+}\PYG{l+m+mi}{1} \PYG{k}{if} \PYG{n}{j}\PYG{o}{!=}\PYG{n}{N}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1} \PYG{k}{else} \PYG{l+m+mi}{0}

    \PYG{n}{helper} \PYG{o}{=} \PYG{n}{Symbol}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u\PYGZus{}intermediate\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{j}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
    \PYG{n}{state}\PYG{p}{[}\PYG{n}{helper}\PYG{p}{]} \PYG{o}{=} \PYG{n}{neg}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{n}{u}\PYG{p}{[}\PYG{n}{i}\PYG{p}{,}\PYG{n}{j}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
    \PYG{n}{state}\PYG{p}{[} \PYG{n}{u}\PYG{p}{[}\PYG{n}{i}\PYG{p}{,}\PYG{n}{j}\PYG{p}{]} \PYG{p}{]} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{mult}\PYG{p}{(}\PYG{n}{alpha}\PYG{p}{,}\PYG{n+nb}{sum}\PYG{p}{(}
        \PYG{n}{u}\PYG{p}{[}\PYG{n}{im1}\PYG{p}{,}\PYG{n}{j}\PYG{p}{]}\PYG{p}{,} \PYG{n}{u}\PYG{p}{[}\PYG{n}{ip1}\PYG{p}{,}\PYG{n}{j}\PYG{p}{]}\PYG{p}{,}
        \PYG{n}{u}\PYG{p}{[}\PYG{n}{i}\PYG{p}{,}\PYG{n}{jm1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{u}\PYG{p}{[}\PYG{n}{i}\PYG{p}{,}\PYG{n}{jp1}\PYG{p}{]}\PYG{p}{,}
        \PYG{n}{helper}\PYG{p}{)}\PYG{p}{)}\PYG{p}{,} \PYG{n}{dt}\PYG{p}{,} \PYG{n}{u0}\PYG{p}{[}\PYG{n}{i}\PYG{p}{,}\PYG{n}{j}\PYG{p}{]}\PYG{p}{)}

\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{state}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[34]:\,\hspace{\fboxrule}\hspace{\fboxsep}}301
\end{sphinxVerbatim}
}

The state is already enormous. Realizing this circuit requires more then 300 wires or computing elements, respectively:

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[35]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{state}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[35]:\,\hspace{\fboxrule}\hspace{\fboxsep}}State(\{'dt': const(0.01),
 'u\_0\_0': int(mult(const(4), sum(u\_9\_0, u\_1\_0, u\_0\_9, u\_0\_1, u\_intermediate\_0\_0)), dt, uinitial\_0\_0),
 'u\_0\_1': int(mult(const(4), sum(u\_9\_1, u\_1\_1, u\_0\_0, u\_0\_2, u\_intermediate\_0\_1)), dt, uinitial\_0\_1),
 'u\_0\_2': int(mult(const(4), sum(u\_9\_2, u\_1\_2, u\_0\_1, u\_0\_3, u\_intermediate\_0\_2)), dt, uinitial\_0\_2),
 'u\_0\_3': int(mult(const(4), sum(u\_9\_3, u\_1\_3, u\_0\_2, u\_0\_4, u\_intermediate\_0\_3)), dt, uinitial\_0\_3),
 'u\_0\_4': int(mult(const(4), sum(u\_9\_4, u\_1\_4, u\_0\_3, u\_0\_5, u\_intermediate\_0\_4)), dt, uinitial\_0\_4),
 'u\_0\_5': int(mult(const(4), sum(u\_9\_5, u\_1\_5, u\_0\_4, u\_0\_6, u\_intermediate\_0\_5)), dt, uinitial\_0\_5),
 'u\_0\_6': int(mult(const(4), sum(u\_9\_6, u\_1\_6, u\_0\_5, u\_0\_7, u\_intermediate\_0\_6)), dt, uinitial\_0\_6),
 'u\_0\_7': int(mult(const(4), sum(u\_9\_7, u\_1\_7, u\_0\_6, u\_0\_8, u\_intermediate\_0\_7)), dt, uinitial\_0\_7),
 'u\_0\_8': int(mult(const(4), sum(u\_9\_8, u\_1\_8, u\_0\_7, u\_0\_9, u\_intermediate\_0\_8)), dt, uinitial\_0\_8),
 'u\_0\_9': int(mult(const(4), sum(u\_9\_9, u\_1\_9, u\_0\_8, u\_0\_0, u\_intermediate\_0\_9)), dt, uinitial\_0\_9),
 'u\_1\_0': int(mult(const(4), sum(u\_0\_0, u\_2\_0, u\_1\_9, u\_1\_1, u\_intermediate\_1\_0)), dt, uinitial\_1\_0),
 'u\_1\_1': int(mult(const(4), sum(u\_0\_1, u\_2\_1, u\_1\_0, u\_1\_2, u\_intermediate\_1\_1)), dt, uinitial\_1\_1),
 'u\_1\_2': int(mult(const(4), sum(u\_0\_2, u\_2\_2, u\_1\_1, u\_1\_3, u\_intermediate\_1\_2)), dt, uinitial\_1\_2),
 'u\_1\_3': int(mult(const(4), sum(u\_0\_3, u\_2\_3, u\_1\_2, u\_1\_4, u\_intermediate\_1\_3)), dt, uinitial\_1\_3),
 'u\_1\_4': int(mult(const(4), sum(u\_0\_4, u\_2\_4, u\_1\_3, u\_1\_5, u\_intermediate\_1\_4)), dt, uinitial\_1\_4),
 'u\_1\_5': int(mult(const(4), sum(u\_0\_5, u\_2\_5, u\_1\_4, u\_1\_6, u\_intermediate\_1\_5)), dt, uinitial\_1\_5),
 'u\_1\_6': int(mult(const(4), sum(u\_0\_6, u\_2\_6, u\_1\_5, u\_1\_7, u\_intermediate\_1\_6)), dt, uinitial\_1\_6),
 'u\_1\_7': int(mult(const(4), sum(u\_0\_7, u\_2\_7, u\_1\_6, u\_1\_8, u\_intermediate\_1\_7)), dt, uinitial\_1\_7),
 'u\_1\_8': int(mult(const(4), sum(u\_0\_8, u\_2\_8, u\_1\_7, u\_1\_9, u\_intermediate\_1\_8)), dt, uinitial\_1\_8),
 'u\_1\_9': int(mult(const(4), sum(u\_0\_9, u\_2\_9, u\_1\_8, u\_1\_0, u\_intermediate\_1\_9)), dt, uinitial\_1\_9),
 'u\_2\_0': int(mult(const(4), sum(u\_1\_0, u\_3\_0, u\_2\_9, u\_2\_1, u\_intermediate\_2\_0)), dt, uinitial\_2\_0),
 'u\_2\_1': int(mult(const(4), sum(u\_1\_1, u\_3\_1, u\_2\_0, u\_2\_2, u\_intermediate\_2\_1)), dt, uinitial\_2\_1),
 'u\_2\_2': int(mult(const(4), sum(u\_1\_2, u\_3\_2, u\_2\_1, u\_2\_3, u\_intermediate\_2\_2)), dt, uinitial\_2\_2),
 'u\_2\_3': int(mult(const(4), sum(u\_1\_3, u\_3\_3, u\_2\_2, u\_2\_4, u\_intermediate\_2\_3)), dt, uinitial\_2\_3),
 'u\_2\_4': int(mult(const(4), sum(u\_1\_4, u\_3\_4, u\_2\_3, u\_2\_5, u\_intermediate\_2\_4)), dt, uinitial\_2\_4),
 'u\_2\_5': int(mult(const(4), sum(u\_1\_5, u\_3\_5, u\_2\_4, u\_2\_6, u\_intermediate\_2\_5)), dt, uinitial\_2\_5),
 'u\_2\_6': int(mult(const(4), sum(u\_1\_6, u\_3\_6, u\_2\_5, u\_2\_7, u\_intermediate\_2\_6)), dt, uinitial\_2\_6),
 'u\_2\_7': int(mult(const(4), sum(u\_1\_7, u\_3\_7, u\_2\_6, u\_2\_8, u\_intermediate\_2\_7)), dt, uinitial\_2\_7),
 'u\_2\_8': int(mult(const(4), sum(u\_1\_8, u\_3\_8, u\_2\_7, u\_2\_9, u\_intermediate\_2\_8)), dt, uinitial\_2\_8),
 'u\_2\_9': int(mult(const(4), sum(u\_1\_9, u\_3\_9, u\_2\_8, u\_2\_0, u\_intermediate\_2\_9)), dt, uinitial\_2\_9),
 'u\_3\_0': int(mult(const(4), sum(u\_2\_0, u\_4\_0, u\_3\_9, u\_3\_1, u\_intermediate\_3\_0)), dt, uinitial\_3\_0),
 'u\_3\_1': int(mult(const(4), sum(u\_2\_1, u\_4\_1, u\_3\_0, u\_3\_2, u\_intermediate\_3\_1)), dt, uinitial\_3\_1),
 'u\_3\_2': int(mult(const(4), sum(u\_2\_2, u\_4\_2, u\_3\_1, u\_3\_3, u\_intermediate\_3\_2)), dt, uinitial\_3\_2),
 'u\_3\_3': int(mult(const(4), sum(u\_2\_3, u\_4\_3, u\_3\_2, u\_3\_4, u\_intermediate\_3\_3)), dt, uinitial\_3\_3),
 'u\_3\_4': int(mult(const(4), sum(u\_2\_4, u\_4\_4, u\_3\_3, u\_3\_5, u\_intermediate\_3\_4)), dt, uinitial\_3\_4),
 'u\_3\_5': int(mult(const(4), sum(u\_2\_5, u\_4\_5, u\_3\_4, u\_3\_6, u\_intermediate\_3\_5)), dt, uinitial\_3\_5),
 'u\_3\_6': int(mult(const(4), sum(u\_2\_6, u\_4\_6, u\_3\_5, u\_3\_7, u\_intermediate\_3\_6)), dt, uinitial\_3\_6),
 'u\_3\_7': int(mult(const(4), sum(u\_2\_7, u\_4\_7, u\_3\_6, u\_3\_8, u\_intermediate\_3\_7)), dt, uinitial\_3\_7),
 'u\_3\_8': int(mult(const(4), sum(u\_2\_8, u\_4\_8, u\_3\_7, u\_3\_9, u\_intermediate\_3\_8)), dt, uinitial\_3\_8),
 'u\_3\_9': int(mult(const(4), sum(u\_2\_9, u\_4\_9, u\_3\_8, u\_3\_0, u\_intermediate\_3\_9)), dt, uinitial\_3\_9),
 'u\_4\_0': int(mult(const(4), sum(u\_3\_0, u\_5\_0, u\_4\_9, u\_4\_1, u\_intermediate\_4\_0)), dt, uinitial\_4\_0),
 'u\_4\_1': int(mult(const(4), sum(u\_3\_1, u\_5\_1, u\_4\_0, u\_4\_2, u\_intermediate\_4\_1)), dt, uinitial\_4\_1),
 'u\_4\_2': int(mult(const(4), sum(u\_3\_2, u\_5\_2, u\_4\_1, u\_4\_3, u\_intermediate\_4\_2)), dt, uinitial\_4\_2),
 'u\_4\_3': int(mult(const(4), sum(u\_3\_3, u\_5\_3, u\_4\_2, u\_4\_4, u\_intermediate\_4\_3)), dt, uinitial\_4\_3),
 'u\_4\_4': int(mult(const(4), sum(u\_3\_4, u\_5\_4, u\_4\_3, u\_4\_5, u\_intermediate\_4\_4)), dt, uinitial\_4\_4),
 'u\_4\_5': int(mult(const(4), sum(u\_3\_5, u\_5\_5, u\_4\_4, u\_4\_6, u\_intermediate\_4\_5)), dt, uinitial\_4\_5),
 'u\_4\_6': int(mult(const(4), sum(u\_3\_6, u\_5\_6, u\_4\_5, u\_4\_7, u\_intermediate\_4\_6)), dt, uinitial\_4\_6),
 'u\_4\_7': int(mult(const(4), sum(u\_3\_7, u\_5\_7, u\_4\_6, u\_4\_8, u\_intermediate\_4\_7)), dt, uinitial\_4\_7),
 'u\_4\_8': int(mult(const(4), sum(u\_3\_8, u\_5\_8, u\_4\_7, u\_4\_9, u\_intermediate\_4\_8)), dt, uinitial\_4\_8),
 'u\_4\_9': int(mult(const(4), sum(u\_3\_9, u\_5\_9, u\_4\_8, u\_4\_0, u\_intermediate\_4\_9)), dt, uinitial\_4\_9),
 'u\_5\_0': int(mult(const(4), sum(u\_4\_0, u\_6\_0, u\_5\_9, u\_5\_1, u\_intermediate\_5\_0)), dt, uinitial\_5\_0),
 'u\_5\_1': int(mult(const(4), sum(u\_4\_1, u\_6\_1, u\_5\_0, u\_5\_2, u\_intermediate\_5\_1)), dt, uinitial\_5\_1),
 'u\_5\_2': int(mult(const(4), sum(u\_4\_2, u\_6\_2, u\_5\_1, u\_5\_3, u\_intermediate\_5\_2)), dt, uinitial\_5\_2),
 'u\_5\_3': int(mult(const(4), sum(u\_4\_3, u\_6\_3, u\_5\_2, u\_5\_4, u\_intermediate\_5\_3)), dt, uinitial\_5\_3),
 'u\_5\_4': int(mult(const(4), sum(u\_4\_4, u\_6\_4, u\_5\_3, u\_5\_5, u\_intermediate\_5\_4)), dt, uinitial\_5\_4),
 'u\_5\_5': int(mult(const(4), sum(u\_4\_5, u\_6\_5, u\_5\_4, u\_5\_6, u\_intermediate\_5\_5)), dt, uinitial\_5\_5),
 'u\_5\_6': int(mult(const(4), sum(u\_4\_6, u\_6\_6, u\_5\_5, u\_5\_7, u\_intermediate\_5\_6)), dt, uinitial\_5\_6),
 'u\_5\_7': int(mult(const(4), sum(u\_4\_7, u\_6\_7, u\_5\_6, u\_5\_8, u\_intermediate\_5\_7)), dt, uinitial\_5\_7),
 'u\_5\_8': int(mult(const(4), sum(u\_4\_8, u\_6\_8, u\_5\_7, u\_5\_9, u\_intermediate\_5\_8)), dt, uinitial\_5\_8),
 'u\_5\_9': int(mult(const(4), sum(u\_4\_9, u\_6\_9, u\_5\_8, u\_5\_0, u\_intermediate\_5\_9)), dt, uinitial\_5\_9),
 'u\_6\_0': int(mult(const(4), sum(u\_5\_0, u\_7\_0, u\_6\_9, u\_6\_1, u\_intermediate\_6\_0)), dt, uinitial\_6\_0),
 'u\_6\_1': int(mult(const(4), sum(u\_5\_1, u\_7\_1, u\_6\_0, u\_6\_2, u\_intermediate\_6\_1)), dt, uinitial\_6\_1),
 'u\_6\_2': int(mult(const(4), sum(u\_5\_2, u\_7\_2, u\_6\_1, u\_6\_3, u\_intermediate\_6\_2)), dt, uinitial\_6\_2),
 'u\_6\_3': int(mult(const(4), sum(u\_5\_3, u\_7\_3, u\_6\_2, u\_6\_4, u\_intermediate\_6\_3)), dt, uinitial\_6\_3),
 'u\_6\_4': int(mult(const(4), sum(u\_5\_4, u\_7\_4, u\_6\_3, u\_6\_5, u\_intermediate\_6\_4)), dt, uinitial\_6\_4),
 'u\_6\_5': int(mult(const(4), sum(u\_5\_5, u\_7\_5, u\_6\_4, u\_6\_6, u\_intermediate\_6\_5)), dt, uinitial\_6\_5),
 'u\_6\_6': int(mult(const(4), sum(u\_5\_6, u\_7\_6, u\_6\_5, u\_6\_7, u\_intermediate\_6\_6)), dt, uinitial\_6\_6),
 'u\_6\_7': int(mult(const(4), sum(u\_5\_7, u\_7\_7, u\_6\_6, u\_6\_8, u\_intermediate\_6\_7)), dt, uinitial\_6\_7),
 'u\_6\_8': int(mult(const(4), sum(u\_5\_8, u\_7\_8, u\_6\_7, u\_6\_9, u\_intermediate\_6\_8)), dt, uinitial\_6\_8),
 'u\_6\_9': int(mult(const(4), sum(u\_5\_9, u\_7\_9, u\_6\_8, u\_6\_0, u\_intermediate\_6\_9)), dt, uinitial\_6\_9),
 'u\_7\_0': int(mult(const(4), sum(u\_6\_0, u\_8\_0, u\_7\_9, u\_7\_1, u\_intermediate\_7\_0)), dt, uinitial\_7\_0),
 'u\_7\_1': int(mult(const(4), sum(u\_6\_1, u\_8\_1, u\_7\_0, u\_7\_2, u\_intermediate\_7\_1)), dt, uinitial\_7\_1),
 'u\_7\_2': int(mult(const(4), sum(u\_6\_2, u\_8\_2, u\_7\_1, u\_7\_3, u\_intermediate\_7\_2)), dt, uinitial\_7\_2),
 'u\_7\_3': int(mult(const(4), sum(u\_6\_3, u\_8\_3, u\_7\_2, u\_7\_4, u\_intermediate\_7\_3)), dt, uinitial\_7\_3),
 'u\_7\_4': int(mult(const(4), sum(u\_6\_4, u\_8\_4, u\_7\_3, u\_7\_5, u\_intermediate\_7\_4)), dt, uinitial\_7\_4),
 'u\_7\_5': int(mult(const(4), sum(u\_6\_5, u\_8\_5, u\_7\_4, u\_7\_6, u\_intermediate\_7\_5)), dt, uinitial\_7\_5),
 'u\_7\_6': int(mult(const(4), sum(u\_6\_6, u\_8\_6, u\_7\_5, u\_7\_7, u\_intermediate\_7\_6)), dt, uinitial\_7\_6),
 'u\_7\_7': int(mult(const(4), sum(u\_6\_7, u\_8\_7, u\_7\_6, u\_7\_8, u\_intermediate\_7\_7)), dt, uinitial\_7\_7),
 'u\_7\_8': int(mult(const(4), sum(u\_6\_8, u\_8\_8, u\_7\_7, u\_7\_9, u\_intermediate\_7\_8)), dt, uinitial\_7\_8),
 'u\_7\_9': int(mult(const(4), sum(u\_6\_9, u\_8\_9, u\_7\_8, u\_7\_0, u\_intermediate\_7\_9)), dt, uinitial\_7\_9),
 'u\_8\_0': int(mult(const(4), sum(u\_7\_0, u\_9\_0, u\_8\_9, u\_8\_1, u\_intermediate\_8\_0)), dt, uinitial\_8\_0),
 'u\_8\_1': int(mult(const(4), sum(u\_7\_1, u\_9\_1, u\_8\_0, u\_8\_2, u\_intermediate\_8\_1)), dt, uinitial\_8\_1),
 'u\_8\_2': int(mult(const(4), sum(u\_7\_2, u\_9\_2, u\_8\_1, u\_8\_3, u\_intermediate\_8\_2)), dt, uinitial\_8\_2),
 'u\_8\_3': int(mult(const(4), sum(u\_7\_3, u\_9\_3, u\_8\_2, u\_8\_4, u\_intermediate\_8\_3)), dt, uinitial\_8\_3),
 'u\_8\_4': int(mult(const(4), sum(u\_7\_4, u\_9\_4, u\_8\_3, u\_8\_5, u\_intermediate\_8\_4)), dt, uinitial\_8\_4),
 'u\_8\_5': int(mult(const(4), sum(u\_7\_5, u\_9\_5, u\_8\_4, u\_8\_6, u\_intermediate\_8\_5)), dt, uinitial\_8\_5),
 'u\_8\_6': int(mult(const(4), sum(u\_7\_6, u\_9\_6, u\_8\_5, u\_8\_7, u\_intermediate\_8\_6)), dt, uinitial\_8\_6),
 'u\_8\_7': int(mult(const(4), sum(u\_7\_7, u\_9\_7, u\_8\_6, u\_8\_8, u\_intermediate\_8\_7)), dt, uinitial\_8\_7),
 'u\_8\_8': int(mult(const(4), sum(u\_7\_8, u\_9\_8, u\_8\_7, u\_8\_9, u\_intermediate\_8\_8)), dt, uinitial\_8\_8),
 'u\_8\_9': int(mult(const(4), sum(u\_7\_9, u\_9\_9, u\_8\_8, u\_8\_0, u\_intermediate\_8\_9)), dt, uinitial\_8\_9),
 'u\_9\_0': int(mult(const(4), sum(u\_8\_0, u\_0\_0, u\_9\_9, u\_9\_1, u\_intermediate\_9\_0)), dt, uinitial\_9\_0),
 'u\_9\_1': int(mult(const(4), sum(u\_8\_1, u\_0\_1, u\_9\_0, u\_9\_2, u\_intermediate\_9\_1)), dt, uinitial\_9\_1),
 'u\_9\_2': int(mult(const(4), sum(u\_8\_2, u\_0\_2, u\_9\_1, u\_9\_3, u\_intermediate\_9\_2)), dt, uinitial\_9\_2),
 'u\_9\_3': int(mult(const(4), sum(u\_8\_3, u\_0\_3, u\_9\_2, u\_9\_4, u\_intermediate\_9\_3)), dt, uinitial\_9\_3),
 'u\_9\_4': int(mult(const(4), sum(u\_8\_4, u\_0\_4, u\_9\_3, u\_9\_5, u\_intermediate\_9\_4)), dt, uinitial\_9\_4),
 'u\_9\_5': int(mult(const(4), sum(u\_8\_5, u\_0\_5, u\_9\_4, u\_9\_6, u\_intermediate\_9\_5)), dt, uinitial\_9\_5),
 'u\_9\_6': int(mult(const(4), sum(u\_8\_6, u\_0\_6, u\_9\_5, u\_9\_7, u\_intermediate\_9\_6)), dt, uinitial\_9\_6),
 'u\_9\_7': int(mult(const(4), sum(u\_8\_7, u\_0\_7, u\_9\_6, u\_9\_8, u\_intermediate\_9\_7)), dt, uinitial\_9\_7),
 'u\_9\_8': int(mult(const(4), sum(u\_8\_8, u\_0\_8, u\_9\_7, u\_9\_9, u\_intermediate\_9\_8)), dt, uinitial\_9\_8),
 'u\_9\_9': int(mult(const(4), sum(u\_8\_9, u\_0\_9, u\_9\_8, u\_9\_0, u\_intermediate\_9\_9)), dt, uinitial\_9\_9),
 'u\_intermediate\_0\_0': neg(mult(4, u\_0\_0)),
 'u\_intermediate\_0\_1': neg(mult(4, u\_0\_1)),
 'u\_intermediate\_0\_2': neg(mult(4, u\_0\_2)),
 'u\_intermediate\_0\_3': neg(mult(4, u\_0\_3)),
 'u\_intermediate\_0\_4': neg(mult(4, u\_0\_4)),
 'u\_intermediate\_0\_5': neg(mult(4, u\_0\_5)),
 'u\_intermediate\_0\_6': neg(mult(4, u\_0\_6)),
 'u\_intermediate\_0\_7': neg(mult(4, u\_0\_7)),
 'u\_intermediate\_0\_8': neg(mult(4, u\_0\_8)),
 'u\_intermediate\_0\_9': neg(mult(4, u\_0\_9)),
 'u\_intermediate\_1\_0': neg(mult(4, u\_1\_0)),
 'u\_intermediate\_1\_1': neg(mult(4, u\_1\_1)),
 'u\_intermediate\_1\_2': neg(mult(4, u\_1\_2)),
 'u\_intermediate\_1\_3': neg(mult(4, u\_1\_3)),
 'u\_intermediate\_1\_4': neg(mult(4, u\_1\_4)),
 'u\_intermediate\_1\_5': neg(mult(4, u\_1\_5)),
 'u\_intermediate\_1\_6': neg(mult(4, u\_1\_6)),
 'u\_intermediate\_1\_7': neg(mult(4, u\_1\_7)),
 'u\_intermediate\_1\_8': neg(mult(4, u\_1\_8)),
 'u\_intermediate\_1\_9': neg(mult(4, u\_1\_9)),
 'u\_intermediate\_2\_0': neg(mult(4, u\_2\_0)),
 'u\_intermediate\_2\_1': neg(mult(4, u\_2\_1)),
 'u\_intermediate\_2\_2': neg(mult(4, u\_2\_2)),
 'u\_intermediate\_2\_3': neg(mult(4, u\_2\_3)),
 'u\_intermediate\_2\_4': neg(mult(4, u\_2\_4)),
 'u\_intermediate\_2\_5': neg(mult(4, u\_2\_5)),
 'u\_intermediate\_2\_6': neg(mult(4, u\_2\_6)),
 'u\_intermediate\_2\_7': neg(mult(4, u\_2\_7)),
 'u\_intermediate\_2\_8': neg(mult(4, u\_2\_8)),
 'u\_intermediate\_2\_9': neg(mult(4, u\_2\_9)),
 'u\_intermediate\_3\_0': neg(mult(4, u\_3\_0)),
 'u\_intermediate\_3\_1': neg(mult(4, u\_3\_1)),
 'u\_intermediate\_3\_2': neg(mult(4, u\_3\_2)),
 'u\_intermediate\_3\_3': neg(mult(4, u\_3\_3)),
 'u\_intermediate\_3\_4': neg(mult(4, u\_3\_4)),
 'u\_intermediate\_3\_5': neg(mult(4, u\_3\_5)),
 'u\_intermediate\_3\_6': neg(mult(4, u\_3\_6)),
 'u\_intermediate\_3\_7': neg(mult(4, u\_3\_7)),
 'u\_intermediate\_3\_8': neg(mult(4, u\_3\_8)),
 'u\_intermediate\_3\_9': neg(mult(4, u\_3\_9)),
 'u\_intermediate\_4\_0': neg(mult(4, u\_4\_0)),
 'u\_intermediate\_4\_1': neg(mult(4, u\_4\_1)),
 'u\_intermediate\_4\_2': neg(mult(4, u\_4\_2)),
 'u\_intermediate\_4\_3': neg(mult(4, u\_4\_3)),
 'u\_intermediate\_4\_4': neg(mult(4, u\_4\_4)),
 'u\_intermediate\_4\_5': neg(mult(4, u\_4\_5)),
 'u\_intermediate\_4\_6': neg(mult(4, u\_4\_6)),
 'u\_intermediate\_4\_7': neg(mult(4, u\_4\_7)),
 'u\_intermediate\_4\_8': neg(mult(4, u\_4\_8)),
 'u\_intermediate\_4\_9': neg(mult(4, u\_4\_9)),
 'u\_intermediate\_5\_0': neg(mult(4, u\_5\_0)),
 'u\_intermediate\_5\_1': neg(mult(4, u\_5\_1)),
 'u\_intermediate\_5\_2': neg(mult(4, u\_5\_2)),
 'u\_intermediate\_5\_3': neg(mult(4, u\_5\_3)),
 'u\_intermediate\_5\_4': neg(mult(4, u\_5\_4)),
 'u\_intermediate\_5\_5': neg(mult(4, u\_5\_5)),
 'u\_intermediate\_5\_6': neg(mult(4, u\_5\_6)),
 'u\_intermediate\_5\_7': neg(mult(4, u\_5\_7)),
 'u\_intermediate\_5\_8': neg(mult(4, u\_5\_8)),
 'u\_intermediate\_5\_9': neg(mult(4, u\_5\_9)),
 'u\_intermediate\_6\_0': neg(mult(4, u\_6\_0)),
 'u\_intermediate\_6\_1': neg(mult(4, u\_6\_1)),
 'u\_intermediate\_6\_2': neg(mult(4, u\_6\_2)),
 'u\_intermediate\_6\_3': neg(mult(4, u\_6\_3)),
 'u\_intermediate\_6\_4': neg(mult(4, u\_6\_4)),
 'u\_intermediate\_6\_5': neg(mult(4, u\_6\_5)),
 'u\_intermediate\_6\_6': neg(mult(4, u\_6\_6)),
 'u\_intermediate\_6\_7': neg(mult(4, u\_6\_7)),
 'u\_intermediate\_6\_8': neg(mult(4, u\_6\_8)),
 'u\_intermediate\_6\_9': neg(mult(4, u\_6\_9)),
 'u\_intermediate\_7\_0': neg(mult(4, u\_7\_0)),
 'u\_intermediate\_7\_1': neg(mult(4, u\_7\_1)),
 'u\_intermediate\_7\_2': neg(mult(4, u\_7\_2)),
 'u\_intermediate\_7\_3': neg(mult(4, u\_7\_3)),
 'u\_intermediate\_7\_4': neg(mult(4, u\_7\_4)),
 'u\_intermediate\_7\_5': neg(mult(4, u\_7\_5)),
 'u\_intermediate\_7\_6': neg(mult(4, u\_7\_6)),
 'u\_intermediate\_7\_7': neg(mult(4, u\_7\_7)),
 'u\_intermediate\_7\_8': neg(mult(4, u\_7\_8)),
 'u\_intermediate\_7\_9': neg(mult(4, u\_7\_9)),
 'u\_intermediate\_8\_0': neg(mult(4, u\_8\_0)),
 'u\_intermediate\_8\_1': neg(mult(4, u\_8\_1)),
 'u\_intermediate\_8\_2': neg(mult(4, u\_8\_2)),
 'u\_intermediate\_8\_3': neg(mult(4, u\_8\_3)),
 'u\_intermediate\_8\_4': neg(mult(4, u\_8\_4)),
 'u\_intermediate\_8\_5': neg(mult(4, u\_8\_5)),
 'u\_intermediate\_8\_6': neg(mult(4, u\_8\_6)),
 'u\_intermediate\_8\_7': neg(mult(4, u\_8\_7)),
 'u\_intermediate\_8\_8': neg(mult(4, u\_8\_8)),
 'u\_intermediate\_8\_9': neg(mult(4, u\_8\_9)),
 'u\_intermediate\_9\_0': neg(mult(4, u\_9\_0)),
 'u\_intermediate\_9\_1': neg(mult(4, u\_9\_1)),
 'u\_intermediate\_9\_2': neg(mult(4, u\_9\_2)),
 'u\_intermediate\_9\_3': neg(mult(4, u\_9\_3)),
 'u\_intermediate\_9\_4': neg(mult(4, u\_9\_4)),
 'u\_intermediate\_9\_5': neg(mult(4, u\_9\_5)),
 'u\_intermediate\_9\_6': neg(mult(4, u\_9\_6)),
 'u\_intermediate\_9\_7': neg(mult(4, u\_9\_7)),
 'u\_intermediate\_9\_8': neg(mult(4, u\_9\_8)),
 'u\_intermediate\_9\_9': neg(mult(4, u\_9\_9)),
 'uinitial\_0\_0': const(0),
 'uinitial\_0\_1': const(0),
 'uinitial\_0\_2': const(0),
 'uinitial\_0\_3': const(0),
 'uinitial\_0\_4': const(0),
 'uinitial\_0\_5': const(0),
 'uinitial\_0\_6': const(0),
 'uinitial\_0\_7': const(0),
 'uinitial\_0\_8': const(0),
 'uinitial\_0\_9': const(0),
 'uinitial\_1\_0': const(0),
 'uinitial\_1\_1': const(0),
 'uinitial\_1\_2': const(0),
 'uinitial\_1\_3': const(0),
 'uinitial\_1\_4': const(0),
 'uinitial\_1\_5': const(0),
 'uinitial\_1\_6': const(0),
 'uinitial\_1\_7': const(0),
 'uinitial\_1\_8': const(0),
 'uinitial\_1\_9': const(0),
 'uinitial\_2\_0': const(0),
 'uinitial\_2\_1': const(0),
 'uinitial\_2\_2': const(0),
 'uinitial\_2\_3': const(0),
 'uinitial\_2\_4': const(0),
 'uinitial\_2\_5': const(0),
 'uinitial\_2\_6': const(0),
 'uinitial\_2\_7': const(0),
 'uinitial\_2\_8': const(0),
 'uinitial\_2\_9': const(0),
 'uinitial\_3\_0': const(0),
 'uinitial\_3\_1': const(0),
 'uinitial\_3\_2': const(0),
 'uinitial\_3\_3': const(0),
 'uinitial\_3\_4': const(0),
 'uinitial\_3\_5': const(0),
 'uinitial\_3\_6': const(0),
 'uinitial\_3\_7': const(0),
 'uinitial\_3\_8': const(0),
 'uinitial\_3\_9': const(0),
 'uinitial\_4\_0': const(0),
 'uinitial\_4\_1': const(0),
 'uinitial\_4\_2': const(0),
 'uinitial\_4\_3': const(0),
 'uinitial\_4\_4': const(0),
 'uinitial\_4\_5': const(0),
 'uinitial\_4\_6': const(0),
 'uinitial\_4\_7': const(0),
 'uinitial\_4\_8': const(0),
 'uinitial\_4\_9': const(0),
 'uinitial\_5\_0': const(0),
 'uinitial\_5\_1': const(0),
 'uinitial\_5\_2': const(0),
 'uinitial\_5\_3': const(0),
 'uinitial\_5\_4': const(0),
 'uinitial\_5\_5': const(1),
 'uinitial\_5\_6': const(0),
 'uinitial\_5\_7': const(0),
 'uinitial\_5\_8': const(0),
 'uinitial\_5\_9': const(0),
 'uinitial\_6\_0': const(0),
 'uinitial\_6\_1': const(0),
 'uinitial\_6\_2': const(0),
 'uinitial\_6\_3': const(0),
 'uinitial\_6\_4': const(0),
 'uinitial\_6\_5': const(0),
 'uinitial\_6\_6': const(0),
 'uinitial\_6\_7': const(0),
 'uinitial\_6\_8': const(0),
 'uinitial\_6\_9': const(0),
 'uinitial\_7\_0': const(0),
 'uinitial\_7\_1': const(0),
 'uinitial\_7\_2': const(0),
 'uinitial\_7\_3': const(0),
 'uinitial\_7\_4': const(0),
 'uinitial\_7\_5': const(0),
 'uinitial\_7\_6': const(0),
 'uinitial\_7\_7': const(0),
 'uinitial\_7\_8': const(0),
 'uinitial\_7\_9': const(0),
 'uinitial\_8\_0': const(0),
 'uinitial\_8\_1': const(0),
 'uinitial\_8\_2': const(0),
 'uinitial\_8\_3': const(0),
 'uinitial\_8\_4': const(0),
 'uinitial\_8\_5': const(0),
 'uinitial\_8\_6': const(0),
 'uinitial\_8\_7': const(0),
 'uinitial\_8\_8': const(0),
 'uinitial\_8\_9': const(0),
 'uinitial\_9\_0': const(0),
 'uinitial\_9\_1': const(0),
 'uinitial\_9\_2': const(0),
 'uinitial\_9\_3': const(0),
 'uinitial\_9\_4': const(0),
 'uinitial\_9\_5': const(0),
 'uinitial\_9\_6': const(0),
 'uinitial\_9\_7': const(0),
 'uinitial\_9\_8': const(0),
 'uinitial\_9\_9': const(0)\})
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[36]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{c\PYGZus{}code} \PYG{o}{=} \PYG{n}{state}\PYG{o}{.}\PYG{n}{export}\PYG{p}{(}\PYG{n}{to}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{C}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{compile}\PYG{p}{(}\PYG{n}{c\PYGZus{}code}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{heateq2d.cpp}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[37]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{data} \PYG{o}{=} \PYG{n}{run}\PYG{p}{(}\PYG{n}{arguments}\PYG{o}{=}\PYG{p}{\PYGZob{}}\PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{max\PYGZus{}iterations}\PYG{l+s+s1}{\PYGZsq{}}\PYG{p}{:}\PYG{l+m+mi}{400}\PYG{p}{\PYGZcb{}}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
Running: ./a.out --max\_iterations=400
\end{sphinxVerbatim}
}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[38]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{j} \PYG{o+ow}{in} \PYG{n}{ndindex}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)}\PYG{p}{:}
    \PYG{n}{plot}\PYG{p}{(}\PYG{n}{data}\PYG{p}{[}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{j}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=2269\sphinxpxdimen,height=1118\sphinxpxdimen]{{examples_Heat-Equation_29_0}.png}

\end{nbsphinxfancyoutput}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[39]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{heat} \PYG{o}{=} \PYG{n}{array}\PYG{p}{(}\PYG{p}{[}\PYG{n}{data}\PYG{p}{[}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{u\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{i}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZus{}}\PYG{l+s+si}{\PYGZob{}}\PYG{n}{j}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{k}{for} \PYG{n}{i}\PYG{p}{,}\PYG{n}{j} \PYG{o+ow}{in} \PYG{n}{ndindex}\PYG{p}{(}\PYG{n}{NN}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}\PYG{o}{.}\PYG{n}{reshape}\PYG{p}{(}\PYG{p}{(}\PYG{n}{N}\PYG{p}{,}\PYG{n}{N}\PYG{p}{,}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{data}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{heat}\PYG{o}{.}\PYG{n}{shape}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[39]:\,\hspace{\fboxrule}\hspace{\fboxsep}}(10, 10, 400)
\end{sphinxVerbatim}
}

The physical recovery of the digital data is not so easy to inspect, since the two spatial dimensions would require to make a movie in order to display the time evolution. What we do instead here is to show the first snapshot and the last one.

In the following two figures, the \sphinxstyleemphasis{x} and \sphinxstyleemphasis{y} axis correspond to their physical coordinates. These are \sphinxstyleemphasis{still images} for \(t=0\) and \(t=t_\text{final}\).

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[22]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{rcParams}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{figure.figsize}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]} \PYG{o}{=} \PYG{p}{(}\PYG{l+m+mi}{40}\PYG{p}{,}\PYG{l+m+mi}{20}\PYG{p}{)}
\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{heat}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,}\PYG{p}{:}\PYG{p}{,}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[22]:\,\hspace{\fboxrule}\hspace{\fboxsep}}<matplotlib.image.AxesImage at 0x7f7fd5956ac0>
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=1114\sphinxpxdimen,height=1118\sphinxpxdimen]{{examples_Heat-Equation_32_1}.png}

\end{nbsphinxfancyoutput}

{
\sphinxsetup{VerbatimColor={named}{nbsphinx-code-bg}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxin}[23]:\,\hspace{\fboxrule}\hspace{\fboxsep}}\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{heat}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,}\PYG{p}{:}\PYG{p}{,}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}
\end{sphinxVerbatim}
}

{

\kern-\sphinxverbatimsmallskipamount\kern-\baselineskip
\kern+\FrameHeightAdjust\kern-\fboxrule
\vspace{\nbsphinxcodecellspacing}

\sphinxsetup{VerbatimColor={named}{white}}
\sphinxsetup{VerbatimBorderColor={named}{nbsphinx-code-border}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\llap{\color{nbsphinxout}[23]:\,\hspace{\fboxrule}\hspace{\fboxsep}}<matplotlib.image.AxesImage at 0x7f7fd59675e0>
\end{sphinxVerbatim}
}

\hrule height -\fboxrule\relax
\vspace{\nbsphinxcodecellspacing}

\makeatletter\setbox\nbsphinxpromptbox\box\voidb@x\makeatother

\begin{nbsphinxfancyoutput}

\noindent\sphinxincludegraphics[width=1114\sphinxpxdimen,height=1118\sphinxpxdimen]{{examples_Heat-Equation_33_1}.png}

\end{nbsphinxfancyoutput}

In order to provide a final discussion, what is visible here is the dissipation of heat from a single maximum to the whole simulation domain.

With this, we end the demonstration notebook about the heat equation in DDA.


\subparagraph{About this notebook}
\label{\detokenize{examples/Heat-Equation:About-this-notebook}}
This notebook was written during a two hour phone call as an interactive demonstration how to do high\sphinxhyphen{}level programming with DDA.

\chapter{PyFPAA}


\section{About FPAA}
\label{\detokenize{fpaa/fpaa:about-fpaa}}\label{\detokenize{fpaa/fpaa:fpaa}}\label{\detokenize{fpaa/fpaa::doc}}
PyFPAA is a work bench to gain experience with hybrid computer programming.
It can be used to create examples for the digital/hybrid extensions of the
Analog Paradigm Model\sphinxhyphen{}1 analog computer (AP/M\sphinxhyphen{}1).

\sphinxtitleref{pyFPAA} is a small Python3 code for compiling
instructions for the AP/M\sphinxhyphen{}1 Hybrid Controller (HC),
especially for the DPT (digital potentiometers),
XBAR (crossbar switch) and the HC itself. The input
is a quite extensive machine description together
with a program (basically an analog circuit), both
written in a minimalistic HDL in YAML representation. See the
\sphinxtitleref{README} file there as well as the \sphinxtitleref{doc} directory
for more details.

See also \sphinxtitleref{examples/fpaa\sphinxhyphen{}circuits} for a number of example
input for the pyFPAA compiler. There also exist basic
test scripts within \sphinxtitleref{tests}.

\phantomsection\label{\detokenize{fpaa/fpaa:module-fpaa}}\index{module@\spxentry{module}!fpaa@\spxentry{fpaa}}\index{fpaa@\spxentry{fpaa}!module@\spxentry{module}}
PyFPAA is a compiler for programmable analog computers (FPAAs). It was written by SvenK in Dec 2019
for quickly approaching a testing infrastructure for the XBAR module for the \sphinxstyleemphasis{Analog Paradigm M\sphinxhyphen{}1}
analog computer.

The script requires a (lengthy) machine description, which encodes the computational parts
available and is quite similar to a machine library in VHDL. That file encodes especially the
hard\sphinxhyphen{}wired vs. configurable parts of the machine.
The actual program is then rather short and describes how the configurable computational parts
are connected with each other. It also specifies constant coefficients which are set with
digital potentiometers or other digital steering parameters.

The output of the code is the analog computer configuration, as required by \sphinxcode{\sphinxupquote{hycon}}. This can
be either
\begin{itemize}
\item {} 
a single line of text, which are mostly hexadecimal encoded
instructions together with command characters, all following the serial console protocol which
the HybridController of the machine expects (\sphinxurl{http://analogparadigm.com/downloads/hc\_handbook.pdf}).

\item {} 
configuration tuples for \sphinxcode{\sphinxupquote{hycon}}

\item {} 
or a direct API to \sphinxcode{\sphinxupquote{hycon}}

\end{itemize}

In order to run this program, all you need is \sphinxcode{\sphinxupquote{PyYAML}} to read the YAML files. If you want
to draw circuit plots, you need \sphinxcode{\sphinxupquote{matplotlib}}.


\subsection{Command line interface}
\label{\detokenize{fpaa/fpaa:command-line-interface}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{o}{\PYGZpc{}} \PYG{n}{python} \PYG{o}{\PYGZhy{}}\PYG{n}{m} \PYG{n}{fpaa} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{help}
\PYG{n}{usage}\PYG{p}{:} \PYG{n}{fpaa}\PYG{o}{.}\PYG{n}{py} \PYG{p}{[}\PYG{o}{\PYGZhy{}}\PYG{n}{h}\PYG{p}{]} \PYG{p}{[}\PYG{o}{\PYGZhy{}}\PYG{n}{v}\PYG{p}{]} \PYG{p}{[}\PYG{o}{\PYGZhy{}}\PYG{n}{o} \PYG{n}{OUTPUT}\PYG{o}{.}\PYG{n}{txt}\PYG{p}{]} \PYG{p}{[}\PYG{o}{\PYGZhy{}}\PYG{n}{p} \PYG{n}{OUTPUT}\PYG{o}{.}\PYG{n}{pdf}\PYG{p}{]} \PYG{p}{(}\PYG{o}{\PYGZhy{}}\PYG{n}{A} \PYG{p}{\PYGZob{}}\PYG{n}{XBAR}\PYG{o}{\PYGZhy{}}\PYG{n}{Only}\PYG{p}{,}\PYG{n}{AP}\PYG{o}{\PYGZhy{}}\PYG{n}{M1}\PYG{o}{\PYGZhy{}}\PYG{n}{Mini}\PYG{p}{\PYGZcb{}} \PYG{o}{|} \PYG{o}{\PYGZhy{}}\PYG{n}{a} \PYG{n}{path}\PYG{o}{/}\PYG{n}{to}\PYG{o}{/}\PYG{n}{my}\PYG{o}{/}\PYG{n}{MACHINE}\PYG{o}{.}\PYG{n}{yml}\PYG{p}{)}
            \PYG{n}{CIRCUIT}\PYG{o}{.}\PYG{n}{yml}

\PYG{n}{A} \PYG{n}{circuit} \PYG{n}{synthesizer} \PYG{k}{for} \PYG{n}{the} \PYG{n}{HyConAVR}\PYG{o}{.}

\PYG{n}{positional} \PYG{n}{arguments}\PYG{p}{:}
\PYG{n}{CIRCUIT}\PYG{o}{.}\PYG{n}{yml}           \PYG{n}{The} \PYG{n}{YAML} \PYG{n}{file} \PYG{n}{holding} \PYG{n}{the} \PYG{n}{circuit} \PYG{n}{description}

\PYG{n}{optional} \PYG{n}{arguments}\PYG{p}{:}
\PYG{o}{\PYGZhy{}}\PYG{n}{h}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{help}            \PYG{n}{show} \PYG{n}{this} \PYG{n}{help} \PYG{n}{message} \PYG{o+ow}{and} \PYG{n}{exit}
\PYG{o}{\PYGZhy{}}\PYG{n}{v}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{verbose}         \PYG{n}{increases} \PYG{n}{log} \PYG{n}{verbosity} \PYG{k}{for} \PYG{n}{each} \PYG{n}{occurence}\PYG{o}{.}
\PYG{o}{\PYGZhy{}}\PYG{n}{o} \PYG{n}{OUTPUT}\PYG{o}{.}\PYG{n}{txt}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{output} \PYG{n}{OUTPUT}\PYG{o}{.}\PYG{n}{txt}
                        \PYG{n}{Put} \PYG{n}{output} \PYG{n}{string} \PYG{n}{into} \PYG{n}{file} \PYG{p}{(}\PYG{n}{default} \PYG{o+ow}{is} \PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{\PYGZhy{}}\PYG{l+s+s1}{\PYGZsq{}} \PYG{o+ow}{and} \PYG{n}{means} \PYG{n}{stdout}\PYG{p}{)}
\PYG{o}{\PYGZhy{}}\PYG{n}{p} \PYG{n}{OUTPUT}\PYG{o}{.}\PYG{n}{pdf}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{plot} \PYG{n}{OUTPUT}\PYG{o}{.}\PYG{n}{pdf}
                        \PYG{n}{Plot} \PYG{n}{crossbar} \PYG{n}{switch}
\PYG{o}{\PYGZhy{}}\PYG{n}{A} \PYG{p}{\PYGZob{}}\PYG{n}{XBAR}\PYG{o}{\PYGZhy{}}\PYG{n}{Only}\PYG{p}{,}\PYG{n}{AP}\PYG{o}{\PYGZhy{}}\PYG{n}{M1}\PYG{o}{\PYGZhy{}}\PYG{n}{Mini}\PYG{p}{\PYGZcb{}}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{registered}\PYG{o}{\PYGZhy{}}\PYG{n}{arch} \PYG{p}{\PYGZob{}}\PYG{n}{XBAR}\PYG{o}{\PYGZhy{}}\PYG{n}{Only}\PYG{p}{,}\PYG{n}{AP}\PYG{o}{\PYGZhy{}}\PYG{n}{M1}\PYG{o}{\PYGZhy{}}\PYG{n}{Mini}\PYG{p}{\PYGZcb{}}
                        \PYG{n}{Target} \PYG{n}{machine} \PYG{n}{architecture} \PYG{n}{description}\PYG{p}{:} \PYG{n}{Any} \PYG{n}{YAML} \PYG{n}{file} \PYG{o+ow}{in} \PYG{n}{directory}
                        \PYG{o}{/}\PYG{n}{home}\PYG{o}{/}\PYG{n}{sven}\PYG{o}{/}\PYG{n}{Analog}\PYG{o}{/}\PYG{n}{Forschungsauftrag}\PYG{o}{/}\PYG{n}{dda}\PYG{o}{/}\PYG{n}{fpaa} \PYG{o+ow}{is} \PYG{n}{available} \PYG{k}{as} \PYG{n}{machine}
\PYG{o}{\PYGZhy{}}\PYG{n}{a} \PYG{n}{path}\PYG{o}{/}\PYG{n}{to}\PYG{o}{/}\PYG{n}{my}\PYG{o}{/}\PYG{n}{MACHINE}\PYG{o}{.}\PYG{n}{yml}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{n}{arch} \PYG{n}{path}\PYG{o}{/}\PYG{n}{to}\PYG{o}{/}\PYG{n}{my}\PYG{o}{/}\PYG{n}{MACHINE}\PYG{o}{.}\PYG{n}{yml}
                        \PYG{n}{Target} \PYG{n}{machine} \PYG{n}{architecture} \PYG{n}{description} \PYG{p}{(}\PYG{n+nb}{any} \PYG{n}{valid} \PYG{n}{filename}\PYG{p}{)}
\end{sphinxVerbatim}

See {\hyperref[\detokenize{fpaa/fpaa:fpaa.fpaa.cli}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{fpaa.cli()}}}}} (\autopageref*{\detokenize{fpaa/fpaa:fpaa.fpaa.cli}}) for further details.
\phantomsection\label{\detokenize{fpaa/fpaa:module-fpaa.fpaa}}\index{module@\spxentry{module}!fpaa.fpaa@\spxentry{fpaa.fpaa}}\index{fpaa.fpaa@\spxentry{fpaa.fpaa}!module@\spxentry{module}}\index{Target (class in fpaa.fpaa)@\spxentry{Target}\spxextra{class in fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.Target}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{Target}}}{\emph{\DUrole{n}{part}}, \emph{\DUrole{n}{pin}}}{}~\index{part (fpaa.fpaa.Target attribute)@\spxentry{part}\spxextra{fpaa.fpaa.Target attribute}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.Target.part}}\pysigline{\sphinxbfcode{\sphinxupquote{part}}}
Alias for field number 0

\end{fulllineitems}

\index{pin (fpaa.fpaa.Target attribute)@\spxentry{pin}\spxextra{fpaa.fpaa.Target attribute}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.Target.pin}}\pysigline{\sphinxbfcode{\sphinxupquote{pin}}}
Alias for field number 1

\end{fulllineitems}


\end{fulllineitems}

\index{load\_from\_yaml() (in module fpaa.fpaa)@\spxentry{load\_from\_yaml()}\spxextra{in module fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.load_from_yaml}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{load\_from\_yaml}}}{\emph{\DUrole{n}{circuit}}, \emph{\DUrole{n}{arch}}}{}
Expects arch and circuit to be strings.

\end{fulllineitems}

\index{synthesize() (in module fpaa.fpaa)@\spxentry{synthesize()}\spxextra{in module fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.synthesize}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{synthesize}}}{\emph{\DUrole{n}{circuit}}, \emph{\DUrole{n}{arch}}}{}
Translate a circuit to a netlist for a given target architecture.

This routine is the heart of the FPAA compiler. It mainly
\begin{itemize}
\item {} 
Allocates available hardware to the requested ones by the user circuits
and allows for book keeping between the user named and architecture named computing
components.

\item {} 
Ensures consistency of the resulting circuit (there are no dangling wires,
no over\sphinxhyphen{}allocation, etc.)

\end{itemize}

There is a lot of \sphinxstyleemphasis{info} and \sphinxstyleemphasis{debug} output available if turned on via Python
logging.

Expects \sphinxcode{\sphinxupquote{arch}} and \sphinxcode{\sphinxupquote{circuit}} to be nested data structures (dicts and lists holding
strings and numbers), similar to their YAML representation. The documentation does
not yet cover an in\sphinxhyphen{}depth description of these data structures, but there are tons
of example YAML files which are straightforward to understand.

Returns \sphinxcode{\sphinxupquote{wired\_circuit}}, a list of computing components (which itself are again
“PODs”, i.e. dicts with nested data structures).

\end{fulllineitems}

\index{normalize\_potentiometer() (in module fpaa.fpaa)@\spxentry{normalize\_potentiometer()}\spxextra{in module fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.normalize_potentiometer}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{normalize\_potentiometer}}}{\emph{\DUrole{n}{value}}, \emph{\DUrole{n}{resolution\_bits}\DUrole{o}{=}\DUrole{default_value}{10}}}{}
Map a real value {[}0..1{]} to Potentiometer value {[}0..1023{]}

\end{fulllineitems}

\index{compile\_instructions() (in module fpaa.fpaa)@\spxentry{compile\_instructions()}\spxextra{in module fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.compile_instructions}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{compile\_instructions}}}{\emph{\DUrole{n}{wired\_circuit}}, \emph{\DUrole{n}{arch}}}{}
Compile a netlist (\sphinxcode{\sphinxupquote{wired\_circuit}}) to configuration \sphinxstyleemphasis{instructions} for setting
up the analog computer hybrid controller.

This routine basically loops over the \sphinxstyleemphasis{hardwired parts} of the given architecture,
i.e. built\sphinxhyphen{}in
\begin{itemize}
\item {} 
potentiometers (DPT\sphinxhyphen{}24 and HC)

\item {} 
cross bar arrays (XBAR)

\end{itemize}

and configures them according to the given wired\_circuit. This means that relevant
allocated potentiometers will be set and the XBAR configuration bitmask will be
computed from the hardware description provided by the circuit and the architecture.

Currently returns a list of instructions (tuples) which could be directly be written
out to serial or passed to PyHyCon.

\begin{sphinxadmonition}{note}{Note:}
This method will change in near time and talk directly to a PyHyCon instance.
\end{sphinxadmonition}

\end{fulllineitems}

\index{plot\_xbar() (in module fpaa.fpaa)@\spxentry{plot\_xbar()}\spxextra{in module fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.plot_xbar}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{plot\_xbar}}}{\emph{\DUrole{n}{target\_file}}, \emph{\DUrole{n}{circuit\_title}}, \emph{\DUrole{n}{xbar\_config}\DUrole{o}{=}\DUrole{default_value}{None}}, \emph{\DUrole{n}{interactive\_plotting}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Draw an the allocation of a crossbar switch array (xbar) matrix.

xbar\_config is a tuple with (cols,rows,boolean\_matrix), and by default the last one
from a global registry (last\_seen\_xbars) is taken, which is what you want.

\end{fulllineitems}

\index{cli() (in module fpaa.fpaa)@\spxentry{cli()}\spxextra{in module fpaa.fpaa}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{fpaa/fpaa:fpaa.fpaa.cli}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{fpaa.fpaa.}}\sphinxbfcode{\sphinxupquote{cli}}}{}{}
This module is callable via \sphinxcode{\sphinxupquote{python \sphinxhyphen{}m fpaa}} or \sphinxcode{\sphinxupquote{./fpaa.py}}. It exposes the main
functions on the command line which is especially helpful for debugging or
interactively programming an analog computer from the command line.

Call \sphinxcode{\sphinxupquote{\sphinxhyphen{}\sphinxhyphen{}help}} for all possible command line options.

\end{fulllineitems}



\section{Example codes for FPAA}
\label{\detokenize{fpaa/examples:example-codes-for-fpaa}}\label{\detokenize{fpaa/examples:fpaa-examples}}\label{\detokenize{fpaa/examples::doc}}
We have a number of circuits implemented from the
\sphinxhref{http://analogparadigm.com/documentation.html}{Analog Paradigm application notes}%
\begin{footnote}[76]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/documentation.html}
%
\end{footnote}
website (\sphinxstyleemphasis{Alpaca} in short).

These are for instance:
\begin{itemize}
\item {} 
\sphinxhref{http://analogparadigm.com/downloads/alpaca\_1.pdf}{Rössler attractor}%
\begin{footnote}[77]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/downloads/alpaca\_1.pdf}
%
\end{footnote} (Alpaca 1)

\item {} 
\sphinxhref{http://analogparadigm.com/downloads/alpaca\_2.pdf}{Lorentz attractor}%
\begin{footnote}[78]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/downloads/alpaca\_2.pdf}
%
\end{footnote} (Alpaca 2)

\item {} 
\sphinxhref{http://analogparadigm.com/downloads/alpaca\_6.pdf}{Lotka\sphinxhyphen{}Volterra equations}%
\begin{footnote}[79]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/downloads/alpaca\_6.pdf}
%
\end{footnote} (Alpaca 6)

\item {} 
\sphinxhref{http://analogparadigm.com/downloads/alpaca\_15.pdf}{Nose\sphinxhyphen{}Hoover oscillator, Jerk oscillator}%
\begin{footnote}[80]\sphinxAtStartFootnote
\sphinxnolinkurl{http://analogparadigm.com/downloads/alpaca\_15.pdf}
%
\end{footnote} (Alpaca 15)

\item {} 
Biochemistry enzyme kinetics (based on n1.pdf)

\item {} 
Different toy codes for solving \sphinxcode{\sphinxupquote{exp(t)}}, \sphinxcode{\sphinxupquote{sin(t)}}, etc.

\end{itemize}


\section{Example: A reprogrammable small Model\sphinxhyphen{}1}
\label{\detokenize{fpaa/mini-m1:example-a-reprogrammable-small-model-1}}\label{\detokenize{fpaa/mini-m1:mini-m1}}\label{\detokenize{fpaa/mini-m1::doc}}
This is work in progress and here comes some more pictures
and description.
\sphinxSetupCaptionForVerbatim{Well there}
\def\sphinxLiteralBlockLabel{\label{\detokenize{fpaa/mini-m1:id1}}}
\begin{sphinxVerbatim}[commandchars=\\\{\},numbers=left,firstnumber=1,stepnumber=1]
\PYG{c+c1}{\PYGZsh{} This is a YAML description file for a machine.}
\PYG{c+c1}{\PYGZsh{} A poor man\PYGZsq{}s Analog HDL (should use Verilog HDLs instead)}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{} Copyright (c) 2020 anabrid GmbH}
\PYG{c+c1}{\PYGZsh{} Contact: https://www.anabrid.com/licensing/}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{} This file is part of the FPAA module of the PyAnalog toolkit.}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{} ANABRID\PYGZus{}BEGIN\PYGZus{}LICENSE:GPL}
\PYG{c+c1}{\PYGZsh{} Commercial License Usage}
\PYG{c+c1}{\PYGZsh{} Licensees holding valid commercial anabrid licenses may use this file in}
\PYG{c+c1}{\PYGZsh{} accordance with the commercial license agreement provided with the}
\PYG{c+c1}{\PYGZsh{} Software or, alternatively, in accordance with the terms contained in}
\PYG{c+c1}{\PYGZsh{} a written agreement between you and Anabrid GmbH. For licensing terms}
\PYG{c+c1}{\PYGZsh{} and conditions see https://www.anabrid.com/licensing. For further}
\PYG{c+c1}{\PYGZsh{} information use the contact form at https://www.anabrid.com/contact.}
\PYG{c+c1}{\PYGZsh{} }
\PYG{c+c1}{\PYGZsh{} GNU General Public License Usage}
\PYG{c+c1}{\PYGZsh{} Alternatively, this file may be used under the terms of the GNU }
\PYG{c+c1}{\PYGZsh{} General Public License version 3 as published by the Free Software}
\PYG{c+c1}{\PYGZsh{} Foundation and appearing in the file LICENSE.GPL3 included in the}
\PYG{c+c1}{\PYGZsh{} packaging of this file. Please review the following information to}
\PYG{c+c1}{\PYGZsh{} ensure the GNU General Public License version 3 requirements}
\PYG{c+c1}{\PYGZsh{} will be met: https://www.gnu.org/licenses/gpl\PYGZhy{}3.0.html.}
\PYG{c+c1}{\PYGZsh{} For Germany, additional rules exist. Please consult /LICENSE.DE}
\PYG{c+c1}{\PYGZsh{} for further agreements.}
\PYG{c+c1}{\PYGZsh{} ANABRID\PYGZus{}END\PYGZus{}LICENSE}
\PYG{c+c1}{\PYGZsh{}}

\PYG{n+nt}{title}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{AP/M\PYGZhy{}1}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{Mini}

\PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
   \PYG{n+no}{This file describes the hardware layout of a particular Analog Paradigm}
   \PYG{n+no}{Model\PYGZhy{}1 machine with software\PYGZhy{}definable XBAR in the smallest setup,}
   \PYG{n+no}{containing SUM8, INT4, MUL4, DPT32 (and of course XBAR, HC).}
   
   \PYG{n+no}{The number of Summers limits the number of negating\PYGZhy{}macro elements}
   \PYG{n+no}{which can be built. The configurable parts show what can be done}
   
      \PYG{n+no}{SUM8.1 =\PYGZgt{} 1 x SUM2m}
      \PYG{n+no}{SUM8.2 =\PYGZgt{} 0.5 SUM2pm}
      \PYG{n+no}{SUM8.3 =\PYGZgt{} 0.5 SUM2pm}
      \PYG{n+no}{SUM8.4 =\PYGZgt{} 0.5 SUM2pm}
      \PYG{n+no}{SUM8.5 =\PYGZgt{} 0.5 SUM2pm}
      \PYG{n+no}{SUM8.6 =\PYGZgt{} 1 x INT2pm}
      \PYG{n+no}{SUM8.7 =\PYGZgt{} 1 x INT2pm, leaving 1 x INT2m}
      \PYG{n+no}{SUM8.8 =\PYGZgt{} 1 x MUL2pm, leaving 1 x MUL2m}

   \PYG{n+no}{In total 8 computing elements. See configurable\PYGZus{}parts for the formal}
   \PYG{n+no}{definition.}

\PYG{n+nt}{configurable\PYGZus{}parts}\PYG{p}{:}
   \PYG{c+c1}{\PYGZsh{} naming follows the HyCon YML file, part \PYGZdq{}elements\PYGZdq{}}
   \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{INTpinv}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0160} \PYG{c+c1}{\PYGZsh{} integrator INT8.1}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0123} \PYG{c+c1}{\PYGZsh{} summer SUM8.4 as inverter}
   \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{INTpinv}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0161} \PYG{c+c1}{\PYGZsh{} integrator INT8.2}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0126} \PYG{c+c1}{\PYGZsh{} summer SUM8.7 as inverter}
   \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{INTp}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0162} \PYG{c+c1}{\PYGZsh{} integrator INT8.3}
   \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{c+c1}{\PYGZsh{} HyCon calls it MLT8\PYGZhy{}0}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{MULpinv}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0100} \PYG{c+c1}{\PYGZsh{} multiplier MUL4.1}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0127} \PYG{c+c1}{\PYGZsh{} summer SUM8.8 as inverter}
   \PYG{n+nt}{MLT0\PYGZhy{}1}\PYG{p}{:} \PYG{c+c1}{\PYGZsh{} HyCon calls it MLT8\PYGZhy{}1}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{MULpinv}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0100} \PYG{c+c1}{\PYGZsh{} multiplier MUL4.2}
   \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUMpinv}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0120} \PYG{c+c1}{\PYGZsh{} summer SUM8.1}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0124} \PYG{c+c1}{\PYGZsh{} summer SUM8.5 as inverter (is below 1)}
   \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUMpinv}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0121} \PYG{c+c1}{\PYGZsh{} summer SUM8.2}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0125} \PYG{c+c1}{\PYGZsh{} summer SUM8.6 as inverter (is below 2)}
   \PYG{n+nt}{SUM0\PYGZhy{}2}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUMp}
     \PYG{n+nt}{address}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0122} \PYG{c+c1}{\PYGZsh{} summer SUM8.3}
   \PYG{n+nt}{PlusOne}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{Positive supply voltage/machine unit, also refered to as Vcc or Vdd,}
       \PYG{n+no}{i.e. +10V in this machine.}
     \PYG{n+nt}{cannot\PYGZus{}be\PYGZus{}allocated}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{True}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ConstantVoltage}
     \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{+1} \PYG{p+pIndicator}{]}
   \PYG{n+nt}{MinusOne}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{Negative supply voltage/machine unit, also refered to as Vss,}
       \PYG{n+no}{i.e. \PYGZhy{}10V in this machine.}
     \PYG{n+nt}{cannot\PYGZus{}be\PYGZus{}allocated}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{True}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ConstantVoltage}
     \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{\PYGZhy{}1} \PYG{p+pIndicator}{]}
   \PYG{n+nt}{None}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{See}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{description}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{NoneType}
     \PYG{n+nt}{cannot\PYGZus{}be\PYGZus{}allocated}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{True}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{NoneType}
   
   
\PYG{c+c1}{\PYGZsh{} We currently not make (yet) use of these levels anywhere, but they}
\PYG{c+c1}{\PYGZsh{} are later required for evaluating MUL\PYGZsq{}s, for instance.}
\PYG{n+nt}{logic}\PYG{p}{:}
   \PYG{n+nt}{boolean}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{True}\PYG{p+pIndicator}{,} \PYG{n+nv}{False} \PYG{p+pIndicator}{]}
   \PYG{n+nt}{machine\PYGZus{}units}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{+1}\PYG{p+pIndicator}{,} \PYG{n+nv}{\PYGZhy{}1} \PYG{p+pIndicator}{]}
   \PYG{n+nt}{voltage\PYGZus{}range}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{+10}\PYG{p+pIndicator}{,} \PYG{n+nv}{\PYGZhy{}10} \PYG{p+pIndicator}{]}
   \PYG{n+nt}{voltage\PYGZus{}unit}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{V}
   \PYG{n+nt}{DGND\PYGZus{}voltage}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0} \PYG{c+c1}{\PYGZsh{} won\PYGZsq{}t this be different}
   \PYG{n+nt}{AGND\PYGZus{}voltage}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0} \PYG{c+c1}{\PYGZsh{} on the chip?}

\PYG{n+nt}{entities}\PYG{p}{:}

\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}            Elementary building blocks of Model\PYGZhy{}1 Computer}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}

   \PYG{n+nt}{DPT}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{elementary}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A single digital potentiometer (part of a DPT24 or HC module).}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{vs}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{vs=v0*v}
     \PYG{n+nt}{input}\PYG{p}{:}
        \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{v0}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{numeric}\PYG{p+pIndicator}{,}\PYG{n+nt}{ range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]} \PYG{p+pIndicator}{\PYGZcb{}}
        \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{v}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{output}\PYG{p}{:}
        \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{vs}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}

   \PYG{n+nt}{SUM}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{elementary}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A single summer (part of a SUM8 module).}
        \PYG{n+no}{The summer is a negating summer featuring}
          \PYG{n+no}{* three inputs of weight a=10 (input prefix \PYGZdq{}d\PYGZdq{} for \PYGZdq{}decade\PYGZdq{}) and}
          \PYG{n+no}{* three inputs of weight a= 1 (input prefix \PYGZdq{}u\PYGZdq{} for \PYGZdq{}unit\PYGZdq{})}
        \PYG{n+no}{We are lazy so we only describe two input lines each.}
        \PYG{n+no}{We dont model the summing junction (SJ) yet.}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}(10*d1}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{10*d2}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{u1}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{u2)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{d1}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{d2}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{u1}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{u2}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{negating}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summer}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ d1}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ d2}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ u1}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ u2}\PYG{p}{:} \PYG{n+nv}{None} \PYG{p+pIndicator}{\PYGZcb{}}

   \PYG{n+nt}{INT}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{elementary}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A single integrator (one of the INT4 module).}

        \PYG{n+no}{The integrator is an (implicite negating summing) intergrator}
        \PYG{n+no}{featuring}
          \PYG{n+no}{* three inputs of weight a=10 (input prefix \PYGZdq{}d\PYGZdq{} for \PYGZdq{}decade\PYGZdq{}) and}
          \PYG{n+no}{* three inputs of weight a= 1 (input prefix \PYGZdq{}u\PYGZdq{} for \PYGZdq{}unit\PYGZdq{})}
        \PYG{n+no}{We are lazy so we only describe two input lines each.}
        \PYG{n+no}{For the moment, we dont model/make use of ModeIC and ModeOP.}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{  }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{  }\PYG{l+lScalar+lScalarPlain}{integral(\PYGZhy{}10*d1(t)}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{10*d2(t)}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{u1(t)}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{u2(t),}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{t)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{d1}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{d2}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{u1}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{u2}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ic}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Initial}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{condition}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{integral}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ d1}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ d2}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ u1}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ u2}\PYG{p}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,}\PYG{n+nt}{ ic}\PYG{p}{:} \PYG{n+nv}{None} \PYG{p+pIndicator}{\PYGZcb{}}


   \PYG{n+nt}{MUL}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{elementary}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{A single multiplier (one of the MLT8 module).}

       \PYG{n+no}{Remember that multiplication is implemented normalized. For instance,}
       \PYG{n+no}{if machine voltage is level=+10V (actually +\PYGZhy{}10V), the multiplication}
       \PYG{n+no}{computes res = (a/level * b/level)*level in order to make sure}
       \PYG{n+no}{|res|\PYGZlt{}10V.}

       \PYG{n+no}{\PYGZhy{}\PYGZgt{} In order to decouple analog programming from the machine where}
          \PYG{n+no}{it runs, the normalization should be implemented in the}
          \PYG{n+no}{compilation step!}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{a}\PYG{p+pIndicator}{,}\PYG{n+nt}{   type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{b}\PYG{p+pIndicator}{,}\PYG{n+nt}{   type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{out}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a*b/voltage\PYGZus{}level}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a}\PYG{p+pIndicator}{:} \PYG{n+nv}{PlusOne}\PYG{p+pIndicator}{,} \PYG{n+nv}{b}\PYG{p+pIndicator}{:} \PYG{n+nv}{PlusOne} \PYG{p+pIndicator}{]} \PYG{c+c1}{\PYGZsh{} useful?}
     
   \PYG{n+nt}{CMPad}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{The left part of a CMP4 comparator (analog2digital),}
        \PYG{n+no}{i.e. a treshold based binarization.}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{res}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{res}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a+b\PYGZgt{}0}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:}   \PYG{n+nv}{a}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:}   \PYG{n+nv}{b}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{res}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{digital} \PYG{p+pIndicator}{\PYGZcb{}}

   \PYG{n+nt}{CMPda}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{The right part of a CMP4 comparator (digital2analog),}
        \PYG{n+no}{i.e. a single electronic switch switching between two analog}
        \PYG{n+no}{signals.}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{u}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{u}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{if(i,}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a,}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{i}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{digital} \PYG{p+pIndicator}{\PYGZcb{}} \PYG{c+c1}{\PYGZsh{} boolean}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{a}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog}  \PYG{p+pIndicator}{\PYGZcb{}} 
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{b}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog}  \PYG{p+pIndicator}{\PYGZcb{}} 
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{u}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog}  \PYG{p+pIndicator}{\PYGZcb{}}


\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}         Macro computing elements plugged together by elementary ones}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}

   \PYG{n+nt}{SUMp}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{macro}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A single summer (SUM8 part) and two digital potentiometers.}
        \PYG{n+no}{We only use weights a=10 from the summer.}
        \PYG{n+no}{The flow chart is given by:}
        
          \PYG{n+no}{(a0)\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
                  \PYG{n+no}{|}
                  \PYG{n+no}{v}
          \PYG{n+no}{(a)\PYGZhy{}\PYGZgt{}[DPTa]\PYGZhy{}\PYGZhy{}(as)\PYGZhy{}\PYGZhy{}\PYGZgt{}[10|        ]}
                              \PYG{n+no}{[  | SUMo   ]\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{} out}
          \PYG{n+no}{(b)\PYGZhy{}\PYGZgt{}[DPTb]\PYGZhy{}\PYGZhy{}(bs)\PYGZhy{}\PYGZhy{}\PYGZgt{}[10|        ]}
                  \PYG{n+no}{\PYGZca{}}
                  \PYG{n+no}{|}
          \PYG{n+no}{(b0)\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}

     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}(a0*a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b0*b)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{negating}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summer}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}
       \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{a0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{b0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
     \PYG{n+nt}{internal\PYGZus{}wires}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{as}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Scaled}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTa)}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{bs}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Scaled}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTb)}
     \PYG{n+nt}{partlist}\PYG{p}{:}
       \PYG{n+nt}{DPTa}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,} \PYG{n+nv}{a} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{as}
       \PYG{n+nt}{DPTb}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,} \PYG{n+nv}{b} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{bs}
       \PYG{n+nt}{SUMo}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUM}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ d1}\PYG{p}{:} \PYG{n+nv}{as}\PYG{p+pIndicator}{,}\PYG{n+nt}{ d2}\PYG{p}{:} \PYG{n+nv}{bs} \PYG{p+pIndicator}{\PYGZcb{}}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
     \PYG{c+c1}{\PYGZsh{} These \PYGZdq{}is a\PYGZdq{}\PYGZhy{}relations should allow using elements instead of others}
     \PYG{n+nt}{is\PYGZus{}a}\PYG{p}{:}
       \PYG{n+nt}{SUM}\PYG{p}{:}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Can}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{mimic}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{simple}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{when}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{having}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{both}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTs}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{1.}
         \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{a0}\PYG{p+pIndicator}{:} \PYG{n+nv}{1}\PYG{p+pIndicator}{,} \PYG{n+nv}{b0}\PYG{p+pIndicator}{:} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{n+nt}{DPT}\PYG{p}{:}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Can}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{mimic}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{simple}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{when}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{not}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summing}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{at}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{all.}
         \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{a}\PYG{p+pIndicator}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,} \PYG{n+nv}{b}\PYG{p+pIndicator}{:} \PYG{n+nv}{None}\PYG{p+pIndicator}{,} \PYG{n+nv}{b0}\PYG{p+pIndicator}{:} \PYG{n+nv}{0}\PYG{p+pIndicator}{]}
         

   \PYG{n+nt}{MULp}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{macro}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{A simple macro element made of a single multiplier (MLT8) and two}
       \PYG{n+no}{digital potentiometers (on DPT24).}
       
       \PYG{n+no}{The flow chart is similar to SUMp:}
       
          \PYG{n+no}{(a0)\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
                  \PYG{n+no}{|}
                  \PYG{n+no}{v}
          \PYG{n+no}{(a)\PYGZhy{}\PYGZgt{}[DPTa]\PYGZhy{}\PYGZhy{}(as)\PYGZhy{}\PYGZhy{}\PYGZgt{}[       ]}
                              \PYG{n+no}{[  MULo ]\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{} out}
          \PYG{n+no}{(b)\PYGZhy{}\PYGZgt{}[DPTb]\PYGZhy{}\PYGZhy{}(bs)\PYGZhy{}\PYGZhy{}\PYGZgt{}[       ]}
                  \PYG{n+no}{\PYGZca{}}
                  \PYG{n+no}{|}
          \PYG{n+no}{(b0)\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}

     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,}\PYG{n+nt}{  type}\PYG{p}{:} \PYG{n+nv}{digital} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{a}\PYG{p+pIndicator}{,}\PYG{n+nt}{   type}\PYG{p}{:} \PYG{n+nv}{analog}  \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,}\PYG{n+nt}{  type}\PYG{p}{:} \PYG{n+nv}{digital} \PYG{p+pIndicator}{\PYGZcb{}}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{b}\PYG{p+pIndicator}{,}\PYG{n+nt}{   type}\PYG{p}{:} \PYG{n+nv}{analog}  \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{out}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog}  \PYG{p+pIndicator}{\PYGZcb{}}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a0*a*b0*b/voltage\PYGZus{}level}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}
       \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{PlusOne}
       \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{PlusOne}
       \PYG{n+nt}{a0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{b0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
     \PYG{n+nt}{internal\PYGZus{}wires}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{as}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Scaled}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTa)}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{bs}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Scaled}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTb)}
     \PYG{n+nt}{partlist}\PYG{p}{:}
       \PYG{n+nt}{DPTa}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,} \PYG{n+nv}{a} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{as}
       \PYG{n+nt}{DPTb}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,} \PYG{n+nv}{b}\PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{bs}
       \PYG{n+nt}{MULo}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{MUL}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{as}\PYG{p+pIndicator}{,} \PYG{n+nv}{bs}\PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
     \PYG{n+nt}{is\PYGZus{}a}\PYG{p}{:}
       \PYG{n+nt}{MUL}\PYG{p}{:}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Can}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{mimic}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{simple}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{multiplier}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{when}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{having}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{both}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTs}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{1.}
         \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{a0}\PYG{p+pIndicator}{:} \PYG{n+nv}{1}\PYG{p+pIndicator}{,} \PYG{n+nv}{b0}\PYG{p+pIndicator}{:} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{c+c1}{\PYGZsh{} DPT: would be ironic since MLT also multiplies. Would rather compute MLT(DPT(x,PlusOne),PlusOne)}

         
   \PYG{n+nt}{INTp}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{macro}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A macro component made of an integrator (one in the INT4 module)}
        \PYG{n+no}{and three potentiometers (two shall be implemented on the DPT24,}
        \PYG{n+no}{one on the HC, but that doesn\PYGZsq{}t matter at this stage).}

        \PYG{n+no}{The integrator is an (implicite negating summing) intergrator}
        \PYG{n+no}{with two inputs. For the moment, we dont make use of ModeIC and}
        \PYG{n+no}{ModeOP. All inputs use weight a=10.}

        \PYG{n+no}{In the moment, the ICs are realized by one potentiometer and}
        \PYG{n+no}{a comparator. The compiler creates the binary sign which steers}
        \PYG{n+no}{the comparator and is outputted by the Hybrid Controller (HC).}

        \PYG{n+no}{The summer is a (negating) summer with a single input.}
        \PYG{n+no}{The summer uses weight a=1.}
        \PYG{n+no}{Neither in integrator nor summer, we make use of the SJ.}

        \PYG{n+no}{The flow chart looks like}

         \PYG{n+no}{ic \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
                                        \PYG{n+no}{|}
         \PYG{n+no}{HC digital output,             |}
         \PYG{n+no}{icSign \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+                  |}
                     \PYG{n+no}{| switches         | controls}
                     \PYG{n+no}{v                  v}
          \PYG{n+no}{+1 \PYGZhy{}(p1)\PYGZhy{}\PYGZgt{}[ SignGen ]\PYGZhy{}(pm)\PYGZhy{}\PYGZgt{}[DPTic]  (HC DPT)}
          \PYG{n+no}{\PYGZhy{}1 \PYGZhy{}(m1)\PYGZhy{}\PYGZgt{}[ (CMPda) ]         |}
                                      \PYG{n+no}{(aic)}
          \PYG{n+no}{a0 \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+                    |}
                   \PYG{n+no}{| controls           | sets IC}
                   \PYG{n+no}{v                    v}
          \PYG{n+no}{a \PYGZhy{}\PYGZgt{}[DPTa]\PYGZhy{}\PYGZhy{}\PYGZhy{}(as)\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{}[10|            ]}
                               \PYG{n+no}{[    Integrator ]\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{} out}
          \PYG{n+no}{b \PYGZhy{}\PYGZgt{}[DPTb]\PYGZhy{}\PYGZhy{}\PYGZhy{}(bs)\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{}[10|            ]}
                   \PYG{n+no}{\PYGZca{}}
                   \PYG{n+no}{|  controls}
          \PYG{n+no}{b0 \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}integral(}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a0*a(t)}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b0*b(t),}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{t)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{icSign}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{boolean}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Sign}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{initial}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{condition}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{value}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ic}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Value}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{for}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{initial}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{condition}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{integral}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}
       \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{a0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{b0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{icSign}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{True}
       \PYG{n+nt}{ic}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
     \PYG{n+nt}{internal\PYGZus{}wires}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{as}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Scaled}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTa)}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{bs}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Scaled}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPTb)}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{aic}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Analog}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{Initial}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{conditions}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{Comparator}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{and}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{multiplied}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{by}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{HC}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{DPT)}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{pm}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Plus}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{or}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{Minus,}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{depending}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{on}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{the}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{sign}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{bit}
     \PYG{n+nt}{partlist}\PYG{p}{:}
       \PYG{n+nt}{DPTa}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,} \PYG{n+nv}{a} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{as}
       \PYG{n+nt}{DPTb}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,} \PYG{n+nv}{b}\PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{bs}
       \PYG{n+nt}{SignGen}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{CMPda0}
         \PYG{n+nt}{input}\PYG{p}{:}
           \PYG{n+nt}{i}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{icSign}
           \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{PlusOne}
           \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{MinusOne}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{pm}
       \PYG{n+nt}{DPTic}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT} \PYG{c+c1}{\PYGZsh{} but shall be implemented on HC for clarity}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{ic}\PYG{p+pIndicator}{,} \PYG{n+nv}{pm} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{aic}
       \PYG{n+nt}{INTo}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{INT}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ d1}\PYG{p}{:} \PYG{n+nv}{as}\PYG{p+pIndicator}{,}\PYG{n+nt}{ d2}\PYG{p}{:} \PYG{n+nv}{bs}\PYG{p+pIndicator}{,}\PYG{n+nt}{ ic}\PYG{p}{:} \PYG{n+nv}{aic} \PYG{p+pIndicator}{\PYGZcb{}}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         
\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}         Macro elements with attached inverter (negation)}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}

   \PYG{n+nt}{SUMpinv}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{macro}
     \PYG{n+nt}{is\PYGZus{}a}\PYG{p}{:}
       \PYG{n+nt}{SUMp}\PYG{p}{:}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
           \PYG{n+no}{Can mimic a single potentiometered summer. Just ignore the inv output.}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A macro component made of two summers (SUM8 module) and two digital}
        \PYG{n+no}{potentiometers (on DPT24). It is an easy extension of the SUMp}
        \PYG{n+no}{module, the flow chart is just:}
        
                 \PYG{n+no}{+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
          \PYG{n+no}{a0  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |        +\PYGZhy{}\PYGZhy{}[ 1| SUMinv ]\PYGZhy{}\PYGZgt{} inv}
          \PYG{n+no}{a   \PYGZhy{}\PYGZhy{}\PYGZgt{}| SUMp  |        |}
          \PYG{n+no}{b0  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{} out}
          \PYG{n+no}{b   \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |}
                 \PYG{n+no}{+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
        
        \PYG{n+no}{Remember, the summer SUMo in SUMp uses weights a=10, while the}
        \PYG{n+no}{inverting summer SUMinv uses weight a=1.}

     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{   }\PYG{l+lScalar+lScalarPlain}{a0*a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b0*b}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}(a0*a}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b0*b)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{minus}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{operation}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(actual}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{output)}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{plus}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{operation}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(negation}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{output)}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}
       \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{a0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{b0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
     \PYG{n+nt}{partlist}\PYG{p}{:}
       \PYG{n+nt}{MainSummer}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUMp}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,} \PYG{n+nv}{a}\PYG{p+pIndicator}{,} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,} \PYG{n+nv}{b} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
       \PYG{n+nt}{SUMinv}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUM}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ u1}\PYG{p}{:} \PYG{n+nv}{out} \PYG{p+pIndicator}{\PYGZcb{}}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}

   \PYG{n+nt}{MULpinv}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{macro}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{Extension of MUL2m with two outputs, where one is negated, thus}
       \PYG{n+no}{requiring an internal summer.}
       \PYG{n+no}{Flow chart is just:}
       
       \PYG{n+no}{ }
                 \PYG{n+no}{+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
          \PYG{n+no}{a0  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |        +\PYGZhy{}\PYGZhy{}[ 1| SUMinv ]\PYGZhy{}\PYGZgt{} inv}
          \PYG{n+no}{a   \PYGZhy{}\PYGZhy{}\PYGZgt{}| MULp  |        |}
          \PYG{n+no}{b0  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{} out}
          \PYG{n+no}{b   \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |}
                 \PYG{n+no}{+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{digital}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{digital}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{  }\PYG{l+lScalar+lScalarPlain}{a0*a*b0*b/voltage\PYGZus{}level}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}a0*a*b0*b/voltage\PYGZus{}level}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}
       \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{PlusOne}
       \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{PlusOne}
       \PYG{n+nt}{a0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{b0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
     \PYG{n+nt}{partlist}\PYG{p}{:}
       \PYG{n+nt}{Multiplier}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{MULp}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,} \PYG{n+nv}{a}\PYG{p+pIndicator}{,} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,} \PYG{n+nv}{b} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
       \PYG{n+nt}{SUMinv}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUM}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ u1}\PYG{p}{:} \PYG{n+nv}{out} \PYG{p+pIndicator}{\PYGZcb{}}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}
         
   \PYG{n+nt}{INTpinv}\PYG{p}{:}
     \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{macro}
     \PYG{n+nt}{is\PYGZus{}a}\PYG{p}{:}
       \PYG{n+nt}{INTp}\PYG{p}{:}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
           \PYG{n+no}{Can mimic a single potentiometered integrator. Just ignore the inv output.}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
        \PYG{n+no}{A macro component which can invert the output of INTp.}
        \PYG{n+no}{The flow chart is just:}
        
                 \PYG{n+no}{+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}
          \PYG{n+no}{a0  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |        +\PYGZhy{}\PYGZhy{}[ 1| SUMinv ]\PYGZhy{}\PYGZgt{} inv}
          \PYG{n+no}{a   \PYGZhy{}\PYGZhy{}\PYGZgt{}| INTp  |        |}
          \PYG{n+no}{b0  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZgt{} out}
          \PYG{n+no}{b   \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |}
          \PYG{n+no}{icSign\PYGZgt{}|       |}
          \PYG{n+no}{ic  \PYGZhy{}\PYGZhy{}\PYGZgt{}|       |}
                 \PYG{n+no}{+\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}+}

     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{out}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}\PYG{l+lScalar+lScalarPlain}{  }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{  }\PYG{l+lScalar+lScalarPlain}{integral(}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a0*a(t)}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b0*b(t),}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{t)}
       \PYG{n+nt}{inv}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}\PYG{l+lScalar+lScalarPlain}{  }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{\PYGZhy{}integral(}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{a0*a(t)}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{+}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{b0*b(t),}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{t)}
     \PYG{n+nt}{input}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Potentiometer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{prefactor}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{icSign}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{boolean}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Sign}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{initial}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{condition}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{value}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ic}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{numeric}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Value}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{for}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{initial}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{condition}
         \PYG{n+nt}{range}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{n+nv}{0}\PYG{p+pIndicator}{,} \PYG{n+nv}{1}\PYG{p+pIndicator}{]}
     \PYG{n+nt}{output}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Actual}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{integrator}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{name}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{analog}
         \PYG{n+nt}{description}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Output}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{summer}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{(negation}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{of}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{integrator)}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}
       \PYG{n+nt}{a}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{b}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{None}
       \PYG{n+nt}{a0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{b0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
       \PYG{n+nt}{icSign}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{True}
       \PYG{n+nt}{ic}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0}
     \PYG{n+nt}{partlist}\PYG{p}{:}
       \PYG{n+nt}{MainINT}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{INTp}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{a0}\PYG{p+pIndicator}{,} \PYG{n+nv}{a}\PYG{p+pIndicator}{,} \PYG{n+nv}{b0}\PYG{p+pIndicator}{,} \PYG{n+nv}{b}\PYG{p+pIndicator}{,} \PYG{n+nv}{icSign}\PYG{p+pIndicator}{,} \PYG{n+nv}{ic} \PYG{p+pIndicator}{]}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}
       \PYG{n+nt}{SUMinv}\PYG{p}{:}
         \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{SUM}
         \PYG{n+nt}{input}\PYG{p}{:} \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ u1}\PYG{p}{:} \PYG{n+nv}{out} \PYG{p+pIndicator}{\PYGZcb{}}
         \PYG{n+nt}{output}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}

\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{}         Pseudo elements (Helpers)}
\PYG{c+c1}{\PYGZsh{}}
\PYG{c+c1}{\PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{} \PYGZsh{}}

   \PYG{n+nt}{ConstantVoltage}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{This is a pseudo\PYGZhy{}element only used for allocate a logic +1 and}
       \PYG{n+no}{logic \PYGZhy{}1 on the XBAR.}
       \PYG{n+no}{Usage examples are given in the partlist with the instances}
       \PYG{n+no}{PlusOne and MinusOne. These parts are subject to be used}
       \PYG{n+no}{also in the actual programs (for the time being), in order to}
       \PYG{n+no}{realize constant inputs for computatational parts. We need}
       \PYG{n+no}{+1 and \PYGZhy{}1 because the potentiometers only implement range [0,1].}
       \PYG{n+no}{The operation x\PYGZhy{}0.5 is then realized by the pseudo\PYGZhy{}code}
       \PYG{n+no}{SUMMER(a=x,a0=1,b=MinusOne,b0=0.5), while x+0.7 is realized by}
       \PYG{n+no}{SUMMER(a=x,a0=1,b=PlusOne,b0=0.7).}
     \PYG{n+nt}{computes}\PYG{p}{:}
       \PYG{n+nt}{value}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{value}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{=}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{x}
     \PYG{n+nt}{input}\PYG{p}{:}  \PYG{p+pIndicator}{[}\PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{x}\PYG{p+pIndicator}{,}\PYG{n+nt}{     type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}\PYG{p+pIndicator}{]}
     \PYG{n+nt}{output}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{value}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}\PYG{p+pIndicator}{]}

   \PYG{n+nt}{NoneType}\PYG{p}{:}
     \PYG{n+nt}{description}\PYG{p}{:} \PYG{p+pIndicator}{|}
       \PYG{n+no}{This pseudo\PYGZhy{}element is only used to implement computational}
       \PYG{n+no}{elements with unconnected inputs. For instance, the pseudo\PYGZhy{}code}
       \PYG{n+no}{SUMMER(x)=\PYGZhy{}x is actually implemented as}
       \PYG{n+no}{SUMMER(a=x,a0=1,b=None,b0=0)  (the value of b0 is not relevant!).}
       \PYG{n+no}{The compiler will throw out None elements in favour of disabling}
       \PYG{n+no}{the corresponding output line of the XBAR.}

       \PYG{n+no}{The None is also used for slurping input from the DPTs, therefore}
       \PYG{n+no}{they have an input.}
     \PYG{n+nt}{computes}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{nothing}
     \PYG{n+nt}{input}\PYG{p}{:}          \PYG{p+pIndicator}{[}\PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{none}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}\PYG{p+pIndicator}{]}
     \PYG{n+nt}{output}\PYG{p}{:}         \PYG{p+pIndicator}{[}\PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ name}\PYG{p}{:} \PYG{n+nv}{none}\PYG{p+pIndicator}{,}\PYG{n+nt}{ type}\PYG{p}{:} \PYG{n+nv}{analog} \PYG{p+pIndicator}{\PYGZcb{}}\PYG{p+pIndicator}{]}
     \PYG{n+nt}{default\PYGZus{}inputs}\PYG{p}{:}  \PYG{p+pIndicator}{\PYGZob{}}\PYG{n+nt}{ none}\PYG{p}{:} \PYG{n+nv}{0} \PYG{p+pIndicator}{\PYGZcb{}}


\PYG{c+c1}{\PYGZsh{} Each of the wired hardware needs configuration by the HC}
\PYG{c+c1}{\PYGZsh{} (which also needs to be configured itself)}
\PYG{n+nt}{wired\PYGZus{}parts}\PYG{p}{:}
  \PYG{n+nt}{X1}\PYG{p}{:}
    \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{XBAR}
    \PYG{n+nt}{address}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0040}
    \PYG{n+nt}{number\PYGZus{}of\PYGZus{}config\PYGZus{}bytes}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{10}
    \PYG{c+c1}{\PYGZsh{} Datasheet of chip AD8113:}
    \PYG{c+c1}{\PYGZsh{} https://www.analog.com/media/en/technical\PYGZhy{}documentation/data\PYGZhy{}sheets/AD8113.pdf}
    \PYG{n+nt}{topology}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{Single}\PYG{l+lScalar+lScalarPlain}{ }\PYG{l+lScalar+lScalarPlain}{AD8113}
    \PYG{n+nt}{size}\PYG{p}{:} \PYG{p+pIndicator}{[} \PYG{n+nv}{16}\PYG{p+pIndicator}{,} \PYG{n+nv}{16} \PYG{p+pIndicator}{]}
    \PYG{n+nt}{input\PYGZus{}columns}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{l+lScalar+lScalarPlain}{PlusOne}          \PYG{c+c1}{\PYGZsh{}  1}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{l+lScalar+lScalarPlain}{MinusOne}         \PYG{c+c1}{\PYGZsh{}  2}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{l+lScalar+lScalarPlain}{SUM0\PYGZhy{}2}           \PYG{c+c1}{\PYGZsh{}  3}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}      \PYG{c+c1}{\PYGZsh{}  4}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}      \PYG{c+c1}{\PYGZsh{}  5}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}      \PYG{c+c1}{\PYGZsh{}  6}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}      \PYG{c+c1}{\PYGZsh{}  7}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{l+lScalar+lScalarPlain}{MLT0\PYGZhy{}1}           \PYG{c+c1}{\PYGZsh{}  8}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}      \PYG{c+c1}{\PYGZsh{}  9}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}      \PYG{c+c1}{\PYGZsh{} 10}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{l+lScalar+lScalarPlain}{INT0\PYGZhy{}2}           \PYG{c+c1}{\PYGZsh{} 11}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}      \PYG{c+c1}{\PYGZsh{} 12}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}      \PYG{c+c1}{\PYGZsh{} 13}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{out}      \PYG{c+c1}{\PYGZsh{} 14}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{inv}      \PYG{c+c1}{\PYGZsh{} 15}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{l+lScalar+lScalarPlain}{None}             \PYG{c+c1}{\PYGZsh{} 16, empty!}
    \PYG{n+nt}{output\PYGZus{}rows}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{}  1}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{}  2}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{}  3}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{}  4}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{}  5}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{}  6}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{}  7}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{}  8}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{}  9}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{} 10}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{} 11}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{} 12}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{} 13}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{} 14}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a}        \PYG{c+c1}{\PYGZsh{} 15}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b}        \PYG{c+c1}{\PYGZsh{} 16}

  \PYG{n+nt}{D1}\PYG{p}{:}
    \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{DPT24}
    \PYG{n+nt}{address}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0060}
    \PYG{n+nt}{size}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{24}
    \PYG{n+nt}{enumeration}\PYG{p}{:}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{}  1}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{}  2}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{}  3}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{}  4}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{}  5}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{}  6}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{}  7}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{}  8}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{}  9}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{MLT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{} 10}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{} 11}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{} 12}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{} 13}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{} 14}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{a0}    \PYG{c+c1}{\PYGZsh{} 15}
       \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{SUM0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{b0}    \PYG{c+c1}{\PYGZsh{} 16}

  \PYG{n+nt}{Main}\PYG{p}{:}
    \PYG{c+c1}{\PYGZsh{} A Hybrid Controller has 8 DPTs, 8 digital inputs and}
    \PYG{c+c1}{\PYGZsh{} 8 digital outputs. There can actually be only one HC per}
    \PYG{c+c1}{\PYGZsh{} machine.}
    \PYG{n+nt}{type}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{HC}
    \PYG{n+nt}{address}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{0x0080}
    \PYG{n+nt}{number\PYGZus{}of\PYGZus{}digital\PYGZus{}output\PYGZus{}ports}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{8}
    \PYG{n+nt}{number\PYGZus{}of\PYGZus{}digital\PYGZus{}input\PYGZus{}ports}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{8}
    \PYG{n+nt}{dpt\PYGZus{}resolution}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{10}
    \PYG{n+nt}{dpt\PYGZus{}enumeration}\PYG{p}{:}
      \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ic}
      \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ic}
      \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{ic}
    \PYG{n+nt}{digital\PYGZus{}input}\PYG{p}{:} \PYG{p+pIndicator}{[}\PYG{p+pIndicator}{]}
    \PYG{n+nt}{digital\PYGZus{}output}\PYG{p}{:}
      \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}0}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{icSign}
      \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}1}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{icSign}
      \PYG{p+pIndicator}{\PYGZhy{}} \PYG{n+nt}{INT0\PYGZhy{}2}\PYG{p}{:} \PYG{l+lScalar+lScalarPlain}{icSign}
\end{sphinxVerbatim}

\chapter{PyHyCon}


\section{The Python Hybrid Controller interface}
\label{\detokenize{hycon/hycon:module-hycon.HyCon}}\label{\detokenize{hycon/hycon:the-python-hybrid-controller-interface}}\label{\detokenize{hycon/hycon:hycon}}\label{\detokenize{hycon/hycon::doc}}\index{module@\spxentry{module}!hycon.HyCon@\spxentry{hycon.HyCon}}\index{hycon.HyCon@\spxentry{hycon.HyCon}!module@\spxentry{module}}
PyHyCon \textendash{} a Python Hybrid Controller interface.

Note that the \sphinxcode{\sphinxupquote{IO::HyCon}} Perl 5 module is the reference implementation
that is maintained by the HyConAVR firmware author (Bernd). You can find
the \sphinxcode{\sphinxupquote{IO::HyCon}} Perl module as well as the mentioned Arduino firmware
at \sphinxurl{https://github.com/anabrid/Model-1/tree/main/software/HC}. The Perl
code is also part of the CPAN at \sphinxurl{https://metacpan.org/pod/IO::HyCon}.

While this implementation tries to be API\sphinxhyphen{}compatible with the reference
implementation, it tries to be minimal/low\sphinxhyphen{}level and won’t implement any
client\sphinxhyphen{}side luxury (such as address mapping). It is the task of the
user to implement something high\sphinxhyphen{}level ontop of this.

Especially, the following tasks are implemented by different modules which
can but do not needed to be used:
\begin{itemize}
\item {} 
Connection managament: HyCon just assumes a file handle, but different
connection types are proposed in the \sphinxcode{\sphinxupquote{connections}} module.

\item {} 
Autosetup: PyHyCon is plain python and has no dependency, for instance 
on YAML. There is \sphinxcode{\sphinxupquote{autosetup}} which implements the “autosetup”
functionality of Perl\sphinxhyphen{}HyCon.

\item {} 
High level functionality is implemented on top of HyCon and not within.
See for instance {\hyperref[\detokenize{fpaa/fpaa:module-fpaa}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{fpaa}}}}} (\autopageref*{\detokenize{fpaa/fpaa:module-fpaa}}) for an abstraction which can generate
HyCon instructions and is aware of the circuit design at the same time.

\end{itemize}

The hycon module also includes an interpreter for the HyCon serial stream
“protocol”. See \sphinxcode{\sphinxupquote{replay}} for further details.


\subsection{Logging and Debugging}
\label{\detokenize{hycon/hycon:logging-and-debugging}}
There are several ways to inspect what HyCon is doing. One of the simplest
is to activate logging on \sphinxcode{\sphinxupquote{INFO}} level:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{logging}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{logging}\PYG{o}{.}\PYG{n}{basicConfig}\PYG{p}{(}\PYG{n}{level}\PYG{o}{=}\PYG{n}{logging}\PYG{o}{.}\PYG{n}{INFO}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{c+c1}{\PYGZsh{} proceed here as usual, i.e.: hc = HyCon(...)}
\end{sphinxVerbatim}
\index{ensure() (in module hycon.HyCon)@\spxentry{ensure()}\spxextra{in module hycon.HyCon}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.ensure}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.HyCon.}}\sphinxbfcode{\sphinxupquote{ensure}}}{\emph{\DUrole{n}{var}}, \emph{\DUrole{o}{**}\DUrole{n}{q}}}{}
This is our assert function which is used widely over the code for dynamic
parameter checking. \sphinxcode{\sphinxupquote{q}} stands for \sphinxstyleemphasis{query}. The function will return
silently if the query is fullfilled and raise a \sphinxcode{\sphinxupquote{ValueError}} otherwise.
Examples for success:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ensure}\PYG{p}{(}\PYG{l+m+mi}{42}\PYG{p}{,} \PYG{n}{eq}\PYG{o}{=}\PYG{l+m+mi}{42}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ensure}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{re}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{fo+.*}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ensure}\PYG{p}{(}\PYG{l+m+mi}{17}\PYG{p}{,} \PYG{n}{inrange}\PYG{o}{=}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,}\PYG{l+m+mi}{20}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ensure}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{x}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{within}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{xyz}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ensure}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bla}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{length}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ensure}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{blub}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{isa}\PYG{o}{=}\PYG{n+nb}{str}\PYG{p}{,} \PYG{n}{length}\PYG{o}{=}\PYG{l+m+mi}{4}\PYG{p}{,} \PYG{n}{re}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{b.*}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}

And in case of failure:
\textgreater{}\textgreater{}\textgreater{} ensure(3, within={[}1,2,9{]})
Traceback (most recent call last):
…
ValueError: Got var=3, but it is none of {[}1, 2, 9{]}.

\end{fulllineitems}

\index{expect (class in hycon.HyCon)@\spxentry{expect}\spxextra{class in hycon.HyCon}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.expect}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.HyCon.}}\sphinxbfcode{\sphinxupquote{expect}}}{\emph{\DUrole{o}{**}\DUrole{n}{q}}}{}
\sphinxcode{\sphinxupquote{ensure}} delayed and on stereoids: Can be initialized with a \sphinxcode{\sphinxupquote{query}} (but with
further options) and then called with a \sphinxcode{\sphinxupquote{HyConRequest}}. Will check the \sphinxstyleemphasis{response}
and also allows \sphinxstyleemphasis{return value mapping}, for instance with regexpes or by splitting.
Example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{R} \PYG{o}{=} \PYG{n}{HyConRequest}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{dummy}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{R}\PYG{o}{.}\PYG{n}{response} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{1,2,3}\PYG{l+s+s2}{\PYGZdq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{E} \PYG{o}{=} \PYG{n}{expect}\PYG{p}{(}\PYG{n}{split}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{,}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n+nb}{type}\PYG{o}{=}\PYG{n+nb}{int}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{print}\PYG{p}{(}\PYG{n+nb}{list}\PYG{p}{(}\PYG{n}{E}\PYG{p}{(}\PYG{n}{R}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{[1, 2, 3]}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{wont\_implement() (in module hycon.HyCon)@\spxentry{wont\_implement()}\spxextra{in module hycon.HyCon}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.wont_implement}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.HyCon.}}\sphinxbfcode{\sphinxupquote{wont\_implement}}}{\emph{\DUrole{n}{reason}}}{}
Will not implement: Returns a function which raises \sphinxcode{\sphinxupquote{NotImplementedError(reason)}} when called.

\end{fulllineitems}

\index{HyConRequest (class in hycon.HyCon)@\spxentry{HyConRequest}\spxextra{class in hycon.HyCon}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyConRequest}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.HyCon.}}\sphinxbfcode{\sphinxupquote{HyConRequest}}}{\emph{\DUrole{n}{command}}, \emph{\DUrole{n}{expected\_response}\DUrole{o}{=}\DUrole{default_value}{None}}}{}
A HyConRequest models a single \sphinxstyleemphasis{request} and \sphinxstyleemphasis{response} cycle. It stores the ASCII \sphinxcode{\sphinxupquote{command}}
emitted by the HyCon and can save a \sphinxstyleemphasis{expected response} future/promise (see \sphinxcode{\sphinxupquote{expect}} class).
A HyConRequest can only be made once. If you want to do it several times, you have to (deep)
copy the instance.
\index{write() (hycon.HyCon.HyConRequest method)@\spxentry{write()}\spxextra{hycon.HyCon.HyConRequest method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyConRequest.write}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{write}}}{\emph{\DUrole{n}{hycon}}}{}
Run this request. Can only be executed once. Can be chained.

\end{fulllineitems}

\index{read() (hycon.HyCon.HyConRequest method)@\spxentry{read()}\spxextra{hycon.HyCon.HyConRequest method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyConRequest.read}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read}}}{\emph{\DUrole{n}{hycon}}, \emph{\DUrole{n}{expected\_response}\DUrole{o}{=}\DUrole{default_value}{None}}, \emph{\DUrole{n}{read\_again}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Read response from HyCon. If \sphinxstyleemphasis{read\_again} is given, will read several times. Can be chained.

\end{fulllineitems}


\end{fulllineitems}

\index{HyCon (class in hycon.HyCon)@\spxentry{HyCon}\spxextra{class in hycon.HyCon}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.HyCon.}}\sphinxbfcode{\sphinxupquote{HyCon}}}{\emph{\DUrole{n}{fh}}, \emph{\DUrole{n}{unidirectional}\DUrole{o}{=}\DUrole{default_value}{False}}}{}
Low\sphinxhyphen{}Level Hybrid Controller OOP interface, similar to the Perl Hybrid controller.

This is a minimalistic implementation which tries to implement all neccessary checking
of input/output request/reply structure correctness, but won’t do any \sphinxstyleemphasis{high level}
support for applications. Users are assumed to write such code on themselves. The PyFPAA
library is an example for a high level “frontend” against HyCon, which includes a
circuit understanding, etc.
\index{query() (hycon.HyCon.HyCon method)@\spxentry{query()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.query}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{query}}}{\emph{\DUrole{o}{*}\DUrole{n}{args}}, \emph{\DUrole{o}{**}\DUrole{n}{kwargs}}}{}
Create a request, run it and check the reply

\end{fulllineitems}

\index{command() (hycon.HyCon.HyCon method)@\spxentry{command()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.command}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{command}}}{\emph{\DUrole{o}{*}}, \emph{\DUrole{n}{help}\DUrole{o}{=}\DUrole{default_value}{None}}, \emph{\DUrole{o}{**}\DUrole{n}{kwargs}}}{}
Return a method which, when called, creates a request, runs it and checks the reply

\end{fulllineitems}

\index{ic() (hycon.HyCon.HyCon method)@\spxentry{ic()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.ic}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{ic}}}{}{}
Switch AC to IC\sphinxhyphen{}mode

\end{fulllineitems}

\index{op() (hycon.HyCon.HyCon method)@\spxentry{op()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.op}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{op}}}{}{}
Switch AC to OP\sphinxhyphen{}mode

\end{fulllineitems}

\index{halt() (hycon.HyCon.HyCon method)@\spxentry{halt()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.halt}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{halt}}}{}{}
Switch AC to HALT\sphinxhyphen{}mode

\end{fulllineitems}

\index{disable\_ovl\_halt() (hycon.HyCon.HyCon method)@\spxentry{disable\_ovl\_halt()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.disable_ovl_halt}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{disable\_ovl\_halt}}}{}{}
Disable HALT\sphinxhyphen{}on\sphinxhyphen{}overflow

\end{fulllineitems}

\index{enable\_ovl\_halt() (hycon.HyCon.HyCon method)@\spxentry{enable\_ovl\_halt()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.enable_ovl_halt}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{enable\_ovl\_halt}}}{}{}
Enable HALT\sphinxhyphen{}on\sphinxhyphen{}overflow

\end{fulllineitems}

\index{disable\_ext\_halt() (hycon.HyCon.HyCon method)@\spxentry{disable\_ext\_halt()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.disable_ext_halt}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{disable\_ext\_halt}}}{}{}
Disable external HALT

\end{fulllineitems}

\index{enable\_ext\_halt() (hycon.HyCon.HyCon method)@\spxentry{enable\_ext\_halt()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.enable_ext_halt}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{enable\_ext\_halt}}}{}{}
Enable external HALT

\end{fulllineitems}

\index{repetitive\_run() (hycon.HyCon.HyCon method)@\spxentry{repetitive\_run()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.repetitive_run}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{repetitive\_run}}}{}{}
Switch to RepOp

\end{fulllineitems}

\index{single\_run() (hycon.HyCon.HyCon method)@\spxentry{single\_run()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.single_run}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{single\_run}}}{}{}
One IC\sphinxhyphen{}OP\sphinxhyphen{}HALT\sphinxhyphen{}cycle

\end{fulllineitems}

\index{pot\_set() (hycon.HyCon.HyCon method)@\spxentry{pot\_set()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.pot_set}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{pot\_set}}}{}{}
Activate POTSET\sphinxhyphen{}mode

\end{fulllineitems}

\index{single\_run\_sync() (hycon.HyCon.HyCon method)@\spxentry{single\_run\_sync()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.single_run_sync}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{single\_run\_sync}}}{}{}
Synchronous run (finishes after a single run finished). Return value is true if terminated by ext. halt condition

\end{fulllineitems}

\index{set\_ic\_time() (hycon.HyCon.HyCon method)@\spxentry{set\_ic\_time()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.set_ic_time}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{set\_ic\_time}}}{\emph{\DUrole{n}{ictime}}}{}
Sets IC (initial condition) time in MILLISECONDS.

\end{fulllineitems}

\index{set\_op\_time() (hycon.HyCon.HyCon method)@\spxentry{set\_op\_time()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.set_op_time}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{set\_op\_time}}}{\emph{\DUrole{n}{optime}}}{}
Sets OP (operation mode) time in MILLISECONDS

\end{fulllineitems}

\index{get\_data() (hycon.HyCon.HyCon method)@\spxentry{get\_data()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.get_data}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{get\_data}}}{}{}
Supposed to be called when a read out group is defined and the machine is in (synchronous) OP mode.

\end{fulllineitems}

\index{read\_element\_by\_address() (hycon.HyCon.HyCon method)@\spxentry{read\_element\_by\_address()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_element_by_address}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_element\_by\_address}}}{\emph{\DUrole{n}{address}}}{}
Read any machine element voltage. Expecting 16\sphinxhyphen{}bit element address as integer.

\end{fulllineitems}

\index{set\_ro\_group() (hycon.HyCon.HyCon method)@\spxentry{set\_ro\_group()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.set_ro_group}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{set\_ro\_group}}}{\emph{\DUrole{n}{addresses}}}{}
Defines a read out group, expects addresses to be an integer list of 16\sphinxhyphen{}bit element addresses.

\end{fulllineitems}

\index{read\_ro\_group() (hycon.HyCon.HyCon method)@\spxentry{read\_ro\_group()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_ro_group}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_ro\_group}}}{}{}
Query for currently set read out group

\end{fulllineitems}

\index{read\_digital() (hycon.HyCon.HyCon method)@\spxentry{read\_digital()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_digital}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_digital}}}{}{}
Read digital inputs

\end{fulllineitems}

\index{digital\_output() (hycon.HyCon.HyCon method)@\spxentry{digital\_output()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.digital_output}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{digital\_output}}}{\emph{\DUrole{n}{port}}, \emph{\DUrole{n}{state}}}{}
Set digital output pins of the Hybrid Controller

\end{fulllineitems}

\index{set\_xbar() (hycon.HyCon.HyCon method)@\spxentry{set\_xbar()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.set_xbar}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{set\_xbar}}}{\emph{\DUrole{n}{address}}, \emph{\DUrole{n}{config}}}{}
Exactly \{self.XBAR\_CONFIG\_BYTES*2\} HEX\sphinxhyphen{}nibbles are required to config data.

\end{fulllineitems}

\index{read\_mpts() (hycon.HyCon.HyCon method)@\spxentry{read\_mpts()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_mpts}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_mpts}}}{\emph{\DUrole{o}{**}\DUrole{n}{kw}}}{}
\sphinxstyleemphasis{Not implemented} because because it is just a high\sphinxhyphen{}level function which calls pot\_set and iterates a list of potentiometer address/names.

\end{fulllineitems}

\index{set\_pt() (hycon.HyCon.HyCon method)@\spxentry{set\_pt()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.set_pt}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{set\_pt}}}{\emph{\DUrole{n}{address}}, \emph{\DUrole{n}{number}}, \emph{\DUrole{n}{value}}}{}
Set a digital potentiometer by address/number.

\end{fulllineitems}

\index{read\_dpts() (hycon.HyCon.HyCon method)@\spxentry{read\_dpts()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_dpts}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_dpts}}}{}{}
Asks the Hybridcontroller for reading out \sphinxstyleemphasis{all} DPTs in the machine (also DPT24 modules).
Returns mapping of PT module to list of values in that module.

\end{fulllineitems}

\index{get\_status() (hycon.HyCon.HyCon method)@\spxentry{get\_status()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.get_status}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{get\_status}}}{}{}
Queries the HybridController about it’s current status. Will return a dictionary.

\end{fulllineitems}

\index{get\_op\_time() (hycon.HyCon.HyCon method)@\spxentry{get\_op\_time()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.get_op_time}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{get\_op\_time}}}{}{}
Asks about current OP time

\end{fulllineitems}

\index{reset() (hycon.HyCon.HyCon method)@\spxentry{reset()}\spxextra{hycon.HyCon.HyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.HyCon.HyCon.reset}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{reset}}}{}{}
Resets the HybridController (has no effect on python instance itself)

\end{fulllineitems}


\end{fulllineitems}



\subsection{Connection managers}
\label{\detokenize{hycon/hycon:module-hycon.connections}}\label{\detokenize{hycon/hycon:connection-managers}}\index{module@\spxentry{module}!hycon.connections@\spxentry{hycon.connections}}\index{hycon.connections@\spxentry{hycon.connections}!module@\spxentry{module}}
Connection or “backends” for the PyHyCon.

The \sphinxcode{\sphinxupquote{HyCon.HyCon}} class requires a file handle to be passed. Usually, file
APIs are cursed in many languages (also python), but you can get your way out
with the following examples and also classes in this module.

Tested or “proven” connection interfaces are:
\begin{itemize}
\item {} 
{\hyperref[\detokenize{hycon/hycon:hycon.connections.tcpsocket}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{tcpsocket}}}}} (\autopageref*{\detokenize{hycon/hycon:hycon.connections.tcpsocket}}): A small adapter for the \sphinxcode{\sphinxupquote{socket()}} python builtin.

\item {} 
{\hyperref[\detokenize{hycon/hycon:hycon.connections.human}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{human}}}}} (\autopageref*{\detokenize{hycon/hycon:hycon.connections.human}}): A small dummy adapter which prints to the interactive user terminal session
and expects commands from there (the naming is ironically pointing to the human acting as
actual Hybrid controller hardware endpoint).

\end{itemize}

Somewhat experimental but known to work is especially for unidirectional access:
\begin{itemize}
\item {} 
\sphinxcode{\sphinxupquote{StringIO.StringIO}}: Circumventing file access by reading from/to strings.

\item {} 
\sphinxcode{\sphinxupquote{sys.stdout}} for just dumping HyCon\sphinxhyphen{}generated instructions

\end{itemize}

\begin{sphinxadmonition}{note}{Note:}
All functions in this module do some progress reporting if you enable python logging
facilities. Do so with

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{logging}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{logging}\PYG{o}{.}\PYG{n}{basicConfig}\PYG{p}{(}\PYG{n}{level}\PYG{o}{=}\PYG{n}{logging}\PYG{o}{.}\PYG{n}{INFO}\PYG{p}{)}
\end{sphinxVerbatim}
\end{sphinxadmonition}


\subsubsection{Usage Examples}
\label{\detokenize{hycon/hycon:usage-examples}}
The following examples are suitable to be run in an interactive python REPL to explore
the APIs.


\paragraph{Using PyHyCon with a microcontroller “simulator”}
\label{\detokenize{hycon/hycon:using-pyhycon-with-a-microcontroller-simulator}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{hycon} \PYG{k+kn}{import} \PYG{n}{HyCon}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac} \PYG{o}{=} \PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{human}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}                                                                                            
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{set\PYGZus{}ic\PYGZus{}time}\PYG{p}{(}\PYG{l+m+mi}{1234}\PYG{p}{)}                                  
\PYG{g+go}{\PYGZlt{}\PYGZlt{} Sending [C001234] to uC}
\PYG{g+go}{[type reply of uC]\PYGZgt{}\PYGZgt{} T\PYGZus{}IC=1234}
\PYG{g+go}{HyConRequest(C001234, expect(eq: T\PYGZus{}IC=1234), self.executed=True, response=T\PYGZus{}IC=1234, reply=T\PYGZus{}IC=1234)}
\end{sphinxVerbatim}


\paragraph{Using PyHyCon only for writing firmware commands}
\label{\detokenize{hycon/hycon:using-pyhycon-only-for-writing-firmware-commands}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{hycon}\PYG{o}{,} \PYG{n+nn}{sys}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac} \PYG{o}{=} \PYG{n}{hycon}\PYG{o}{.}\PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{sys}\PYG{o}{.}\PYG{n}{stdout}\PYG{p}{,} \PYG{n}{unidirectional}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{set\PYGZus{}ic\PYGZus{}time}\PYG{p}{(}\PYG{l+m+mi}{234}\PYG{p}{)}
\PYG{g+go}{C000234HyConRequest(C000234, expect(eq: T\PYGZus{}IC=234), self.executed=True, response=n.a., reply=n.a.)}
\end{sphinxVerbatim}

Such a unidirectional approach can be interesting when generating bitstreams, for
larger integration tests, etc.


\paragraph{Using PyHyCon over TCP/IP}
\label{\detokenize{hycon/hycon:using-pyhycon-over-tcp-ip}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{sock} \PYG{o}{=} \PYG{n}{tcpsocket}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{localhost}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+m+mi}{12345}\PYG{p}{)}                 
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac} \PYG{o}{=} \PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{sock}\PYG{p}{)}                                     
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{reset}\PYG{p}{(}\PYG{p}{)}                                           
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{digital\PYGZus{}output}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{k+kc}{True}\PYG{p}{)}                           
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{set\PYGZus{}op\PYGZus{}time}\PYG{p}{(}\PYG{l+m+mi}{123}\PYG{p}{)}                                  
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{set\PYGZus{}xbar}\PYG{p}{(}\PYG{l+m+mh}{0x0040}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{0000000210840000781B}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}          
\end{sphinxVerbatim}

This setup is particularly interesting when connecting network\sphinxhyphen{}transparently to
actual hardware. The target TCP server is expected to route the contents to a
serial port/USB UART without introducing buffering. Examples for this kind of
stub servers are given at {\color{red}\bfseries{}networking\sphinxhyphen{}hc\_}.


\paragraph{Using PyHyCon over Serial}
\label{\detokenize{hycon/hycon:using-pyhycon-over-serial}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fh} \PYG{o}{=} \PYG{n}{serial}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{/dev/ttyUSB0}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+m+mi}{115200}\PYG{p}{)}                     
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac} \PYG{o}{=} \PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{fh}\PYG{p}{)}                                          
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac}\PYG{o}{.}\PYG{n}{digital\PYGZus{}output}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{k+kc}{True}\PYG{p}{)}                              
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{c+c1}{\PYGZsh{} etc.}
\end{sphinxVerbatim}

You are encouraged to use the {\hyperref[\detokenize{hycon/hycon:hycon.connections.serial}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{serial}}}}} (\autopageref*{\detokenize{hycon/hycon:hycon.connections.serial}}) class, which uses
\sphinxhref{https://pythonhosted.org/pyserial/}{PySerial}%
\begin{footnote}[81]\sphinxAtStartFootnote
\sphinxnolinkurl{https://pythonhosted.org/pyserial/}
%
\end{footnote} under the hood and does the
clearing/resetting of the stream for you (something which is more cumbersome over serial
then over TCP).

If you really want, you can also use PySerial directly:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{Serial} \PYG{k+kn}{from} \PYG{n+nn}{serial}                               
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fh} \PYG{o}{=} \PYG{n}{Serial}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{/dev/ttyUSB0}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+m+mi}{115200}\PYG{p}{)}                     
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac} \PYG{o}{=} \PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{fh}\PYG{p}{)}                                          
\end{sphinxVerbatim}

Note that this approach suffers from binary/string conversions, but you could
probably wrap \sphinxcode{\sphinxupquote{open(fh)}} in some text mode.

If you (also) do not like PySerial, you can connect to a char device on a unixoid
operating system with vanilla python (this example is kind\sphinxhyphen{}of\sphinxhyphen{}untested):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{os}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fd} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{/dev/ttyUSB0}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{os}\PYG{o}{.}\PYG{n}{O\PYGZus{}RDWR} \PYG{o}{|} \PYG{n}{os}\PYG{o}{.}\PYG{n}{O\PYGZus{}NOCTTY}\PYG{p}{)}      
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fh} \PYG{o}{=} \PYG{n}{os}\PYG{o}{.}\PYG{n}{fdopen}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{fd}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{wb+}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{buffering}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{)}                
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{ac} \PYG{o}{=} \PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{fh}\PYG{p}{)}                                             
\end{sphinxVerbatim}

In this case, you certainly want to set the connection parameters (baud rate, etc.) by
\sphinxcode{\sphinxupquote{ioctl}}, for instance in before on your linux terminal using a command
like \sphinxcode{\sphinxupquote{stty \sphinxhyphen{}F /dev/ttyUSB0 115200}}, or with \sphinxcode{\sphinxupquote{stty ospeed 115200}}
and \sphinxcode{\sphinxupquote{stty ispeed 115200}} on Mac. Furthermore, when using this approach, consider
writing a small wrapper which runs \sphinxcode{\sphinxupquote{fh.flush()}} after writing.
\index{repeated\_reset() (in module hycon.connections)@\spxentry{repeated\_reset()}\spxextra{in module hycon.connections}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.connections.repeated_reset}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.connections.}}\sphinxbfcode{\sphinxupquote{repeated\_reset}}}{\emph{\DUrole{n}{fh}}}{}
This routine tries to \sphinxstyleemphasis{clear} output buffers of the hycon UART by sending repeated
reset instructions and waiting until the reply “RESET” appears on the line. Doing this,
it implements the HyCon protocol, but the \sphinxcode{\sphinxupquote{HyCon}} code does not deal with
connection issues, which is why this function is aprt of \sphinxcode{\sphinxupquote{connections}}.

Calling this function on beginning the setup is recommended for direct serial
connections.

You can also call to this method with the {\color{red}\bfseries{}:fun:\textasciigrave{}HyCon.HyCon.repeated\_reset()\textasciigrave{}} shorthand.

This function returns \sphinxcode{\sphinxupquote{True}} when the connection suceeded, else \sphinxcode{\sphinxupquote{False}}.

\end{fulllineitems}

\index{human (class in hycon.connections)@\spxentry{human}\spxextra{class in hycon.connections}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.connections.human}}\pysigline{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.connections.}}\sphinxbfcode{\sphinxupquote{human}}}
Dummy IOWrapper for testing HyCon.py without the actual hardware

\end{fulllineitems}

\index{tcpsocket (class in hycon.connections)@\spxentry{tcpsocket}\spxextra{class in hycon.connections}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.connections.tcpsocket}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.connections.}}\sphinxbfcode{\sphinxupquote{tcpsocket}}}{\emph{\DUrole{n}{host}}, \emph{\DUrole{n}{port}}}{}
Wrapper for communicating with HyCon over TCP/IP. See also HyCon\sphinxhyphen{}over\sphinxhyphen{}TCP.README for further instructions
\index{write() (hycon.connections.tcpsocket method)@\spxentry{write()}\spxextra{hycon.connections.tcpsocket method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.connections.tcpsocket.write}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{write}}}{\emph{\DUrole{n}{sth}}}{}
Expects sth to be a string

\end{fulllineitems}


\end{fulllineitems}

\index{serial (class in hycon.connections)@\spxentry{serial}\spxextra{class in hycon.connections}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.connections.serial}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.connections.}}\sphinxbfcode{\sphinxupquote{serial}}}{\emph{\DUrole{n}{port}}, \emph{\DUrole{n}{baudrate}}, \emph{\DUrole{o}{**}\DUrole{n}{passed\_options}}}{}
Small wrapper for making the use of PySerial more handy (no need for extra import)

\end{fulllineitems}



\subsection{Autosetup features}
\label{\detokenize{hycon/hycon:module-hycon.autosetup}}\label{\detokenize{hycon/hycon:autosetup-features}}\index{module@\spxentry{module}!hycon.autosetup@\spxentry{hycon.autosetup}}\index{hycon.autosetup@\spxentry{hycon.autosetup}!module@\spxentry{module}}
The autosetup module of the hycon package is the python implementation of the
similar named feature of the Perl HyCon library.

It is used to setup a hybrid controller based from a YAML file which includes
a mapping from names to computing element and potentiometer addresses and
a problem description containing information about timing, potentiometer
values (coefficients) and a readout group of interest. It can also describe
the configuration of an XBAR module.

The idea of this YAML file is to describe the analog circuit as complete as
possible, to keep the steering hycon code in perl (or python, respectively)
short. Furthermore, it brings some kind of highlevel description of the
circuit, since many parts of the circuit are given names.

This idea is some intermediate idea to the pyFPAA code which I wrote. It can
be seen as an alternative high\sphinxhyphen{}level frontend to pyHyCon. Remember, the idiom
of pyHyCon is to provide only a lowest level API for interaction with the
hardware hybrid controller.

About the history of this code: Bernd started to write his auto\sphinxhyphen{}setup code
at 25\sphinxhyphen{}DEC\sphinxhyphen{}2019. I started to write my pyFPAA code at the same time. Roughly
one year later, where most of the time was spent at other stuff, I now port
parts of Bernds auto\sphinxhyphen{}setup code to python in order to be able to use the
same YAML files.
\index{DotDict (class in hycon.autosetup)@\spxentry{DotDict}\spxextra{class in hycon.autosetup}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.DotDict}}\pysigline{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.autosetup.}}\sphinxbfcode{\sphinxupquote{DotDict}}}
Small syntactic sugar: Dot notation to access to dictionary attributes, which is especially
handy for deeply nested dicts. There are plenty of similar library for python around, but
this implementation is only five lines (yes, five). The following usage example is longer
then the implementation:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a} \PYG{o}{=} \PYG{p}{\PYGZob{}} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{b}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mi}{42}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{non\PYGZhy{}identifier}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{p}{\PYGZob{}} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{:} \PYG{p}{\PYGZob{}} \PYG{l+m+mi}{3}\PYG{p}{:} \PYG{l+m+mi}{123} \PYG{p}{\PYGZcb{}} \PYG{p}{\PYGZcb{}}\PYG{p}{\PYGZcb{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a} \PYG{o}{=} \PYG{n}{DotDict}\PYG{p}{(}\PYG{n}{a}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{o}{.}\PYG{n}{b}
\PYG{g+go}{42}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{o}{.}\PYG{n}{foo}\PYG{o}{.}\PYG{n}{bar}
\PYG{g+go}{\PYGZob{}3: 123\PYGZcb{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{non\PYGZhy{}identifier}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{]}   \PYG{c+c1}{\PYGZsh{} traditional \PYGZus{}\PYGZus{}getitem\PYGZus{}\PYGZus{} access is still possible}
\PYG{g+go}{3}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{o}{.}\PYG{n}{foo}\PYG{o}{.}\PYG{n}{bar}\PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{]}          \PYG{c+c1}{\PYGZsh{} especially hand for non\PYGZhy{}pure\PYGZhy{}ascii identifiers}
\PYG{g+go}{123}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{DotDict}\PYG{p}{(}\PYG{n}{DotDict}\PYG{p}{(}\PYG{n}{a}\PYG{p}{)}\PYG{p}{)}\PYG{o}{.}\PYG{n}{b} \PYG{c+c1}{\PYGZsh{} DotDict can be applied repeatedly without loss of functionality}
\PYG{g+go}{42}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{c} \PYG{o}{=} \PYG{n}{DotDict}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{c}\PYG{o}{.}\PYG{n}{foo} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{b}\PYG{l+s+s2}{\PYGZdq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{c}                     \PYG{c+c1}{\PYGZsh{} also works for setting, not only reading}
\PYG{g+go}{\PYGZob{}\PYGZsq{}foo\PYGZsq{}: \PYGZsq{}b\PYGZsq{}\PYGZcb{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{c}\PYG{o}{.}\PYG{n}{bar} \PYG{o}{=} \PYG{n}{DotDict}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{c}\PYG{o}{.}\PYG{n}{bar}\PYG{o}{.}\PYG{n}{baz} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bla}\PYG{l+s+s2}{\PYGZdq{}}     \PYG{c+c1}{\PYGZsh{} Limitation for nested setting: create nested DotDicts first.}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{PotentiometerAddress (class in hycon.autosetup)@\spxentry{PotentiometerAddress}\spxextra{class in hycon.autosetup}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.PotentiometerAddress}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.autosetup.}}\sphinxbfcode{\sphinxupquote{PotentiometerAddress}}}{\emph{\DUrole{n}{address}}, \emph{\DUrole{n}{number}}}{}
Stores a potentiometer address, which is a tuple of a (typically hex\sphinxhyphen{}given) bus address
of the hardware element and an element\sphinxhyphen{}internal number. Example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a} \PYG{o}{=} \PYG{n}{PotentiometerAddress}\PYG{p}{(}\PYG{l+m+mh}{0x200}\PYG{p}{,} \PYG{l+m+mh}{0x20}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{b} \PYG{o}{=} \PYG{n}{PotentiometerAddress}\PYG{o}{.}\PYG{n}{fromText}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{0x200/20}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}  \PYG{c+c1}{\PYGZsh{} FIXME: Is number really base 16?}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a} \PYG{o}{==} \PYG{n}{b}
\PYG{g+go}{True}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{o}{.}\PYG{n}{address}   \PYG{c+c1}{\PYGZsh{} Don\PYGZsq{}t forget that python standard numeric output is in decimal}
\PYG{g+go}{512}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{a}\PYG{o}{.}\PYG{n}{toText}\PYG{p}{(}\PYG{p}{)}
\PYG{g+go}{\PYGZsq{}0x200/20\PYGZsq{}}
\end{sphinxVerbatim}
\index{fromText() (hycon.autosetup.PotentiometerAddress class method)@\spxentry{fromText()}\spxextra{hycon.autosetup.PotentiometerAddress class method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.PotentiometerAddress.fromText}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{classmethod }}\sphinxbfcode{\sphinxupquote{fromText}}}{\emph{\DUrole{n}{text}}}{}
Parses something like 0x200/2 to (0x200, 2). Will also accept 0200/2 as hex.

\end{fulllineitems}


\end{fulllineitems}

\index{autosetup() (in module hycon.autosetup)@\spxentry{autosetup()}\spxextra{in module hycon.autosetup}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.autosetup}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.autosetup.}}\sphinxbfcode{\sphinxupquote{autosetup}}}{\emph{\DUrole{n}{hycon}}, \emph{\DUrole{n}{conf}}, \emph{\DUrole{n}{reset}\DUrole{o}{=}\DUrole{default_value}{True}}}{}
hycon is expected to be an instance of HyCon.
conf is expected to be a dictionary.

If you want to load from a YAML file, use the yaml\_load function.

TODO: XBAR support not yet implemented.

\end{fulllineitems}

\index{autoconnect() (in module hycon.autosetup)@\spxentry{autoconnect()}\spxextra{in module hycon.autosetup}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.autoconnect}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.autosetup.}}\sphinxbfcode{\sphinxupquote{autoconnect}}}{\emph{\DUrole{n}{conf}}}{}
Opens a file handle to the target position found in the YAML file. Follows the same
rules as the perl routine, i.e. looks for \sphinxstyleemphasis{serial} or \sphinxstyleemphasis{tcp} key and connects
according to the parameters.

Example serial port configuration:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{serial}\PYG{p}{:}
  \PYG{n}{port}\PYG{p}{:} \PYG{o}{/}\PYG{n}{dev}\PYG{o}{/}\PYG{n}{cu}\PYG{o}{.}\PYG{n}{usbserial}\PYG{o}{\PYGZhy{}}\PYG{n}{DN050L21}
  \PYG{n}{bits}\PYG{p}{:} \PYG{l+m+mi}{8}
  \PYG{n}{baud}\PYG{p}{:} \PYG{l+m+mi}{250000}
  \PYG{n}{parity}\PYG{p}{:} \PYG{n}{none}
  \PYG{n}{stopbits}\PYG{p}{:} \PYG{l+m+mi}{1}
  \PYG{n}{poll\PYGZus{}interval}\PYG{p}{:} \PYG{l+m+mi}{10}
  \PYG{n}{poll\PYGZus{}attempts}\PYG{p}{:} \PYG{l+m+mi}{20000}
\end{sphinxVerbatim}

Note that we only take into account port and baud rate, since everything else looks standard
and the pySerial port cannot deal with an integer stopbit \sphinxcode{\sphinxupquote{1}} but expects something like \sphinxcode{\sphinxupquote{serial.STOPBITS\_ONE}}.
As a note to the future, \sphinxurl{https://tools.ietf.org/html/rfc2217.html} is supported by pySerial and
should be adopted by the YAML definition.,

Example TCP port configuration:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{tcp}\PYG{p}{:}
    \PYG{n}{addr}\PYG{p}{:} \PYG{l+m+mf}{192.168}\PYG{o}{.}\PYG{l+m+mf}{31.190}
    \PYG{n}{port}\PYG{p}{:} \PYG{l+m+mi}{12345}
    \PYG{n}{connection\PYGZus{}timeout}\PYG{p}{:} \PYG{l+m+mi}{2}
    \PYG{n}{timeout}\PYG{p}{:} \PYG{l+m+mf}{0.1}
    \PYG{n}{poll\PYGZus{}interval}\PYG{p}{:} \PYG{l+m+mi}{10}
    \PYG{n}{poll\PYGZus{}attempts}\PYG{p}{:} \PYG{l+m+mi}{2000}
    \PYG{n}{quick\PYGZus{}start}\PYG{p}{:} \PYG{k+kc}{False}
\end{sphinxVerbatim}

Again, we only take into account the IP address and the TCP port, everything else is ignored for the
time being.

\end{fulllineitems}

\index{AutoConfHyCon (class in hycon.autosetup)@\spxentry{AutoConfHyCon}\spxextra{class in hycon.autosetup}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.AutoConfHyCon}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.autosetup.}}\sphinxbfcode{\sphinxupquote{AutoConfHyCon}}}{\emph{\DUrole{n}{conf}}}{}
Syntactic sugar to provide a “setup” method similar to the perl
HyCon API.

TODO: Should also provide other methods for high level value read
and set access.

\sphinxcode{\sphinxupquote{conf}} can either be a string holding the YAML filename  or a dictionary (holding the
configuration content, i.e. parsed YAML file).
\index{get\_data\_by\_name() (hycon.autosetup.AutoConfHyCon method)@\spxentry{get\_data\_by\_name()}\spxextra{hycon.autosetup.AutoConfHyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.AutoConfHyCon.get_data_by_name}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{get\_data\_by\_name}}}{}{}
Get readout group data handily labeled by name

\end{fulllineitems}

\index{set\_pt\_by\_name() (hycon.autosetup.AutoConfHyCon method)@\spxentry{set\_pt\_by\_name()}\spxextra{hycon.autosetup.AutoConfHyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.AutoConfHyCon.set_pt_by_name}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{set\_pt\_by\_name}}}{\emph{\DUrole{n}{name}}, \emph{\DUrole{n}{value}}}{}
Set a digital potentiometer by name

\end{fulllineitems}

\index{read\_element\_by\_name() (hycon.autosetup.AutoConfHyCon method)@\spxentry{read\_element\_by\_name()}\spxextra{hycon.autosetup.AutoConfHyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.AutoConfHyCon.read_element_by_name}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_element\_by\_name}}}{\emph{\DUrole{n}{name}}}{}
Reads element by name

\end{fulllineitems}

\index{read\_dpts\_by\_name() (hycon.autosetup.AutoConfHyCon method)@\spxentry{read\_dpts\_by\_name()}\spxextra{hycon.autosetup.AutoConfHyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.AutoConfHyCon.read_dpts_by_name}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_dpts\_by\_name}}}{}{}
Asks the Hybridcontroller for reading out \sphinxstyleemphasis{all} DPTs in the machine (also DPT24 modules).
Returns single map of DPT name to value (as float).

\end{fulllineitems}

\index{read\_ro\_group\_by\_name() (hycon.autosetup.AutoConfHyCon method)@\spxentry{read\_ro\_group\_by\_name()}\spxextra{hycon.autosetup.AutoConfHyCon method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.autosetup.AutoConfHyCon.read_ro_group_by_name}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_ro\_group\_by\_name}}}{}{}
Returns an OrderedDict of read\sphinxhyphen{}out group elements, with names

\end{fulllineitems}


\end{fulllineitems}



\subsection{Protocol Replay features}
\label{\detokenize{hycon/hycon:module-hycon.replay}}\label{\detokenize{hycon/hycon:protocol-replay-features}}\index{module@\spxentry{module}!hycon.replay@\spxentry{hycon.replay}}\index{hycon.replay@\spxentry{hycon.replay}!module@\spxentry{module}}
A HyCon command stream interpreter.

Will spill out LISP\sphinxhyphen{}like commands which can be fed into the hycon
again. This allows for replaying, which is helpful for a number of 
special scenarios such as:
\begin{itemize}
\item {} 
Offline\sphinxhyphen{}validating a HyCon instruction stream

\item {} 
Man\sphinxhyphen{}in\sphinxhyphen{}the\sphinxhyphen{}middle inspecting an HyCon instruction stream

\item {} 
Validating the correctness of high\sphinxhyphen{}level HyCon instructions
(such as emitted by the PyFPAA or autosetup codes)

\end{itemize}

The code basically implements a character\sphinxhyphen{}by\sphinxhyphen{}character tokenizer/parser.
It is built based on a simple mapping datastructure which assigns each
one\sphinxhyphen{}letter command the respective PyHyCon method name. Furthermore,
method arguments can be read and converted.

It would be nice to join HyCon.py and replay.py to a single file which
translates between the serial protocol and the OOP API calls. The transformation
is quite trivial, but now we have a lot of code doing nothing of 
bigger interest.

The ordering follows the AVR Ino code.
\index{delayed() (in module hycon.replay)@\spxentry{delayed()}\spxextra{in module hycon.replay}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.replay.delayed}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.replay.}}\sphinxbfcode{\sphinxupquote{delayed}}}{\emph{\DUrole{n}{static\_method}}}{}
This is a decorator for a static method in a class. It will
make the function body “delayed”, i.e. when calling the function,
a future/promise/delay/deferred element is returned.
Some parameter bounding (closure) happens: The decorated arguments
are evaluated early while the later execution expects only a single
reader argument. Example to follow the logic:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{f} \PYG{o}{=} \PYG{k}{lambda} \PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{,}\PYG{n}{c}\PYG{p}{,}\PYG{n}{d}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{,}\PYG{n}{c}\PYG{p}{,}\PYG{n}{d}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{g} \PYG{o}{=} \PYG{n}{delayed}\PYG{p}{(}\PYG{n}{f}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{h} \PYG{o}{=} \PYG{n}{g}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{h}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}
\PYG{g+go}{4 1 2 3}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{consume (class in hycon.replay)@\spxentry{consume}\spxextra{class in hycon.replay}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.replay.consume}}\pysigline{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.replay.}}\sphinxbfcode{\sphinxupquote{consume}}}
Consume is an ugly namespace and not a class, actually.
The basic idea of these (static!) functions is to be
called delayedly with a function as it’s argument which
acts like the io.IOBase.read() function, i.e. advances
an internal cursor (side effect) and returns \sphinxstyleemphasis{n} characters
from the stream. Crude Example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{tokenizer} \PYG{o}{=} \PYG{p}{[}\PYG{n}{consume}\PYG{o}{.}\PYG{n}{exact}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{test}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{consume}\PYG{o}{.}\PYG{n}{decimals}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{)}\PYG{p}{,} \PYG{n}{consume}\PYG{o}{.}\PYG{n}{exact}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{foo}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{consume}\PYG{o}{.}\PYG{n}{hex}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)}\PYG{p}{]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{test} \PYG{o}{=} \PYG{n}{io}\PYG{o}{.}\PYG{n}{StringIO}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{test123fooAA}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{reader} \PYG{o}{=} \PYG{n}{test}\PYG{o}{.}\PYG{n}{read}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{p}{[} \PYG{n}{token}\PYG{p}{(}\PYG{n}{reader}\PYG{p}{)} \PYG{k}{for} \PYG{n}{token} \PYG{o+ow}{in} \PYG{n}{tokenizer} \PYG{p}{]}
\PYG{g+go}{[\PYGZsq{}test\PYGZsq{}, 123, \PYGZsq{}foo\PYGZsq{}, 170]}
\end{sphinxVerbatim}
\index{number() (hycon.replay.consume method)@\spxentry{number()}\spxextra{hycon.replay.consume method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.replay.consume.number}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{number}}}{\emph{\DUrole{n}{digits}}, \emph{\DUrole{n}{base}}, \emph{\DUrole{n}{multiply}\DUrole{o}{=}\DUrole{default_value}{1}}}{}
Reads a number with \#digit digits in some base. Can perform a multiplication afterwards.

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{consume}\PYG{o}{.}\PYG{n}{number}\PYG{p}{(}\PYG{l+m+mi}{8}\PYG{p}{,}\PYG{l+m+mi}{16}\PYG{p}{)}\PYG{p}{(}\PYG{n}{io}\PYG{o}{.}\PYG{n}{StringIO}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{deadbeef}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{)}
\PYG{g+go}{3735928559}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{consume}\PYG{o}{.}\PYG{n}{number}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{10}\PYG{p}{,}\PYG{n}{multiply}\PYG{o}{=}\PYG{l+m+mi}{2}\PYG{p}{)}\PYG{p}{(}\PYG{n}{io}\PYG{o}{.}\PYG{n}{StringIO}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{42}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{)}
\PYG{g+go}{84}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{list() (hycon.replay.consume method)@\spxentry{list()}\spxextra{hycon.replay.consume method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.replay.consume.list}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{list}}}{\emph{\DUrole{n}{split}}, \emph{\DUrole{n}{end}}, \emph{\DUrole{n}{digits}}, \emph{\DUrole{n}{base}}}{}
Reads a list of numbers. Limitations:
* Always expects end token to come
* All numbers must have same number of digits (and same base)
* Cannot handle empty list or and won’t accept end\sphinxhyphen{}of\sphinxhyphen{}file before end token.

Examples:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{consume}\PYG{o}{.}\PYG{n}{list}\PYG{p}{(}\PYG{n}{split}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{,}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,}\PYG{n}{digits}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{n}{base}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{,}\PYG{n}{end}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{.}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{(}\PYG{n}{io}\PYG{o}{.}\PYG{n}{StringIO}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{1,5,2,3,9.}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{)}
\PYG{g+go}{[1, 5, 2, 3, 9]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{consume}\PYG{o}{.}\PYG{n}{list}\PYG{p}{(}\PYG{n}{split}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{:}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,}\PYG{n}{digits}\PYG{o}{=}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{n}{base}\PYG{o}{=}\PYG{l+m+mi}{16}\PYG{p}{,}\PYG{n}{end}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{;}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{(}\PYG{n}{io}\PYG{o}{.}\PYG{n}{StringIO}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{5a:88:ff:ff;}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{read}\PYG{p}{)}
\PYG{g+go}{[90, 136, 255, 255]}
\end{sphinxVerbatim}

\end{fulllineitems}


\end{fulllineitems}

\index{HyConRequestReader (class in hycon.replay)@\spxentry{HyConRequestReader}\spxextra{class in hycon.replay}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.replay.HyConRequestReader}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.replay.}}\sphinxbfcode{\sphinxupquote{HyConRequestReader}}}{\emph{stream\_or\_string}, \emph{mapping=\{\textquotesingle{}?\textquotesingle{}: (\textquotesingle{}NOT\_IMPLEMENTED\textquotesingle{}}, \emph{\textquotesingle{}Prints help\textquotesingle{})}, \emph{\textquotesingle{}A\textquotesingle{}: \textquotesingle{}enable\_ovl\_halt\textquotesingle{}}, \emph{\textquotesingle{}B\textquotesingle{}: \textquotesingle{}enable\_ext\_halt\textquotesingle{}}, \emph{\textquotesingle{}C\textquotesingle{}: (\textquotesingle{}set\_ic\_time\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{})}, \emph{\textquotesingle{}D\textquotesingle{}: (\textquotesingle{}digital\_output\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{}}, \emph{True)}, \emph{\textquotesingle{}E\textquotesingle{}: \textquotesingle{}single\_run\textquotesingle{}}, \emph{\textquotesingle{}F\textquotesingle{}: \textquotesingle{}single\_run\_sync\textquotesingle{}}, \emph{\textquotesingle{}G\textquotesingle{}: (\textquotesingle{}set\_ro\_group\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{})}, \emph{\textquotesingle{}L\textquotesingle{}: (\textquotesingle{}NOT\_IMPLEMENTED\textquotesingle{}}, \emph{\textquotesingle{}Locate a computing element\textquotesingle{})}, \emph{\textquotesingle{}P\textquotesingle{}: (\textquotesingle{}set\_pt\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{})}, \emph{\textquotesingle{}R\textquotesingle{}: \textquotesingle{}read\_digital\textquotesingle{}}, \emph{\textquotesingle{}S\textquotesingle{}: \textquotesingle{}pot\_set\textquotesingle{}}, \emph{\textquotesingle{}X\textquotesingle{}: (\textquotesingle{}set\_xbar\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{})}, \emph{\textquotesingle{}a\textquotesingle{}: \textquotesingle{}disable\_ovl\_halt\textquotesingle{}}, \emph{\textquotesingle{}b\textquotesingle{}: \textquotesingle{}disable\_ext\_halt\textquotesingle{}}, \emph{\textquotesingle{}c\textquotesingle{}: (\textquotesingle{}set\_op\_time\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{})}, \emph{\textquotesingle{}d\textquotesingle{}: (\textquotesingle{}digital\_output\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{}}, \emph{False)}, \emph{\textquotesingle{}e\textquotesingle{}: \textquotesingle{}repetitive\_run\textquotesingle{}}, \emph{\textquotesingle{}f\textquotesingle{}: \textquotesingle{}read\_ro\_group\textquotesingle{}}, \emph{\textquotesingle{}g\textquotesingle{}: (\textquotesingle{}read\_element\_by\_address\textquotesingle{}}, \emph{\textless{}function delayed.\textless{}locals\textgreater{}.decorated.\textless{}locals\textgreater{}.deferred\textgreater{})}, \emph{\textquotesingle{}h\textquotesingle{}: \textquotesingle{}halt\textquotesingle{}}, \emph{\textquotesingle{}i\textquotesingle{}: \textquotesingle{}ic\textquotesingle{}}, \emph{\textquotesingle{}l\textquotesingle{}: \textquotesingle{}get\_data\textquotesingle{}}, \emph{\textquotesingle{}o\textquotesingle{}: \textquotesingle{}op\textquotesingle{}}, \emph{\textquotesingle{}q\textquotesingle{}: \textquotesingle{}read\_dpts\textquotesingle{}}, \emph{\textquotesingle{}s\textquotesingle{}: \textquotesingle{}get\_status\textquotesingle{}}, \emph{\textquotesingle{}t\textquotesingle{}: \textquotesingle{}get\_op\_time\textquotesingle{}}, \emph{\textquotesingle{}x\textquotesingle{}: \textquotesingle{}reset\textquotesingle{}\}}}{}
Converts HyCon “configuration strings” to high level API calls.
This can be seen as the inverse operation to calling the HyCon.

Instances of this class act as iterator. It will consume the
incoming stream character by character (or the whole string, if
given as a string).

Example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{instructions} \PYG{o}{=} \PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{C000100c015000P0200000204P0300030000G0362;0363;0220;0221;0222;0223.}\PYG{l+s+s1}{\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{commands} \PYG{o}{=} \PYG{n+nb}{list}\PYG{p}{(}\PYG{n}{HyConRequestReader}\PYG{p}{(}\PYG{n}{instructions}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{for} \PYG{n}{c} \PYG{o+ow}{in} \PYG{n}{commands}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{c}\PYG{p}{)}
\PYG{g+go}{(\PYGZsq{}set\PYGZus{}ic\PYGZus{}time\PYGZsq{}, 100)}
\PYG{g+go}{(\PYGZsq{}set\PYGZus{}op\PYGZus{}time\PYGZsq{}, 15000)}
\PYG{g+go}{(\PYGZsq{}set\PYGZus{}pt\PYGZsq{}, 512, 0, 0.19941348973607037)}
\PYG{g+go}{(\PYGZsq{}set\PYGZus{}pt\PYGZsq{}, 768, 3, 0.0)}
\PYG{g+go}{(\PYGZsq{}set\PYGZus{}ro\PYGZus{}group\PYGZsq{}, [866, 867, 544, 545, 546, 547])}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{replayed} \PYG{o}{=} \PYG{n}{io}\PYG{o}{.}\PYG{n}{StringIO}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{hc} \PYG{o}{=} \PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{replayed}\PYG{p}{,} \PYG{n}{unidirectional}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{replay}\PYG{p}{(}\PYG{n}{hc}\PYG{p}{,} \PYG{n}{commands}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{replayed}\PYG{o}{.}\PYG{n}{getvalue}\PYG{p}{(}\PYG{p}{)} \PYG{o}{==} \PYG{n}{instructions}
\PYG{g+go}{True}
\end{sphinxVerbatim}

\end{fulllineitems}

\index{replay() (in module hycon.replay)@\spxentry{replay()}\spxextra{in module hycon.replay}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/hycon:hycon.replay.replay}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.replay.}}\sphinxbfcode{\sphinxupquote{replay}}}{\emph{\DUrole{n}{hycon}}, \emph{\DUrole{n}{commands}}}{}
Given commands a list of tuples, this will mostly act like operator.methodcaller
on them. If no arguments are given, the tuple can be omitted.

Basic example:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{class} \PYG{n+nc}{WannaBeHyCon}\PYG{p}{:}
\PYG{g+gp}{... }    \PYG{k}{def} \PYG{n+nf}{toot}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,}\PYG{n}{x}\PYG{p}{)}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{too(}\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{)ooot}\PYG{l+s+s2}{\PYGZdq{}} \PYG{o}{\PYGZpc{}} \PYG{n}{x}\PYG{p}{)}
\PYG{g+gp}{... }    \PYG{k}{def} \PYG{n+nf}{bar}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{this is bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{... }    \PYG{k}{def} \PYG{n+nf}{buz}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,}\PYG{n}{a}\PYG{p}{,}\PYG{n}{b}\PYG{p}{,}\PYG{n}{c}\PYG{p}{)}\PYG{p}{:} \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{a*b = }\PYG{l+s+si}{\PYGZob{}}\PYG{n}{a}\PYG{o}{*}\PYG{n}{b}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{ but what is }\PYG{l+s+si}{\PYGZob{}}\PYG{n}{c}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{replay}\PYG{p}{(}\PYG{n}{WannaBeHyCon}\PYG{p}{(}\PYG{p}{)}\PYG{p}{,} \PYG{p}{[} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{bar}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{toot}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{fuz}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{,} \PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{buz}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{)} \PYG{p}{]}\PYG{p}{)}
\PYG{g+go}{this is bar}
\PYG{g+go}{too(fuz)ooot}
\PYG{g+go}{a*b = 2 but what is 3}
\end{sphinxVerbatim}

The command format is produced by the HyConRequestReader and thus can be fed
into this replay function:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{replay}\PYG{p}{(}\PYG{n}{HyCon}\PYG{p}{(}\PYG{n}{sys}\PYG{o}{.}\PYG{n}{stdout}\PYG{p}{,} \PYG{n}{unidirectional}\PYG{o}{=}\PYG{k+kc}{True}\PYG{p}{)}\PYG{p}{,} \PYG{n}{HyConRequestReader}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{xiohaARt}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{g+go}{xiohaARt}
\end{sphinxVerbatim}

This works for almost any useful instruction stream.

\end{fulllineitems}



\section{HyCon Serial (USB/RS\sphinxhyphen{}232) over TCP/IP}
\label{\detokenize{hycon/networking:hycon-serial-usb-rs-232-over-tcp-ip}}\label{\detokenize{hycon/networking:networking-hc}}\label{\detokenize{hycon/networking::doc}}
On the machine where the HyCon board is attached to, run something like \sphinxcode{\sphinxupquote{socat}}
or for instance the \sphinxcode{\sphinxupquote{tcp\_serial\_redirect.py}} which is shipped with \sphinxcode{\sphinxupquote{PySerial}}
and can be obtained from
\sphinxurl{https://raw.githubusercontent.com/pyserial/pyserial/master/examples/tcp\_serial\_redirect.py}

Other Unix binaries which can be used are for instance \sphinxcode{\sphinxupquote{socat}}
\sphinxurl{https://bloggerbust.ca/post/let-socket-cat-be-thy-glue-over-serial/}
or \sphinxcode{\sphinxupquote{netcat}}.

Next, put a script like the following at that machine (now refered to as
the server):

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{c+ch}{\PYGZsh{}!/bin/bash \PYGZhy{}x}
\PYG{n}{source} \PYG{o}{\PYGZti{}}\PYG{o}{/}\PYG{o}{.}\PYG{n}{bash\PYGZus{}profile}
\PYG{n}{cd} \PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{\PYGZdl{}(dirname \PYGZdl{}0)}\PYG{l+s+s2}{\PYGZdq{}}
\PYG{o}{/}\PYG{n}{usr}\PYG{o}{/}\PYG{n}{local}\PYG{o}{/}\PYG{n+nb}{bin}\PYG{o}{/}\PYG{n}{python3} \PYG{n}{tcp\PYGZus{}serial\PYGZus{}redirect}\PYG{o}{.}\PYG{n}{py} \PYG{o}{\PYGZhy{}}\PYG{n}{P} \PYG{l+m+mi}{12345} \PYG{o}{/}\PYG{n}{dev}\PYG{o}{/}\PYG{n}{cu}\PYG{o}{.}\PYG{n}{usbserial}\PYG{o}{\PYGZhy{}}\PYG{n}{DN050L1O} \PYG{l+m+mi}{115200}
\end{sphinxVerbatim}

Then, from the client machine, run something like

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{ssh} \PYG{o}{\PYGZhy{}}\PYG{n}{L} \PYG{l+m+mi}{12345}\PYG{p}{:}\PYG{n}{localhost}\PYG{p}{:}\PYG{l+m+mi}{12345} \PYG{n}{ac} \PYG{o}{/}\PYG{n}{path}\PYG{o}{/}\PYG{n}{to}\PYG{o}{/}\PYG{n}{the}\PYG{o}{/}\PYG{n}{ac}\PYG{o}{\PYGZhy{}}\PYG{n}{bridge}\PYG{o}{/}\PYG{n}{run}\PYG{o}{\PYGZhy{}}\PYG{n}{bridge}\PYG{o}{.}\PYG{n}{sh}
\end{sphinxVerbatim}

Where \sphinxcode{\sphinxupquote{run\sphinxhyphen{}bridge.sh}} contains that script above.
Now you can connect to TCP port \sphinxcode{\sphinxupquote{12345}} at the client machine in order to speak directly
with the HyCon. This works remarkably well, also TCP buffering or network latency is not
a problem at all for me even with Bernds slow internet connection :\sphinxhyphen{})

\begin{sphinxadmonition}{note}{Note:}
\sphinxstylestrong{Known bugs}: When quitting the ssh session, the bridge is sometimes not killed properly.
In this case, log into the server and kill the script directly, for instance with
the following command:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{ps} \PYG{n}{aux} \PYG{o}{|} \PYG{n}{grep} \PYG{n}{tcp\PYGZus{}serial\PYGZus{}redirect} \PYG{o}{|} \PYG{n}{awk} \PYG{l+s+s1}{\PYGZsq{}}\PYG{l+s+s1}{\PYGZob{}}\PYG{l+s+s1}{print \PYGZdl{}2\PYGZcb{}}\PYG{l+s+s1}{\PYGZsq{}} \PYG{o}{|} \PYG{n}{xargs} \PYG{n}{kill}
\end{sphinxVerbatim}
\end{sphinxadmonition}


\section{Analog data aquisition}
\label{\detokenize{hycon/aquisition:module-hycon.aquisition}}\label{\detokenize{hycon/aquisition:analog-data-aquisition}}\label{\detokenize{hycon/aquisition:hycon-aquisition}}\label{\detokenize{hycon/aquisition::doc}}\index{module@\spxentry{module}!hycon.aquisition@\spxentry{hycon.aquisition}}\index{hycon.aquisition@\spxentry{hycon.aquisition}!module@\spxentry{module}}
The {\hyperref[\detokenize{hycon/aquisition:module-hycon.aquisition}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{hycon.aquisition}}}}} (\autopageref*{\detokenize{hycon/aquisition:module-hycon.aquisition}}) package collects various codes related to \sphinxstyleemphasis{data aquisition}.
Currently, we have a number of pythonic analog2digital data auqisition
routines:
\begin{itemize}
\item {} 
The Hybrid Controller uC itself offers methods such as
{\hyperref[\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_ro_group}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{hycon.HyCon.HyCon.read\_ro\_group()}}}}} (\autopageref*{\detokenize{hycon/hycon:hycon.HyCon.HyCon.read_ro_group}}) and similar. The aquisition
is high precision (16bit) but quite limited in time, given the small
memory of the uC which is used for store the full aquisition before
a transfer is possible (no streaming implemented).

\item {} 
DSOs (digital storage oscilloscopes) can be used for high quality
and industry standard data aquisition. A particular python example is
provided in the {\hyperref[\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{siglent\_scpi.siglent}}}}} (\autopageref*{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent}}) code.
These devices are typically also limited in aquisition time, which is
naturally mapped to the display. Furthermore, these devices are always
very limited in the number of analog channels, and devices with
many channels are expensive.

\item {} 
Custom Data loggers provide maximum flexibilty, given the large amount
of channels implementable with cheap microcontrollers
such as the \sphinxhref{https://www.pjrc.com/teensy/}{Teensy}%
\begin{footnote}[82]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.pjrc.com/teensy/}
%
\end{footnote}. However, these
cheap uCs typically only have an average resolution of 10bit.
A particular
example is given at \sphinxurl{https://github.com/anabrid/TeensyLogger}
(see also \sphinxurl{https://the-analog-thing.org/wiki/Teensy}).

\end{itemize}

When it comes to classical analog computing, one would like to optimize
the aquisition for high resolution (16bit), many channels (as many as possible).
What is not so important is the sampling rate, since the cutoff frequency of
the discrete circuits is rather low (at the order of MHz).


\subsection{Siglent SCPI}
\label{\detokenize{hycon/aquisition:module-hycon.aquisition.siglent_scpi}}\label{\detokenize{hycon/aquisition:siglent-scpi}}\index{module@\spxentry{module}!hycon.aquisition.siglent\_scpi@\spxentry{hycon.aquisition.siglent\_scpi}}\index{hycon.aquisition.siglent\_scpi@\spxentry{hycon.aquisition.siglent\_scpi}!module@\spxentry{module}}
Pythonic API for Siglent Digital Oscilloscope in order to perform data aquisition.
This is a python standalone code implementing the SCPI protocol (without further
Python libraries) over sockets. The connection is assumed to be established over
Ethernet (not USB, despite this should also work, in principle, as the siglent
registers as UART device over USB). The code can work in blocking and non\sphinxhyphen{}blocking
fashion (but is not fully async).

See the programming guide
\sphinxurl{https://siglentna.com/wp-content/uploads/dlm\_uploads/2021/01/SDS1000-SeriesSDS2000XSDS2000X-E\_ProgrammingGuide\_PG01-E02D.pdf}
for the reference. This code was tested against an Siglent SDS1104X\sphinxhyphen{}E with four 10bit channels.

Here is a picture of such an oscilloscope. On the back, it has an RJ45 ethernet
connector and a USB client socket. Whether over USB\sphinxhyphen{}UART or TCP, it allows to be
programmed with the
\sphinxhref{https://en.wikipedia.org/wiki/Standard\_Commands\_for\_Programmable\_Instruments}{Standards Commands for Programmable Instruments (SCPI)}%
\begin{footnote}[83]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Standard\_Commands\_for\_Programmable\_Instruments}
%
\end{footnote}
standard, which is basically a simple command\sphinxhyphen{}reply text protocol similar to the
one we implement with the {\hyperref[\detokenize{hycon/hycon:module-hycon.HyCon}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{hycon.HyCon}}}}} (\autopageref*{\detokenize{hycon/hycon:module-hycon.HyCon}}).

\noindent\sphinxincludegraphics[width=0.800\linewidth]{{cc39c07b8844d2facdccb7dd9ccee39aca86a5d1}.jpg}

Over ethernet, one can also access the oscilloscope screen via
\sphinxhref{https://en.wikipedia.org/wiki/Virtual\_Network\_Computing}{VNC}%
\begin{footnote}[84]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/Virtual\_Network\_Computing}
%
\end{footnote}. 
The oscilloscope provides a web interface which includes an in\sphinxhyphen{}browser
VNC client and models the interface controls. Both is shown side on side in
the UI. The interface knobs are translated to SCPI commands via Javascript.
The status indicators are polled. The overall UI is quite heavy, rather slow
and generates, in particular, high load on the oscilloscope.

\noindent\sphinxincludegraphics[width=1.000\linewidth]{{f6a0b7b21773e86d38b43ca7bacc4d3e9707426f}.png}

\begin{sphinxadmonition}{warning}{Warning:}
Make sure you \sphinxstylestrong{never ever run the browser interface at the same time as 
a telnet session or this script}. This will break the oscilloscope randomly
and requires you to cold start it. This is a reproducable bug in the Siglent
firmware.

It is, however, fine to run a VNC connection to the oscilloscope while
running this script.
\end{sphinxadmonition}

This script is also executable as standalone and offers an API to contact the siglent
and do a single readout, assuming the triggering took place independently.
\index{downsample() (in module hycon.aquisition.siglent\_scpi)@\spxentry{downsample()}\spxextra{in module hycon.aquisition.siglent\_scpi}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.downsample}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.aquisition.siglent\_scpi.}}\sphinxbfcode{\sphinxupquote{downsample}}}{\emph{\DUrole{n}{data}}, \emph{\DUrole{n}{factor}}}{}
Downsample all numpy 1d arrays, since \sphinxcode{\sphinxupquote{query("MEMORY\_SIZE 70K")}} has no effect…
TODO: MEMSIZE only works in STOP mode.

\end{fulllineitems}

\index{write\_npz() (in module hycon.aquisition.siglent\_scpi)@\spxentry{write\_npz()}\spxextra{in module hycon.aquisition.siglent\_scpi}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.write_npz}}\pysiglinewithargsret{\sphinxcode{\sphinxupquote{hycon.aquisition.siglent\_scpi.}}\sphinxbfcode{\sphinxupquote{write\_npz}}}{\emph{\DUrole{n}{data}}, \emph{\DUrole{n}{fname}\DUrole{o}{=}\DUrole{default_value}{None}}}{}
Write out NPZ files. See \sphinxurl{https://numpy.org/doc/stable/reference/generated/numpy.savez.html}
for this numpy specific binary file format.
Expects data to be a python dictionary (ideally some \sphinxcode{\sphinxupquote{np.array}}).

\end{fulllineitems}

\index{siglent (class in hycon.aquisition.siglent\_scpi)@\spxentry{siglent}\spxextra{class in hycon.aquisition.siglent\_scpi}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{class }}\sphinxcode{\sphinxupquote{hycon.aquisition.siglent\_scpi.}}\sphinxbfcode{\sphinxupquote{siglent}}}{\emph{\DUrole{n}{host}}, \emph{\DUrole{n}{port}\DUrole{o}{=}\DUrole{default_value}{5025}}}{}
This is a classy API to the oscilloscope. A usage example intermixed with
HyCon controlling may look like this:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{hycon}\PYG{n+nn}{.}\PYG{n+nn}{aquisition}\PYG{n+nn}{.}\PYG{n+nn}{siglent\PYGZus{}scpi} \PYG{k}{as} \PYG{n+nn}{sig}

\PYG{n}{hc} \PYG{o}{=} \PYG{n}{AutoConfHyCon}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{something.yml}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{hc}\PYG{o}{.}\PYG{n}{get\PYGZus{}status}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}

\PYG{n}{siglent} \PYG{o}{=} \PYG{n}{sig}\PYG{o}{.}\PYG{n}{siglent}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{192.168.32.68}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Siglent Status: }\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{siglent}\PYG{o}{.}\PYG{n}{status}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}

\PYG{n}{hc}\PYG{o}{.}\PYG{n}{ic}\PYG{p}{(}\PYG{p}{)}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{ICs freely running, preparing Siglent trigger...}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{c+c1}{\PYGZsh{}input(\PYGZdq{}Press enter to continue\PYGZdq{})}
\PYG{n}{prepped} \PYG{o}{=} \PYG{n}{siglent}\PYG{o}{.}\PYG{n}{trigger\PYGZus{}single}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{siglent}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Siglent Status: }\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{siglent}\PYG{o}{.}\PYG{n}{status}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{prepped}\PYG{p}{:}
    \PYG{k}{raise} \PYG{n+ne}{ValueError}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Could not properly prepare the Siglent.}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{time}\PYG{o}{.}\PYG{n}{sleep}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{hc}\PYG{o}{.}\PYG{n}{single\PYGZus{}run\PYGZus{}sync}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{time}\PYG{o}{.}\PYG{n}{sleep}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} 2 seconds \PYGZdq{}OP time\PYGZdq{}.}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{Finished with single run sync. Waiting another second for siglent.}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\PYG{n}{time}\PYG{o}{.}\PYG{n}{sleep}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{hc}\PYG{o}{.}\PYG{n}{ic}\PYG{p}{(}\PYG{p}{)}
\PYG{c+c1}{\PYGZsh{}input(\PYGZdq{}HC stopped. Press enter to readout siglent.\PYGZdq{})}
\PYG{n}{data} \PYG{o}{=} \PYG{n}{siglent}\PYG{o}{.}\PYG{n}{read\PYGZus{}all}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{sig}\PYG{o}{.}\PYG{n}{write\PYGZus{}npz}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,} \PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{output.npz}\PYG{l+s+s2}{\PYGZdq{}}\PYG{p}{)}
\end{sphinxVerbatim}

\begin{sphinxadmonition}{warning}{Warning:}
While this code basically works, the refactoring at PyAnalog\sphinxhyphen{}introduction
time was not tested. That is, this code is not yet fully tested.
\end{sphinxadmonition}
\index{send() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{send()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.send}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{send}}}{\emph{\DUrole{n}{md}}, \emph{\DUrole{n}{log\_end}\DUrole{o}{=}\DUrole{default_value}{\textquotesingle{}\textbackslash{}n\textquotesingle{}}}, \emph{\DUrole{n}{blocking}\DUrole{o}{=}\DUrole{default_value}{False}}, \emph{\DUrole{n}{sleep\_sec}\DUrole{o}{=}\DUrole{default_value}{0.5}}}{}
Send SCPI command to siglent.

\end{fulllineitems}

\index{query() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{query()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.query}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{query}}}{\emph{\DUrole{n}{sleep\_sec}\DUrole{o}{=}\DUrole{default_value}{0.5}}}{}
Query the siglent for something.
This is basically a {\hyperref[\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.send}]{\sphinxcrossref{\sphinxcode{\sphinxupquote{send()}}}}} (\autopageref*{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.send}})/\sphinxcode{\sphinxupquote{recv()}} cycle, according to the
SCPI standard.

\end{fulllineitems}

\index{query\_num() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{query\_num()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.query_num}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{query\_num}}}{\emph{\DUrole{n}{pat}}}{}
A shorthand which returns the number in some readout which looks like \sphinxcode{\sphinxupquote{a = 123}}.

\end{fulllineitems}

\index{status() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{status()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.status}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{status}}}{}{}
Reads out the status bit (\sphinxcode{\sphinxupquote{INR?}}) and translates it according to the manual,
thus returning a string.

\begin{sphinxadmonition}{warning}{Warning:}
Attention, Querying INR? is \sphinxstyleemphasis{NOT} a read\sphinxhyphen{}only operation but changes
the oscilloscope status.
\end{sphinxadmonition}

\end{fulllineitems}

\index{trigger\_single() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{trigger\_single()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.trigger_single}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{trigger\_single}}}{}{}
Brings the Oscilloscope in single trig mode and checks the success of this
operation (returns \sphinxcode{\sphinxupquote{True}} in case of passed check).

\end{fulllineitems}

\index{read\_wf() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{read\_wf()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.read_wf}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_wf}}}{\emph{\DUrole{n}{channel}}, \emph{\DUrole{n}{try\_multiples}\DUrole{o}{=}\DUrole{default_value}{2}}}{}
Read the actual waveform. This can be called after an aquisition took place
and the oscilloscope trigger fired. In many times, this will fail and return
no data. This results in a thrown \sphinxcode{\sphinxupquote{ValueError}}. Otherwise, data recieving
is looped (with lot’s of logging since it takes some seconds). When some 
consistency is reached (all announced data is recieved), will return the 
\sphinxstyleemphasis{raw recieved channel data} as 1d list of numbers. That is, these are 10bit
numbers.

This function will by default try several times to ask for data, in case the
siglent did not properly answer.

\end{fulllineitems}

\index{read\_all() (hycon.aquisition.siglent\_scpi.siglent method)@\spxentry{read\_all()}\spxextra{hycon.aquisition.siglent\_scpi.siglent method}}

\begin{fulllineitems}
\phantomsection\label{\detokenize{hycon/aquisition:hycon.aquisition.siglent_scpi.siglent.read_all}}\pysiglinewithargsret{\sphinxbfcode{\sphinxupquote{read\_all}}}{\emph{\DUrole{n}{channels}\DUrole{o}{=}\DUrole{default_value}{None}}}{}
Read the actual waveforms by querying the passed channel list. A channel is
an integer between \sphinxcode{\sphinxupquote{0}} and \sphinxcode{\sphinxupquote{4}}, see \sphinxcode{\sphinxupquote{siglent.channels}} for the valid
channel list. If not provided, all channels are read.

Will do the conversion to voltages, that is, returns proper floats representing
a voltage in unit V.  Returns a dictionary mapping the channel name to the 1d data.

\end{fulllineitems}


\end{fulllineitems}


\appendix
\chapter{Appendix} % or: Endnotes


\section{About this documentation}
\label{\detokenize{index:about-this-documentation}}
This documentation is written in \sphinxhref{https://en.wikipedia.org/wiki/ReStructuredText}{ReStructured text}%
\begin{footnote}[85]\sphinxAtStartFootnote
\sphinxnolinkurl{https://en.wikipedia.org/wiki/ReStructuredText}
%
\end{footnote}
(RST) and rendered using the \sphinxhref{https://www.sphinx-doc.org/}{Sphinx}%
\begin{footnote}[86]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.sphinx-doc.org/}
%
\end{footnote}. documentation
system. Possible output formats are not only web pages (HTML), but also PDF,
amongst others. If you have sphinx installed (\sphinxcode{\sphinxupquote{pip install sphinx}}), you can
just go to the \sphinxcode{\sphinxupquote{doc}} directory and type \sphinxcode{\sphinxupquote{make html}} or \sphinxcode{\sphinxupquote{make pdf}} to
generate the docs locally. If you have a mixed Python2/Python3 system, call
\sphinxcode{\sphinxupquote{make html SPHINXBUILD="python3 \sphinxhyphen{}msphinx"}} to ensure using Python3.

If you want to start editing/improving this documentation, you might want to
read the \sphinxhref{https://docutils.sourceforge.io/docs/user/rst/quickstart.html}{ReStructuredText Primer}%
\begin{footnote}[87]\sphinxAtStartFootnote
\sphinxnolinkurl{https://docutils.sourceforge.io/docs/user/rst/quickstart.html}
%
\end{footnote}. A handy tool for hot reloading (regenerating) the documentation
during editing is \sphinxhref{https://github.com/prkumar/sphinx-reload}{Sphinx\sphinxhyphen{}Reload}%
\begin{footnote}[88]\sphinxAtStartFootnote
\sphinxnolinkurl{https://github.com/prkumar/sphinx-reload}
%
\end{footnote}. After
installation, just run \sphinxcode{\sphinxupquote{sphinx\sphinxhyphen{}reload doc/}} from the root directory and point your
browser to an address such as \sphinxurl{http://localhost:5500/}.

This documentation is automatically updated/built at Git commit/push time by our
Gitlab Continous Integration infrastructured and uploaded
as static files to our \sphinxhref{https://www.anabrid.dev/}{Anabrid Dev Server}%
\begin{footnote}[89]\sphinxAtStartFootnote
\sphinxnolinkurl{https://www.anabrid.dev/}
%
\end{footnote}
(formally \sphinxhref{https://readthedocs.org/}{Read The Docs}%
\begin{footnote}[90]\sphinxAtStartFootnote
\sphinxnolinkurl{https://readthedocs.org/}
%
\end{footnote}). you can find the docs at:
\begin{itemize}
\item {} 
\sphinxurl{https://anabrid.dev/pyanalog/dirhtml/} primary link

\item {} 
\sphinxurl{https://anabrid.dev/pyanalog/latex/pyanalog.pdf} for a +100 page
printable/downloadable/searchable PDF version

\item {} 
Various different versions for download at \sphinxurl{https://anabrid.dev/pyanalog/}

\end{itemize}


\section{Indices and tables}
\label{\detokenize{index:indices-and-tables}}\begin{itemize}
\item {} 
\DUrole{xref,std,std-ref}{Python Function/Class index}

\item {} 
\DUrole{xref,std,std-ref}{Python module index}

\end{itemize}


\renewcommand{\indexname}{Python Module Index}
\begin{sphinxtheindex}
\let\bigletter\sphinxstyleindexlettergroup
\bigletter{d}
\item\relax\sphinxstyleindexentry{dda}\sphinxstyleindexpageref{dda/package:\detokenize{module-dda}}
\item\relax\sphinxstyleindexentry{dda.ast}\sphinxstyleindexpageref{dda/ast:\detokenize{module-dda.ast}}
\item\relax\sphinxstyleindexentry{dda.computing\_elements}\sphinxstyleindexpageref{dda/computing_elements:\detokenize{module-dda.computing_elements}}
\item\relax\sphinxstyleindexentry{dda.cpp\_exporter}\sphinxstyleindexpageref{dda/cpp-codegen:\detokenize{module-dda.cpp_exporter}}
\item\relax\sphinxstyleindexentry{dda.dsl}\sphinxstyleindexpageref{dda/dsl:\detokenize{module-dda.dsl}}
\item\relax\sphinxstyleindexentry{dda.scipy}\sphinxstyleindexpageref{dda/scipy:\detokenize{module-dda.scipy}}
\item\relax\sphinxstyleindexentry{dda.sympy}\sphinxstyleindexpageref{dda/cas:\detokenize{module-dda.sympy}}
\indexspace
\bigletter{f}
\item\relax\sphinxstyleindexentry{fpaa}\sphinxstyleindexpageref{fpaa/fpaa:\detokenize{module-fpaa}}
\item\relax\sphinxstyleindexentry{fpaa.fpaa}\sphinxstyleindexpageref{fpaa/fpaa:\detokenize{module-fpaa.fpaa}}
\indexspace
\bigletter{h}
\item\relax\sphinxstyleindexentry{hycon.aquisition}\sphinxstyleindexpageref{hycon/aquisition:\detokenize{module-hycon.aquisition}}
\item\relax\sphinxstyleindexentry{hycon.aquisition.siglent\_scpi}\sphinxstyleindexpageref{hycon/aquisition:\detokenize{module-hycon.aquisition.siglent_scpi}}
\item\relax\sphinxstyleindexentry{hycon.autosetup}\sphinxstyleindexpageref{hycon/hycon:\detokenize{module-hycon.autosetup}}
\item\relax\sphinxstyleindexentry{hycon.connections}\sphinxstyleindexpageref{hycon/hycon:\detokenize{module-hycon.connections}}
\item\relax\sphinxstyleindexentry{hycon.HyCon}\sphinxstyleindexpageref{hycon/hycon:\detokenize{module-hycon.HyCon}}
\item\relax\sphinxstyleindexentry{hycon.replay}\sphinxstyleindexpageref{hycon/hycon:\detokenize{module-hycon.replay}}
\end{sphinxtheindex}

\renewcommand{\indexname}{Index}
\printindex
\end{document}