%This documents the Ballad VM. If we end up releasing it bare-bones, wrap this
%document in appropriate silly or challenge related stuff later.

\section{Ballad} Ballad is a programming language expressed in music. It is an
`interpreted', Turing complete language which does not follow the von Neumann
architecture.  This is the case insofar as code memory is separate from static,
non-executable memory as well as the actual, active memory. The Ballad VM has a
series of registers as well as a stack, in which active data is processed.

The code memory cannot be modified during the execution of a program, nor can
the static memory section. These are not placed on a heap or stack, as in a
more conventional program, but are maintained separately from the active
memory. The static memory can be of arbitrary size, but the code memory is
restricted to a maximum of 256 bytes. The implementation of the Ballad VM
should reflect this.

The stack is similarly limited in size to 256 bytes. It can be pushed and
popped from, but it can also be addressed and written to directly in the style
of a stack of fixed length backed by an array. A stack pointer internal to the
VM should track the location of the top of the stack; the bottom is fixed to
the zero position and the stack grows upwards. The stack is addressed by Ballad
instructions ranging from 0x00 (the bottom) to 0xFF (the largest value).

All data is, by default, an unsigned eight bit integer. Modifications to this
may be made by the program (for example, implementing two's complement or the
like), but the Ballad VM should treat all numbers as such for the purpose of
calculating overflow.

There are two sets of registers which Ballad uses. These are the math registers
and the swap registers. One set is designed for and used by all arithmetic
operations, the other set is designed for moving data between locations and as
a general purpose register set. There are eight registers of each type and are
addressed by a byte of value 0x00 to 0x07.

\subsection{Decoding} Ballad programs consist of static data sections and code
sections which are expressed as music in (at least) two-track MIDI files. The
first track consists of the static memory section and the second of the code
section. Other tracks are ignored.

Within a track, interpretation is ignored until one whole note (4 beats in 4/4)
is found by the Ballad VM. All Ballad tracks must have this whole note at the
beginning of a valid section, code or data. This note is used to decode the
rest of the section, by providing the appropriate key, or MIDI note number.
This key is used to demodulate the rest of the song, which is restricted to
notes on the major scale, based on this key.

Demodulation occurs by first transposing the key of song to a common key
(typically by subtracting the MIDI number of the tonic note mentioned above
from the MIDI number of the given note to decode). The only relevant note in a
chord is its root; all higher notes are ignored in this version of Ballad. Once
the song is in a uniform key, it is necessary to obtain the offset \emph{in the
scale} of the given note to decode (as opposed to its raw MIDI number). In any
given Ballad program, there are only sixteen notes of the major scale given as
chord roots or individual notes. To obtain Ballad bytecode from a Ballad song,
it is necessary to map these to bytes.

The mapping of notes to bytes is done by first obtaining the aforementioned
offset. This yields one of sixteen numbers, or 0x0 to 0xF. Taken in pairs, from
the beginning of the Ballad song to the end, then converted into bytes, Ballad
bytecode is obtained. For example, if the whole note at the start of one of the
tracks was `A-0', then the next two notes were `A-0' then `D-1', the resulting
hex byte would be 0x0a, or newline in ASCII (where 0 represents the first
octave, 1 represents the one above it). By applying this to each of the first
two tracks of the Ballad song, a sequence of bytes can be obtained.

\subsection{Static Memory} Static memory is used to provide predetermined input
to a Ballad program. In other languages, this would usually take the form of
constant character strings. It is indexed from zero by Ballad instructions and
can be loaded via the static loading commands.

\subsection{Code Memory} Code memory is a linear chain of instructions and
their arguments. There are instructions which take between one and three
arguments. Each instruction to a Ballad argument is one byte long, which makes
calls fairly straightforward.

\clearpage
\section{Ballad Instructions} This section describes the various Ballad
instructions, their calling conventions and what registers are accessed by a
given call, if any. Math registers are referenced as \emph{m}, the general
purpose, or swap registers, are referenced by \emph{s} and immediate
instructions (in unsigned single-byte representations) are indicated by
\emph{im}. If an instruction accepts no arguments, \emph{None} is used.

\subsection{Mathematical Instructions}
All arithmetic operations imply unsigned integer arithmetic and overflow where
appropriate.
\\
\begin{table}[h!]
\centering
\caption{Mathematical Instructions}
\begin{tabular}{| l | l | l | p{8cm} | }
	\hline
	Instruction & Opcode & Arguments & Semantics \\\hline
		       add & 1 & m0, m1 & Add the values stored in m0 to m1 and store the result
	in m0 \\\hline
		       sub & 2 & m0, m1 & Subtract the values stored in m1 from m0 and store the result
	in m0 \\\hline
		       mul & 3 & m0, m1 & Multiply the values stored in m0 to m1 and store the result
	in m0 \\\hline
		       div & 4 & m0, m1 & Divide m0 by m1 and store the result
	in m0 \\\hline
		       xor & 5 & m0, m1 & Perform a bitwise exclusive or on the values stored in
	m0 to m1 and store the result in m0 \\\hline
		       and & 6 & m0, m1 & Perform a bitwise `and' on the values stored in
	m0 to m1 and store the result in m0 \\\hline
		       or & 7 & m0, m1 & Perform a bitwise `or' on the values stored in
	m0 to m1 and store the result in m0 \\\hline
		       or & 8 & m0, m1 & Perform a bitwise inverse (0b00000000 $\rightarrow$ 0b11111111) on the
	values stored in
	m0 to m1 and store the result in m0 \\\hline
	inc & 9 & m0 & Increment the value in m0 by one and save it to m0 \\\hline
	dec & 10 & m0 & Decrement the value in m0 by one and save it to m0 \\\hline
\end{tabular}
\end{table}
\clearpage
\subsection{Jump Instructions}
These instructions change the instruction pointer (IP) in some way. Offsets
range from 0 (the start of the code section) and can end at 255 (the end of the
code section). When given, an immediate (\emph{im}) value is an offset.
\begin{table}[h!]
	\centering
	\caption{Jump Instructions}
	\begin{tabular}{|l|l|l|p{8cm}|}
		\hline
		Instruction & Opcode & Arguments & Semantics \\\hline
			       jmp & 11 & im & Set the IP to the given offset \\\hline
			       jeq & 12 & m0, m1, im & If the value in m0 is equal to the value stored
					in m1, set the IP to the offset \\\hline
			       jne & 13 & m0, m1, im & If the value in m0 is not equal to the value stored
					in m1, set the IP to the offset \\\hline
			       jlt & 14 & m0, m1, im & If the value in m0 is less than the value stored
					in m1, set the IP to the offset \\\hline
			       jgt & 15 & m0, m1, im & If the value in m0 is greater than the value stored
					in m1, set the IP to the offset \\\hline
			       jlte & 16 & m0, m1, im & If the value in m0 is less than
					or equal to the value stored
					in m1, set the IP to the offset \\\hline
			       jgte & 17 & m0, m1, im & If the value in m0 is greater than
					or equal to the value stored
					in m1, set the IP to the offset \\\hline
				ret & 28 & m0 & Set the IP to the value stored in m0 \\\hline
	\end{tabular}
\end{table}

\clearpage
\subsection{Memory Instructions}
These instructions deal with moving data in and out of static memory and the
stack. Typically, the value to move is stored in an \emph{s} register and the
offset in the target memory location is stored in an \emph{m} register.
\begin{table}[h!]
	\centering
	\caption{Memory Instructions}
	\begin{tabular}{|l|l|l|p{8cm}|}
		\hline
		Instruction & Opcode & Arguments & Semantics \\\hline
		       push & 18 & s0 & Put the value stored in s0 at the top of the stack, then
		increment the stack pointer \\\hline
		pop & 19 & s0 & put the value on the top of the stack into s0, then decrement
		the stack pointer\\\hline
lstat & 23 & s0, m0 & Fetch the byte stored in static memory from the offset stored in m0 and put it into
		s0 \\\hline
		stget & 24 & s0, m0 & Fetch the value stored on the stack at the offset stored in
		m0 and put it into s0 \\\hline
		stput & 25 & m0, s0 & Put the value stored in s0 onto the stack at the offset stored
		in m0\\\hline
	\end{tabular}
\end{table}

\clearpage
\subsection{Move Instructions}
These instructions handle moving data between registers and putting immediate
data into registers. They also handle things like immediate loading from within
the code. As usual, assume unsigned bytes.
\begin{table}[h!]
	\centering
	\caption{Move Instructions}
	\begin{tabular}{|l|l|l|p{8cm}|}
		\hline
		Instruction & Opcode & Arguments & Semantics \\\hline
		      movim & 30 & m0, im & This stores the value of the immediate into the math register
		indexed by m0 \\\hline
		movis & 29 & s0, im & This stores the value of the immediate into the swap register
		indexed by s0 \\\hline
		movrm & 21 & m0, s0 & This moves the value stored in the swap register s0 into the
		math register indexed by m0 \\\hline
		movrs & 21 & s0, m0 & This moves the value stored in the math register m0 into the
		swap register indexed by s0 \\\hline
	\end{tabular}
\end{table}

\clearpage
\subsection{Utility Instructions}
These instructions handle `system' level instructions, reading and writing from the user.
\begin{table}[h!]
	\centering
	\caption{Move Instructions}
	\begin{tabular}{|l|l|l|p{8cm}|}
		\hline
		Instruction & Opcode & Arguments & Semantics \\\hline
		       read & 27 & m0, m1 & This command reads in bytes numbering the value stored
		in m1 onto the stack at the address (offset) given by the value stored in m0\\\hline
		       print & 26 & s0, s1 & This command prints out bytes numbering the value stored
		in s1 from the stack at the address (offset) given by the value stored in s0\\\hline
	\end{tabular}
\end{table}


\documentclass[%
%   preprint,
superscriptaddress,
%groupedaddress,
%unsortedaddress,
%runinaddress,
%frontmatterverbose,
%preprint,
%showpacs,preprintnumbers,
%nofootinbib,
%nobibnotes,
%bibnotes,
%twocolumn,
amsmath,amssymb,
aps,
pre,
%prb,
%rmp,
%prstab,
%prstper,
floatfix,
]{revtex4-2}

\usepackage{graphicx}% Include figure files
\usepackage{overpic}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\usepackage{hyperref}% add hypertext capabilities
\usepackage{color}
\usepackage{verbatim}
\graphicspath{{./fig/}}
%\usepackage{epstopdf}
%\usepackage{auto-pst-pdf}

%todo Chris: Write about 1/1 mode
%todo Chris: Write results/figure explanation section

%todo Ralf: Write q_\infty derivation
%todo Ralf: Read and improve introduction.

\begin{document}
\title{An interactive toy model for the sawtooth oscillation in tokamak fusion reactors}
\author{R.J.J. Mackenbach}
\affiliation{Science and Technology of Nuclear Fusion, Department of Applied Physics, Eindhoven University of Technology, 5600 MB Eindhoven, The Netherlands}
\author{C. B. Smiet}
\affiliation{Princeton Plasma Physics Laboratory, Princeton University, Princeton, New Jersey, USA}
\affiliation{Huygens-Kamerlingh Onnes Laboratory, Leiden University, P.O.\ Box 9504, 2300 RA Leiden, The Netherlands}

\begin{abstract}
  The sawtooth crash is an instability occurring in the core of a tokamak plasma that redistributes the temperature and pressure in the core region.
  In the Kadomtsev model the crash is caused by a 1/1 internal kink that reconnects the hot plasma within the core region.
  In this paper we present a minimal analytical model with two free parameters that reproduces the predicted changes in topology.
  This paints an intuitive picture of how the magnetic topology changes during a sawtooth crash.
\end{abstract}
\maketitle

\section{Introduction}
Global energy consumption keeps increasing, and so do greenhouse gas emissions. This in turn, through many feedback mechanisms \cite{Curry1995,Bloom2010}, raises the earth's average temperature and sea-levels. Since the energy-thirst of the human race is hard to quench, we must turn to renewable energy resources. Many options exist, but only few will be able to sustain the increasing need for energy in the long run. Nuclear fusion, in which small atomic nuclei combine to larger ones releasing vast amounts of energy, is one of those options.
There are many different concepts for a fusion energy power plant. The tokamak (a Russian acronym for ``\textit{toroidal chamber with magnetic coils}") is the leading candidate as of now (in terms of funding and technological readiness). This doughnut-shaped machine confines a plasma (an ionized gas) by making use of strong magnetic fields and large currents.
The field in the toroidal direction (long way around the torus) is generated by external coils, while the poloidal field (short way around the tours) that `twists' the field as it goes around is generated by currents in the plasma itself.
This twisting is quantified by the safety factor $q=n/m$ (where $n$ is the number of toroidal windings of a field line and $m$ the number of poloidal windings).
The plasma contains the fuel of our machine - the deuterium and tritium nuclei which will fuse into helium and produce energy. Using this configuration the tokamak tries to produce more energy than is needed to heat the machine to operating temperature (quantified in Lawson's criterion \cite{Lawson1957}), a feat which ITER hopes to demonstrate.

Tokamaks however, are not free of problems. These machines are plagued by many different complications, such as large heat fluxes and neutron activation of materials. We will focus on one such complication, the sawtooth oscillation. During a sawtooth event, the hot and dense plasma in the core is redistributed through a region in the center of the plasma, causing a sudden drop in the core temperature and density. Slowly, the plasma in the core heats up again and becomes more dense, until the process repeats. If one plots the plasma temperature in the core over time, one would typically see a sawtooth-like pattern, hence the name of the phenomenon.

The sawtooth crash has been observed in tokamak fusion reactors since 1974 \cite{von1974studies, vershkov1974role}.
Because of the temperature dependent Spitzer resistivity, the plasma current that creates the poloidal field in the reactor preferentially concentrates on the hottest plasma region near the magnetic axis.
This decreases the safety factor (increases the twisting) around the core.
Current diffuses onto the core of the tokamak on a slow, resistive timescale, until a fast instability is triggered at a specific value of $q_0$ (the safety factor on the magnetic axis).
This instability leads to mixing of all the plasma in the core, and results in a flat temperature and pressure profile.
It also affects the poloidal and toroidal flux, resulting in a higher $q_0$.
The sawtooth cycle resets, and current slowly accumulates on the axis until the instability is triggered again.

A numerical simulation of a sawtoothing discharge done with M3DC1~\cite{jardin2012multiple} is shown in figure [REF]. [ADD ANIMATED GIF TO PAPER m3dsim.gif].
A simulation such as this reproduces the observed phenomena to a degree, but in order to keep the computing resources manageable, many simplifications to the plasma dynamics need to be made.
The most advanced calculations of the plasma dynamics cost millions of cpu-hours and are run on exascale devices.
Another approach is to develop analytical models that reduce the complexity of the problem as much as possible, to still reproduce the essential features of the phenomenon.

\begin{figure}
    \centering
    \includegraphics[width=0.7\textwidth]{fullfig149.png}
    \caption{Sawtoothing behavior reproduced in a low-resolution full numerical simulation of plasma dynamics.}
    \label{fig:my_label}
\end{figure}

One of the most enduring models for the sawtooth was presented by Kadomtsev~\cite{kadomtsev1975disruptive}.
In this model the region within the $q=1$ surface becomes susceptible to an internal kink mode, a resistive tearing instability of the $q=1$ surface, or both~\cite{coppi1976resistive}.
The plasma in the core reconnects with cold plasma from outside the $q=1$ surface along a helical ribbon on the $q=1$ surface, and is deposited in a growing 1/1 island.
This growing island eventually completely displaces the hot core, and the temperature and current are redistributed.
After the crash, the hot core is completely replaced by the $1/1$ island, which has $q_0=1$.

In this paper we present a simple analytical toy model that approximates the above process and which uses only  two independent parameters to reproduce the predicted change in topology: a 1/1 internal kink that displaces the core, and a linear interpolation between the initial and final flux predicted by Kadomtsev.
Other expressions for the time-dependent magnetic topology during the sawtooth crash have been presented by Kolesnichenko~\cite{kolesnichenko1996theory} and Jaulmes~\cite{jaulmes2014redistribution}.
These works calculate the intermediate states in the Kadomtsev reconnection process.
Our model separates the reconnection phase into two separate and independent perturbations, resulting in a more analytically tractable and intuitive picture, at the cost of accuracy.

\section{Theory}

\section*{Initial magnetic field}
The magnetic field in a tokamak ideally consists of nested toroidal magnetic surfaces with a monotonically increasing $q$-profile.
We generate such an equilibrium field using a poloidal flux function $\psi_p(R, Z)$ and a toroidal current function $I(\psi_p)$.
The coordinates used are illustrated in figure~\ref{fig:coords}.
Physically $\psi_p$ represents the amount of flux through the circular disc with radius R centered on the $Z$ axis (indicated by the green circle in figure~\ref{fig:coords}.
$I$, which is sometimes called $F$ or $G$, represents the current through the same surface divided by 2$\pi$.

\begin{figure}\label{fig:coords}
  \begin{overpic}[scale=.5]{fig/torus.png}
    \put(80, 42){\Large $\theta$}
    \put(48, 60){\Large $Z$}
    \put(90, 40){\Large $R$}
    \put(55, 45){\Large $\phi$}
  \end{overpic}
  \caption{Coordinates used for generating the magnetic field. }
\end{figure}

The magnetic fields are calculated from $\psi_p$ and $I$ using:
\begin{equation}\label{eq:unperturbed}
  B_R = -\frac{1}{R} \frac{\partial \psi_p}{\partial Z}, \quad B_z= \frac{1}{R} \frac{\partial
  \psi_p}{\partial R}, \quad
  B_\phi = \frac{1}{R} I.
\end{equation}

For the poloidal flux function we use
\begin{equation}
  \psi_p = a^2,
\end{equation}
where $a=\sqrt{Z^2 + (R-R_0)^2}$ with $R_0$ the location of the equilibrium magnetic axis.
The surfaces of constant $\psi_p$, which are magnetic surfaces, are thus circular-cross-section concentric tori around a magnetic axis located at $R=R_0$.

For our current function $I$ we choose the following relation:
\begin{equation}
  I(\psi) = 2(q_0 + \gamma \psi_p)\sqrt{R_0-\psi_p}.
\end{equation}

The safety factor on each surface is calculated through~\cite{wesson2011tokamaks}:
\begin{equation}\label{eq:qprofint}
  q=\frac{1}{2\pi} \oint \frac{1}{R}\frac{B_\phi}{B_p}\mathrm{d} l,
\end{equation}
where $B_p=\sqrt{B_R^2+B_Z^2}$ is the magnitude of the poloidal magnetic field.
The integration is carried out over a magnetic surface, which in the circular-cross-section concentric toroidal geometry can be done analytically.
The quantity $R B_p$ is constant in this geometry, so we get:
\begin{equation}
  q = \frac{1}{2\pi} \frac{I(\psi_p)}{RB_p}\oint \frac{1}{R} \mathrm{d}l.
\end{equation}
We evaluate the integral by integrating over $\theta$ and using the identities $R=R_0 +a \cos(\theta)$ and $\mathrm{d}l = a \mathrm{d}\theta$ to yield:
\begin{equation}
  \oint \frac{1}{R} \mathrm{d}l = \int_0^{2\pi} \frac{a}{R_0 + a \cos(\theta)} \mathrm{d}l =
  \frac{2\pi a}{\sqrt{R_0^2 -a^2}}
\end{equation}
In the above integration we used the facts that $R_0>0$ and $R_0>a>0$.
This explains our choice of the function $I$, whose square root term cancels against the integrand, giving us the safety factor profile of:
\begin{equation}
  q=q_0 + \gamma \psi_p.
\end{equation}

The expressions in \ref{eq:unperturbed} thus give us an axisymmetric magnetic field where field lines lie on nested concentric toroidal magnetic surfaces with monotonically increasing safety factor.
For this calculation we choose the parameters $\gamma=1$ and $q_0=2/3$.
This field has no Shafranov shift (a shift of the magnetic axis outwards, induced by plasma pressure).
Including a Shafranov shift would make the factor $RB_p$ non-constant on a magnetic surface, thus requiring numerical integration for the evaluation of the integral in~\eqref{eq:qprofint}.

\section*{Internal Kink}
We calculate the change in magnetic field caused by an ideal displacement $\boldsymbol{\xi}$.
Here $\boldsymbol{\xi}(R, \phi, Z)$ is called the displacement vector that at every point specifies the direction and magnitude of the displacement.
In linearized ideal MHD, the first order change in magnetic field is given by the expression:
\begin{equation}\label{eq:kinky}
    \delta \mathbf{B} = \nabla \times (\boldsymbol{\xi} \times \mathbf{B}_0)
\end{equation}
(For those familiar with differential geometry, this expression can be interpreted as the first order effect of Lie dragging the magnetic field in the direction of the displacement vector; $\mathcal{L}_{\boldsymbol{\xi}} \mathbf{B} = \left[\boldsymbol{\xi}, \mathbf{B}\right]$. This reduces to equation~\eqref{eq:kinky} when $\boldsymbol{\xi}$ and $\mathbf{B}$ are divergence free and $\boldsymbol{\xi}$ is infinitesimal.)

The displacement associated with the internal kink is a rigid top-hat displacement of the entire region within the $q=1$ surface.
At different angles around the torus, the direction varies, making one full rotation around the torus.
Such a displacement would result in singularities in the perturbed magnetic field when equation~\eqref{eq:kinky} is evaluated.
These singularities correspond with current sheet formation, but will be troublesome for our numeric integration.

The rigid top-hat displacement of the internal kink has a limiting case that is the marginally stable quasi-interchange mode described by Waelbroeck~\cite{waelbroeck1989nonlinear}.
This mode occurs when the safety factor is flat and close to 1 in the core region.
To avoid singularities in our field we opt to implement this smooth displacement function.

The displacement vector is calculated from a stream function $\Psi$ given by the equation:
\begin{equation}
    \Psi = e^{-\frac{a^2}{\Delta^2}}\cos(n \phi - m \theta)
\end{equation}
Where $\Delta$ is a characteristic width that limits the extent of the displaced region.
The displacement is calculated from $\xi_R= -(1/R) (\partial \Psi/\partial z)$ and $\xi_Z= (1/R) (\partial \Psi/\partial R)$.
The $\phi$-component of the displacement vector is zero.

As can be seen from equation~\eqref{eq:kinky}, the perturbed field depends on the equilibrium field $\mathbf{B}_0$.

\section*{The Kadomtsev final state}
We would like to know the final state of the magnetic field after the sawtooth crash. We calculate the predictions of the Kadomtsev model~\cite{kadomtsev1975disruptive} adapting the derivation presented by Biskamp~\cite{Biskamp1997}. Employing the conservation of helical flux $\psi_*$, which is the component of the vector potential in the direction of a helical coordinate, one can find an expression for the final magnetic field. Taking our helical coordinate to be $(1,1)$, the expression for the helical flux in the large aspect ratio limit becomes:
\begin{equation}
    \psi_{*} = (1-q_0)a^2 - \frac{\gamma}{2}a^4.
\end{equation}
This $\psi_*$ has the shape of a ``Mexican hat" potential since $q_0<1$ and $\gamma>0$. The Kadomstev model states that during the crash surfaces inside the $q=1$ surface reconnect with the surfaces outside of the $q=1$ surface. In terms of helical flux, this means that surfaces with equal $\psi_*$ merge with one another.  The surfaces of equal $\psi_*$ can be found by solving the equation
\begin{equation}
    \psi_{*} = C = \text{constant.}
\end{equation}
Solving this equation to $a^2$ will yield two solutions, $a_i^2$ and $a_e^2$, with the property that $a_i^2 < a_e^2$. The final coordinate where the merged surfaces will end up can be found by employing conservation of area between the two merging surfaces,
\begin{equation}
    a_{\infty}^2 = a_e^2 - a_i^2
\end{equation}
Using this, we can find that the helical flux after reconnection becomes
\begin{equation}
    \psi_{*,\infty} = \frac{1}{2}\frac{(1-q_0)^2}{\gamma} - \frac{1}{8} \gamma a^4.
    \label{eq:final-helical-flux}
\end{equation}
Reconnection only occurs when there are two surfaces with equal flux. Otherwise the flux function is unchanged. The last radial coordinate where this reconnection occurs is the mixing radius $a_{\text{mix}}$ , and can be calculated to be
\begin{equation}
    a_{\text{mix}} = \sqrt{ \frac{2(1-q_0)}{\gamma} }.
\end{equation}
Since the toroidal field is mostly generated by the external coils, we expect that the toroidal magnetic field is unchanged. This means that the change in $\psi_*$ comes purely from the poloidal flux function. This results in the final poloidal flux function
\begin{equation}
    \psi_\infty = \begin{cases}
    \frac{3}{8} \gamma a^4 + q_0 a^2 + \frac{1}{2}  \frac{( 1 - q_0  )}{\gamma} , & a<a_{\rm mix} \\
    \psi_p, & a> a_{\rm mix}
    \end{cases}
\end{equation}
from which the magnetic field is calculated in the same way as equation~\eqref{eq:unperturbed}.
One can now also calculate the corresponding safety factor. It is found to be
\begin{equation}
    q_\infty(a) = \begin{cases}
    \frac{4 \gamma a^2 + 4 q_0}{3 \gamma a^2 + 4 q_0}, & a<a_{\rm mix} \\
    q_0 + \gamma a^2, & a>a_{\rm mix}
    \end{cases}
\end{equation}
This $q$-profile is larger than unity everywhere except at $a=0$, which is as expected. Furthermore, the $q$-profile is discontinuous at $a=a_{\text{mix}}$.

\section{Results}
We construct a Poincar\'e plot of the magnetic field.
A Poincar\'e plot gives a good sense of the magnetic topology.
It is calculated by taking a point in the $\phi=0$ plane, numerically calculating the magnetic field line passing through that point, and noting the location where the that field line passes through the $\phi=0$ plane every time it does so.
If a field line fills out a magnetic surface, and the the field line is followed for long enough, then the Poincar\'e section will start to fill out the circle that corresponds with the intersection of that magnetic surface and the $\phi=0$ plane.

This procedure is done for 100 different field lines, and each field line is given a different color.
Integration is carried out by a 5th order Runge-kutta method with adaptive step size that runs on a distributed computing network.
We also calculate the safety factor of each field line, buy counting the number of times it winds around the magnetic axis of the unperturbed field.
This information is shown below the Poincar\'e plot.
The Poincar\'e section for the unperturbed field (equation~\eqref{eq:unperturbed}) is visible in figure [REF TO FIG].

We can now calculate the total magnetic field, by making use of all our previously calculated functions. The magnetic field takes on the following form:
\begin{equation}\label{eq:totalfield}
    \mathbf{B}_{\text{total}}(\epsilon,\alpha) =  \mathbf{B}_0 + \alpha \mathbf{B}_{1,1}+ \epsilon (\mathbf{B}_\infty -\mathbf{B}_0).
\end{equation}
The factor $\alpha$ determines the strength of the internal kink perturbation, whereas $\epsilon$ linearly interpolates between the initial state and the final state, as predicted by the Kadomtsev model.

The effects of these two perturbations on the field can be interactively explored in figure [REF].
In figure [REF] different combinations of $\alpha$ and $\epsilon$ can be specifed along a path, and a Poincar\'e plot of every set of ($\alpha$, $\epsilon$) along this path will be computed.

When a path is chosen such that only $\alpha$ varies, but $\epsilon$ remains zero, we see the effect of the internal kink on the magnetic configuration.
As can be seen, this results in a shifting of the magnetic axis in the direction of the perturbation, and back again.

When only $\epsilon$ is varied, but $\alpha$ is kept constant, the magnetic structure does not change at all.
The only change is seen in the plot of the safety factor, which just linearly interpolates between the initial value of $q_0=2/3$ [change!] and $q_0=0.9$ in the final Kadomtsev state.

An interesting thing happens when we first apply the internal kink $\alpha$, and with this perturbation in place, start increasing $\epsilon$.
As soon as $\epsilon$ is non-zero, we see a drastic change in the magnetic structure.
We see a set of crescent-moon shaped curves in the Poincar\'e plot.
These are caused by field lines lying on a new type of magnetic surface, that does not surround the magnetic axis anymore.
Such a structure is called a \emph{magnetic island}.
Because this structure has appeared on the surface where previously $q=n/m=1/1$, this is called a $1/1$-island.
Opposite to the center of the island, we see the point where the tips of the crescent moon touch.
The point where the tips touch exactly is called an X-point.
There is a field line at the center of the X-point that comes back to itself after one rotation.

As we continue to increase  $\epsilon$, the size of the island keeps increasing, even when we keep $\alpha$ constant.
Increasing $\epsilon$ tends to flatten the safety factor profile, bringing $q$ closer to 1 everywhere in the core region.
As $q$ gets closer to 1, it means that field lines rotate around exactly once poloidally per toroidal rotation.
The perturbation $\mathbf{B}_{1,1}$ given by equation~\eqref{eq:kinky} has exactly the same angular dependence.
That means that the effect of $\mathbf{B}_{1,1}$ on the trajectory of a field line gets larger and larger, the closer $q$ gets to 1.
If $\mathbf{B}_{1,1}$ adds a little push to the direction of a field line in one location, it will be adding the same push further along, and at every point, eventually completely changing the trajectory of the field line.
This effect, where the magnetic structure is strongly affected even by a very small perturbation, if the effect accumulates in this way, is called \emph{magnetic resonance}.

As we change $\epsilon$ towards 1, the safety factor becomes flatter, and closer to 1.
This means that the effect of the internal kink becomes stronger, pushing the original magnetic axis further out, and at the same time increasing the size of the island.
When $\epsilon$ gets really close to 1, the original axis gets closer and closer to the X-point, and fewer and field lines surround it, while more and more field lines are part of the island.
Before $\epsilon$ reaches 1, the effect of the kink is already so strong, that the original axis is pushed into the X-point, and both disappear!

The island has grown so large that it has completely taken over, and the original axis has completely disappeared.
If we have not returned $\alpha$ to zero, the magnetic field in the core will still be strongly distorted.
But the drive for such a perturbation has disappeared now that the safety factor is above 1 everyhwere, so the last step should be to return $\alpha$ to 1, and see that the magnetic structure becomes axisymmetric again.
The final step is to return to the original profile with $q_0<1$, from which the cycle starts anew.

- fast and slow
- kink triggering
- realistic path

\section*{Conclusions and Discussion}
The model we have presented above gives a very simple intuitive picture of a minimal set of perturbations that result in the topological changes associated with the Kadomtsev sawtooth process.
We take two effects; the ideal kink and a linear interpolation between two axisymmetric states, to reproduce the changes in magnetic topology that constitute the Kadomtsev satwooth.

The evolution of the magnetic structure exhibited by our model is probably simpler than what would be physically realized.
A better approximation would be given by the models presented in~\cite{kolesnichenko1996theory, jaulmes2014redistribution}, as these models give a physical picture for the intermediate states between initial and final state (they for example conserve flux during the process, which the process presented here does not necessarily do).
Nevertheless, the states in these models will also not correspond exactly to the actual magnetic state during the sawtooth crash, as there will be many other effects present such as current sheet formation, deformation of the shape of the original axis, etc.

\subsection*{Acknowledgements}
We would like to thank H. J. De Blank for enlightening discussions. We would like to thank the entire KingsDS team, D. Desjardins, KC Erb, and P. Navaeiopour, for implementing the model on the distributed computing network.

\bibliographystyle{naturemag}
\bibliography{refs}

\end{document}


\chapter{De-Entanglement by Priors - Case study with Acoustic Unit Discovery}

\section{Problem Introduction}
A major bottleneck in the progress of many data-intensive language processing tasks such as speech recognition and synthesis is scalability to new languages and domains.
Building such technologies for unwritten or under-resourced languages is often not feasible due to lack of annotated data or other expensive resources.
A fundamental resource required to build such a stack is a phonetic lexicon - something that translates acoustic input to textual representation. Having such a lexicon, even if noisy, can help bootstrap speech recognition models, synthesis, and other technologies. Typical approaches may involve a pivot language or bootstrapping or adapting from a closely related high-resource language.
But, this can be a deceptively non-trivial task due to linguistic differences which can pose inherent difficulties.
For instance, it may be unreasonable to analyze a Sino-Tibetan language using English as a source. Moreover, using an additional language might make the model learn unintended surface level associations or biases between the participating languages that prevent them from generalizing across languages. Associations between these languages over a set of units that may better generalize to other languages. Therefore, in this paper we are interested in discovering the appropriate acoustic phonetic units.

\begin{figure}[t]
\centering
\includegraphics[width=80mm,scale=0.5]{images/vaconda_architecture_zerospeech2019.png}
\caption{Illustration of our procedure for automatically discovering acoustic units from a speech utterance. We pass the speech utterance through a downsampling encoder. The encoded representation is hashed to a latent code based on a discrete articulatory prior bank. The code is passed to the decoder, a WaveNet using speaker embeddings as global conditioning that regenerates audio. }
\label{frame_replacement_overview}
\end{figure}

In ZeroSpeech Challenge\citep{zerospeech2019} resynthesis is considered a good proxy task to evaluate the performance of systems when training using unsupervised approaches. To accomplish this we use neural generative models. %Resynthesis might be a good proxy.
Deep Neural Generative models have seen a tremendous amount of progress in the recent past. These models aim to model the joint probability of the data distribution and the conditioning information as a product of conditional distributions. Typical implementations of such models follow an autoregressive framework, although other formulations have been suggested as well. Such models have been shown very effective in addressing one of the major challenges with conventional vocoding techniques - fidelity.
Neural generative models has been shown to generate speech that rivals natural speech when conditioned on predicted mel spectrum \citep{shen2017natural}. Speech has a lot of natural variations in terms of content, speaker, channel information, speaking style, prosodic variations, etc. Accordingly, we are interested in models which have flexibility to  marginalize such variations but preserve the phonetic content and distinguish meaningful differences between phonetic units.To accomplish this, we employ sequence to sequence models with latent random variables (referred to as latent stochastic models hereafter). These models provide a mechanism to jointly train both the latent representations as well as the downstream inference network. They are expected to both discover and disentangle causal factors of variation present in the distribution of original data, so as to generalize at inference time. While training latent stochastic models, optimizing the exact log likelihood can be intractable. To address this, a recognition network is employed to approximate the posterior probability using reparameterization \citep{vae}. When deployed in encoder-decoder models, this approach is often subject to an optimization challenge referred to as KL-collapse \citep{bowman_continuous}, wherein the generator (usually an RNN) marginalizes the learnt latent representation. Typical approaches to dealing this issue involve annealing the KL divergence loss~\citep{bowman_continuous,zhou2017multi}, weakening the generator \citep{zhao2017learning} and ensuring the recall using bag of words loss.  In our work, we present an approach to deal with the KL-collapse problem by vector quantization in the latent space.  Building on \citep{vq-vae, chorowski2019unsupervised}, we add additional constraints in the prior space forcing the latent representations to follow articulatory dimensions: The encoded representation is hashed to a latent code based on a articulatory prior bank designed using a discrete codebook. Our decoder is a conditional WaveNet using speaker embedding as global embedding trained to regenerate input audio using the  code sequence as local information.

\section{Background - Acoustic Unit Discovery}

Let us consider a speech corpus X which consists of speakers $\{ s_1, s_2...,s_n \}$. The goal of acoustic unit discovery is to come up with a set of units \textbf{U} that represent a speech utterance \textit{x} $\subset$ X allowing robust resynthesis. %comprehensively.
The elements of such a set also might conform to desirable characteristics  such as being injective, consistent and compact, i.e. that different inputs should have discriminant acoustic units, but expected variance such as speaker or dialect should produce the same acoustic units. %, and the set of units should be
% We aim to discover a minimal set of units to fit these goals.
%must be well corresponding to the acoustic vectors(predictable)

There have been numerous attempts to discover such acoustic units in an unsupervised fashion. In \citep{subword_diarization}, authors presented an approach to modify the speaker diarization system to detect speaker-dependent acoustic units. \citep{unsupervised_AMtraining_ArenJansen} proposed a GMM-based approach to discover speaker-independent subword units. However, their system requires a separate Spoken Term Detector. Recently, due to the surge of deep generative model, using unsupervised method such as auto-encoder and variational auto-encoder (VAE). \citep{badino_autoencoder} designed a stacked AutoEncoder using backpropagation and then cluster the representations at the bottleneck layer. To avoid quick transitions leading to repeated units, they employed a smoothing function based on transition probabilities of the individual states. \citep{hmm-vae_bhiksha} extended the structured VAE to incorporate the Hidden Markov Models as latent model. \citep{vq-vae, chorowski2019unsupervised} proposed VQ-VAE and argue that by vector quantization the ``“posterior collapse" problem could be circumvented.

\section{\textit{VACONDA}}
\label{proposed_approach}

\subsection{Analysis of optimization and de-entanglement}
\label{analysis}

WaveNet \citep{van2016WaveNet} is an autoregressive neural model with a stack of 1D convolutional layers that is capable of directly generating audio signal. It has been shown to produce generated speech that rivals natural speech when conditioned on predicted mel spectrum \citep{shen2017natural}. The input to WaveNet is subjected to corresponding gated activations while passing through each dilated convolutional layer and is classified by the final softmax layer into a $\mu$ law encoding.  The concrete form of the residual gated activation function is given by following equation:

\begin{equation} \label{WaveNet_Eqn}
\begin{split}
  r_d(x) = tanh(W_{f} * x) \odot \sigma (W_{g} * x)  \\
\end{split}
\end{equation}

\noindent where $x$ and $r_d(x)$ are the input and output with dilation $d$, respectively. The symbol $*$ is a convolution operator with dilation $d$ and the symbol $\odot$ is an element-wise product operator. $W$ represents a convolution weight. The subscripts $f$ and $g$ represent a filter and a gate, respectively. The joint probability of a waveform \textbf{X} can be written as:

\begin{equation} \label{WaveNet_gen_Eqn}
\begin{split}
  P(X | \theta)  = \prod_{t=1}^{T} P(x_t | x_1, x_2 .. x_{t-1}, \theta)  \\
\end{split}
\end{equation}

\noindent given model parameters $\theta$. During implementation of WaveNet, the autoregressive process is realized by a stack of dilated convolutions. The final output $y_t$ at time step $t$ can be expressed mathematically as:

\begin{equation}
\begin{split}
  \hat{y_t} \sim \sum_{d=0}^{D} h_d * r_d(x) \\
\end{split}
\label{WaveNet_Eqn}
\end{equation}

\noindent where $x$, $y$ represent input and output vectors; $D$ is the number of different dilation used and $d$ is the dilation factor; $h_d$ is the convolution weights. This stack of convolutions is repeated multiple times in the original WaveNet. Optimization in WaveNet is performed based on the error between predicted sample and the ground truth sample conditioned on previous samples in the receptive field alongside the local conditioning. Expressing the loss function being optimized mathematically the error at sample $t$ is:

\begin{equation} \label{discrete_Eqn}
\begin{split}
  l_t = Div(\hat{y_t} || y_t)
\end{split}
\end{equation}

Here, we define the divergence similar to the \citep{salimans2017pixelcnn++}, To optimize this loss, the contribution from the individual convolution layers towards this global error function must be nullified. Now let us consider the expression for intermediate output for a single filter in Eqn~\ref{WaveNet_Eqn}:

\begin{equation}
\begin{split}
  x_{out}(t) = \sum_{\tau=0}^{t} h(\tau)x(t-\tau)
\end{split}
\end{equation}

\noindent where $\tau$ is the receptive field covered by the model and $h(\tau)$ represents the discrete state representation at time $t$. Without loss of generality and dropping the term $\tau$ for brevity, the spectral representation generated by the model can be expressed as:

\begin{equation} \label{transfer_function_representation}
  Y(z)  = H(z) X(z)
\end{equation}

Considering the discrete nature of input from Eqn \ref{discrete_Eqn}, an interpretation of Eqn \ref{transfer_function_representation} is that the neural autoregressive model acts as the transfer function and is discretized by convolving with the samples from original signal. It has to be noted that this is similar to the formulation of source filter model of speech, specifically the periodic components aka voiced sounds. Voiced sounds typically represented as impulse train are convolved with the transfer function to generate spectral envelope. As a corollary, from Eqn \ref{discrete_Eqn} and \ref{transfer_function_representation}, we posit that the optimization in WaveNet model is performed by minimizing the divergence between true and approximate spectral envelope. Note that latent stochastic models such as VAEs are aimed to minimize the divergence between true and approximate posterior distributions of input data. The advantage with such models is the presence of stochastic random variables that capture the causal factors of variation in input based on some prior information about the distributional characteristics of data. Techniques aimed at this \citep{beta_vae} have shown that it is possible to effectively disentangle the factors of variation using stochastic variables. Hence, we postulate that it should be possible to augment WaveNet decoder with a suitable encoder and an appropriate prior distribution to disentangle the acoustic phonetic units from a given utterance.

However, this is a deceptively non-trivial task. If the prior is too simplistic, such as unit normal distribution, the model is trivially incentivized to force the posterior distribution to closely follow the Gaussian prior distribution \citep{lossy_vae}, particularly early in training. This results in the decoder marginalizing out the latent variable completely, manifesting in poor reconstruction ability. On the other hand, making the prior distribution arbitrarily complex also leads to unreasonable constraints on the decoder. For instance, in scenarios that have categorical distributions as their output (tasks such as language modeling, machine translation, and image captioning among others) it is unintuitive to assume that the true prior that generates latent distribution is a Gaussian when the likelihood is based on discrete sequential data. We make an observation that dealing with speech presents a characteristic advantage - speech has both continuous as well as discrete priors. The generative process of speech assumes a Gaussian prior distribution which is continuous in nature. However, the language which is also present in the utterance can be approximated to be sampled from a discrete prior distribution. Exact manifestation of this in the linguistics can be at different levels: phonemes, words, syllables, subword units, etc. From the analysis presented in the previous section, we hypothesize that if we use background knowledge about the data distribution while designing the priors, we can help the encoder effectively disentangle the latent causal factors of variation in the data. In other words, this presents us with an opportunity to control what gets disentangled in the latent space by appropriately choosing a prior distribution. Therefore, we engineer our prior space to account for the phonetic information in the utterance by representing the prior as a discrete latent variable bank, similar to the filterbanks used for feature extraction from speech. Each discrete latent variable has a different set of states reflecting one of the articulatory dimensions. The specific design of our latent space is highlighted in Table \ref{articulatory features}.

\renewcommand{\arraystretch}{1.0}
\begin{table}[t]
\caption{Articulatory Features\label{tab:arti}}
\centering
\begin{tabular}{l | c | c}\toprule[\heavyrulewidth] \textbf{Feature name} & \textbf{Value} & \textbf{Details} \\
\toprule[\heavyrulewidth]
vc & + - 0 & vowel or consonant \\
vlng & s l d a 0 & vowel length\\
vheight & 1 2 3 0 - & vowel height \\
vfront & 1 2 3 0 - & vowel frontness\\
vrnd & + - 0 & lip rounding\\
ctype & s f a n l r 0 & consonant type \\
cplace & l a p b d v g 0 & place of articulation \\
cvox & + - 0 & consonant voicing\\
asp & + - 0 & consonant voicing\\
nuk & + - 0 & consonant voicing\\
\bottomrule[\heavyrulewidth]
\end{tabular}
\label{articulatory features}
\end{table}

\section{Experiments}
\label{expts}

\subsection{ZeroSpeech 2019 dataset}
% The goal of ZeroSpeech dataset is to learn the Phonetic representation of the audio without any supervision, discover the symbolic representation of the audio, and resynthesize the audio using these unit. The evaluation metric look at both the quality of sub-unit and the resynthesized audio.

ZeroSpeech Challenge 2019: TTS without T is to propose to build a speech synthesizer without any text or phonetic labels~\citep{sakti2008development1, sakti2008development2, zerospeech2019}. The systems are required to extract the symbolic representation of the raw audio, and then re-synthesize the audio using these discovered units. There are three datasets in total: (1) \textit{Unit Discovery Dataset} provides audio from a variety of speakers and is used to unsupervised acoustic modeling, (2)  \textit{Voice Dataset} provides audio from the targeted speaker and is used for synthesizer modeling and (3)  \textit{Parallel Dataset} is intended for finetuning both the sub-systems. We have not utilized the parallel dataset for our observations in this study. The development language is English and the test language is Standard Indonesian. The system is constrained to not use any pre-existing resource or models. To ensure that the model generalizes out of the box, the hyperparameter will be fine-tuned only on the development dataset, and the model will be trained in test language under the same parameters.

\iffalse
\begin{enumerate}
    \item \textit{Unit Discovery Dataset} provides audio from a variety of speakers and is used to unsupervised acoustic modeling
    \item \textit{Voice Dataset} provides audio from the targeted speaker and is used for synthesizer modeling
    \item \textbit{Parallel Dataset} is used for finetuning the both sub-systems
\end{enumerate}

The development language is English and the test language is Standard Indonesian. The system is refrained from using any pre-existing resource or models. To ensure that the model generalizes out of the box, the hyper-parameter will be fine-tuned only on the development dataset, and the model will be trained in test language under the same parameters.
\fi

% \subsubsection{CSTR VCTK Corpus}

% CSTR VCTK is an English speech dataset, which contains 109 native speakers with various accents. Each speaker is required to record 400 sentences from newspaper, plus Rainbow Passage and an elicitation paragraph intended to identify the speaker's accent.

%\subsection{Implementation Details}

% CSTR VCTK Corpus includes speech data uttered by 109 native speakers of English with various accents. Each speaker reads out about 400 sentences, most of which were selected from a newspaper plus the Rainbow Passage and an elicitation paragraph intended to identify the speaker's accent
%
% newspaper sentences,

\iffalse
Our voice building process employs the phone sharing approach as outlined in \citep{rallabandi_mixedlingual_IS2017} - where the combined phoneset is formed by the union of phones from both the languages - to build acoustic models. In this section, we present our approaches to generate the required bilingual acoustic data using just monolingual recordings. Specifically, in each of the subsections, we introduce the approaches we follow to artificially generate spectral content in English. We then follow the outlined procedure to build a bilingual voice using the native (L1) recordings and `pseudo English' (L2) recordings.

In this section, present our approaches for ZeroSpeech 2019. Specifically, our aim is to build robust models capable of accomplishing (1) Discovering acoustic units given a speech utterance. and (2) Generating novel utterances conditioned on the discovered acoustic units. For this, we have built two systems: (1) System A which is a pipeline based approach and (2) System B which is an end-to-end approach.
\fi

\section{Baseline System}

We have a three-stage pipeline: (1) \textit{Unit Discovery}: We hypothesize acoustic units given a speech utterance using latent Stochastic Models; (2) \textit{Unit Alignment}: We fine-tune the alignment between the utterance and the proposed acoustic units ; (3) \textit{Unit Synthesis}: We build a speech synthesizer using the acoustic units and the target voice.

%In this section, we will elaborate on each of the three stages.

%\subsubsection{Acoustic Unit Discovery}
%\subsubsection{Acoustic Unit Alignment}

As proposed in \citep{sitaram2013bootstrapping}, we take the initially discovered transcription of the acoustic units for our speech corpus and train an ASR model on it. Then we re-encode the corpus using the ASR model, and train a TTS system on it. Here we using Bi-LSTM with CTC loss as our ASR model, and tacotron \citep{tacotron_transferlearning2multispeaker} as TTS system.

% At each iteration, an acoustic model is trained from the parallel speech-transcription data. This acoustic model is then used to re-decode the speech data, and so on for 10 iterations. At the end of each iteration, we have produced a rebuilt acoustic model and a re-decoded transcript. These two are used to build a synthetic CLUSTERGEN \citep{black2006clustergen} voice (given the noise in the generated data, statistical parametric synthesis is appropriate) using Festvox for the purpose of evaluation on a held out test set on the basis of MCD scores. The best-aligned transcription is taken as the one producing the synthetic voice with the lowest distortion score.

%\subsubsection{Acoustic Unit Synthesis}

\begin{figure}[t]
  \centering
  \subfigure[Original speech]{
    \includegraphics[width=0.95\linewidth]{images/target4.png}}
\subfigure[Generated speech]{
    \includegraphics[width=0.95\linewidth]{images/generated4.png}}
\subfigure[Converted speech]{
    \includegraphics[width=0.95\linewidth]{images/transferred4.png}}
  \caption{Spectrograms of original, generated, and converted speech. The source speaker is female while the target speaker is male.\label{fig:waveform}}
\end{figure}

\subsection{VACONDA}

The architecture of our model is built on top of VQ-VAE. It consists of three modules: an encoder, quantizer and a decoder. As our encoder, we use a dilated convolution stack of layers which downsamples the input audio by 64. The speech signal was power normalized and squashed to the range (-1,1) before feeding to the downsampling encoder. To make the training faster, we have used chunks of 2000 time steps. This means we get 31 timesteps at the output of the encoder. The quantizer acts as a bottleneck and performs vector quantization to generate the appropriate code from a parameterized codebook. We define the latent space $e \in \mathbmm{R}^{k\times d}$ to contain $k$ $d$-dim continuous vector. Quantization is implemented using minimum distance in the embedding space. The number of classes was chosen to be 64, approximating 64 universal phonemes. We use a linear mapping to first project the 128 dimensional vector to 160 dimensions. We then perform comparisons with respect to individual articulatory dimensions each of which is 16 in size.  Assuming $z_e(x)$ denotes the encoder output in the latent space, then the input of decoder $z_d(x)$ will be obtained by $\argmin_{j}d(e_j, z_e(x))$, where $d$ is a similarity function of two vectors. In this paper, we consider Euclidean distance as the similarity metric.  Our decoder is an iterated dilated convolution-based WaveNet that uses a 256-level quantized raw signal as the input and the output from vector quantization module as the conditioning. Although using a Mixture of Logistics loss function might yield a better output, we have only used a 256 class softmax in this study. The decoder takes the output from the quantizer along with the speaker label as global conditioning and aims to reconstruct the input in an autoregressive fashion. Following IDCNNs, we have shared the parameters of all the stacks.

% In this subsection we describe our end-to-end approach for the task. We extend the framework proposed in \citep{vq-vae} to accomplish subword unit discovery. Although a structure such as HMM \citep{hmm-vae_bhiksha} might be intuitively better at capturing the transitions, we have limited ourselves to a vector quantization based approach as we observed it to be better at handling the posterior collapse problem in VAEs. We have used 3 stacks of 10 layers each in the decoder and residual blocks with similar dilation factors in each of the stacks shared their parameters \citep{strubell2017fast}.

% Our voice building process employs the VQ-VAE approach as outlined in \citep{rallabandi_mixedlingual_IS2017}, where the raw audio is first fed to a downsampling encoder which reduces the time resolution by 64. This encoded representation is then hashed into a latent representation that is forced to follow articulatory constraints. Specifically, we employ a set of discrete embeddings of cardinality 5, where each is a multi-dimensional array in itself associated with a continuous vector. The output from this hash function is fed to the decoder, which is a conditional WaveNet implemented using iterated dilated convolutions. In this section, we first present our analysis of the optimization that happens in our models. We then present a case for controlling the disentanglement that happens in such models to accomplish voice conversion. This is followed by an explanation of each component in our model in detail.

% Aside from the architecture discussed in Section~\ref{proposed_approach}, we argue that adding meaningful inductive bias can help the model learn better. We first normalize the vector representation to ensure the same scale in the latent space. Compared to VQ-VAE, we incorporate the articulatory features information in Table~\ref{tab:arti}. The above articulatory features apply to all human languages. To incorporate them, we first transpose the embedding from 128-dimension to 160-dimension by a linear layer. Then, we equally divide the latent embedding into 10 parts, and perform the vector quantization separately. Finally we concatenate all vectors, and feed into the linear layer to map it back to 128-dimension. In each class, the number of latent embedding is the number of possible values.

\subsection{Analysis}

In this section, we will discuss different design choices in the architecture, including input features and latent space constraints.

% \subsubsection{Input Feature}

% We first compare the performance gap between different features as our model's input. The feature used along with its performance is shown in Table~\ref{tab:input}.

\subsubsection{Acoustic Unit Discovery}

Here we analyze the AUD performance of three different models in ZeroSpeech dataset as shown in Table~\ref{tab:aud}. We only show the results in English since we don't have ground truth for the Indonesian language.

% Now all is baseline

\renewcommand{\arraystretch}{1.1}
\begin{table}[!htbp]
\caption{Performance of different systems in ZeroSpeech}
\centering
\begin{tabular}{l c c}\toprule[\heavyrulewidth]
& \multicolumn{2}{c}{English}\\
Model & ABX score & bitrate \\
\toprule[\heavyrulewidth]
Baseline & \textbf{27.46} & 74.5\\
Three-stage Model & 34.86 & 68.54 \\
VACONDA & 38 & \textbf{58.19} \\

\bottomrule[\heavyrulewidth]
\end{tabular}
\label{tab:aud}
\end{table}

As in Table~\ref{tab:aud}, the VACONDA achieves the best bit rate among three models. With such small number of unit, we could resynthesize and even convert the speech in a very high quality.

\subsubsection{Speech Resynthesis and Conversion}

The proposed model supports synthesizing the same speech in both the same speaker and a different speaker. Here we show a sample in the test dataset of Indonesian language in Figure~\ref{fig:waveform}. When we feed the decoder with the same speaker identification, the decoder will generate the original audio. Otherwise, it will perform speech convertion. The three audio shares similar structure.  However, the converted audio has denser waveform, suggesting it's a different speaker. For the sampled audio, please visit the \href{http://tts.speech.cs.cmu.edu/rsk/campaigns/interspeech2019/submissions/acoustic_unit_discovery/}{our website}.

%The results are shown in Table~\ref{tab:constraints}. We use

% \renewcommand{\arraystretch}{1.1}
% \begin{table}[htbp]
% \caption{System performance with latent space constraints}
% \centering
% \begin{tabular}{l | c}\toprule[\heavyrulewidth] \textbf{Model} & \textbf{ABX score}\\
% \toprule[\heavyrulewidth]
% Baseline model & 12\\
% \bottomrule[\heavyrulewidth]
% \end{tabular}
% \label{tab:constraints}
% \end{table}

\label{analysis}

\subsection{Conclusion}

In this case study, we present an approach to automatically discover acoustic-phonetic units from a speech utterance in an unsupervised fashion. We first present an analysis to show that incorporating latent random variables into neural generative models using suitable priors allows us to control what gets encoded into the latent space. Based on this, we employ articulatory features as a discrete prior bank in the latent space and obtain acoustic units that are speaker and language independent.  To validate effectiveness of the discovered units, we perform discriminability tests as part of ZeroSpeech Challenge 2019.


\section{Extending Extended \UTXO}
\label{sec:EUTXOma}

Before discussing applications and the formal model of \EUTXOma, we briefly summarise the structure of \EUTXO, and then informally introduce the multi-asset extension that is the subject of this paper.
Finally, we will discuss a shortcoming in the state machine mapping of \EUTXO\ as introduced in~\cite{eutxo-1-paper} and illustrate how the multi-asset extension fixes that shortcoming.

\subsection{The starting point: Extended \UTXO}
\label{sec:informal-eutxo}

In Bitcoin's \UTXO\ ledger model, the ledger is formed by a list of transactions grouped into blocks.
As the block structure is secondary to the discussion in this paper, we will disregard it in the following.
A transaction $\tx$ is a quadruple \((I, O, r, S)\) comprising a set of \emph{inputs} $I$, a list of \emph{outputs} $O$, a \emph{validity interval} $r$, and a set of signatures $S$, where inputs and outputs represent cryptocurrency value flowing into and out of the transaction, respectively.
The sum of the inputs must be equal to the sum of the outputs; in other words, transactions preserve value.
% True, but not crucial IMHO and we need to save space. -= chak
%\footnote{
%  Real transactions will likely have other fields that need to be balanced, such as fees or new tokens that are minted or forged.
%  We will omit these for now for simplicity, but in general they also need to observe preservation of value.
%}
Transactions are identified by a collision-resistant cryptographic hash $h$ computed from the transaction.\footnote{%
  We denote the hash of some data $d$ as $d^\#$.%
}

An input $i\in I$ is represented as a pair \((\outRef, \rho)\) of an \emph{output reference} $\outRef$ and a \emph{redeemer value} $\rho$.
The output reference $\outRef$ uniquely identifies an output in a preceding transaction by way of the transaction's hash and the output's position in the transaction's list of outputs.

In plain \UTXO, an output $o\in O$ is a pair of a \emph{validator script} $\nu$ and cryptocurrency value $\val$.
In the Extended \UTXO\ model (\EUTXO)~\cite{eutxo-1-paper}, outputs become triples \((\nu, \val, \delta)\), where the added \emph{datum} $\delta$ enables passing additional information to the validator.

The purpose of the validator is to assess whether an input $i$ of a subsequent transaction trying to spend (i.e., consume) an output $o$ should be allowed to do so.
To this end, we execute the validator script to check whether \(\nu(\rho, \delta, \sigma) = \true\) holds.
Here $\sigma$ comprises additional information about the \emph{validation context} of the transaction.
In the plain \UTXO\ model that contextual information is fairly limited: it mainly consists of the validated transaction's hash, the signatures $S$, and information about the length of the blockchain. In the \EUTXO\ model, we extend $\sigma$ to include the entirety of the validated transaction $\tx$ as well as all the outputs spent by the inputs of $\tx$.

\subsection{Token bundles}
\label{sec:informal-token-bundles}

In \UTXO\ and \EUTXO, the $\val$ carried by an output is represented as an integral value denoting a specific quantity of the ledger's native cryptocurrency.
As discussed in more detail in the companion paper~\cite{plain-multicurrency}, we can generalise $\val$ to carry a two-level structure of \emph{finitely-supported functions.}
The technicalities are in Appendix~\ref{app:model}; for now, we can regard them as nested finite maps to quantities of tokens.
For example, the value
\(\{\mathsf{Coin} \mapsto \{\mathsf{Coin} \mapsto 3\}, g \mapsto \{t_1
\mapsto 1, t_2 \mapsto 1\}\}\) contains $3$ $\mathsf{Coin}$ coins
(there is only one (fungible) token $\mathsf{Coin}$ for a payment
currency also called $\mathsf{Coin}$), as well as (non-fungible) tokens $t_1$ and $t_2$,
both in asset group $g$.  Values can be added naturally, e.g.,
\begin{align*}
 & \{\mathsf{Coin} \mapsto \{\mathsf{Coin} \mapsto 3\}, g \mapsto \{t_1
   \mapsto 1, t_2 \mapsto 1\}\} \\
 + \ & \{\mathsf{Coin} \mapsto \{\mathsf{Coin} \mapsto 1\}, g \mapsto \{t_3 \mapsto 1\}\} \\
 = \ & \{\mathsf{Coin} \mapsto \{\mathsf{Coin} \mapsto 4\}, g \mapsto \{t_1
       \mapsto 1, t_2 \mapsto 1, t_3 \mapsto 1\}\} \ .
\end{align*}
%
In a bundle, such as \(g \mapsto \{t_1 \mapsto 1, t_2 \mapsto 1, t_3 \mapsto 1\}\), we call $g$ an \emph{asset group} comprising a set of tokens $t_1$, $t_2$, and $t_3$. In the case of a fungible asset group, such as $\mathsf{Coin}$, we may call it a \emph{currency}.
In contrast to fungible tokens, only a single instance of a non-fungible token may be minted.

\subsection{Forging custom tokens}

To enable the introduction of new quantities of new tokens on the ledger (\emph{minting}) or the removal of existing tokens (\emph{burning}), we add a \emph{forge field} to each transaction.
The use of the forge field needs to be tightly controlled, so that the minting and burning of tokens is guaranteed to proceed according to the token's \emph{forging policy}.
We implement forging policies by means of scripts that are much like the validator scripts used to lock outputs in \EUTXO.

Overall, a transaction in \EUTXOma\ is thus a sextuple \((I, O, r, \forge, \fpss, S)\), where $\forge$, just like $\val$ in an output, is a token bundle and $\fpss$ is a set of \emph{forging policy scripts}.
Unlike the value attached to transaction outputs, $\forge$ is allowed to contain negative quantities of tokens. Positive quantities represent minted tokens and negative quantities represent burned tokens.
In either case, any asset group $\phi$ that occurs in $\forge$ (i.e., \(\forge = \{\ldots, \phi \mapsto \mathit{toks}, \ldots\}\)) must also have its forging policy script in the transaction's $\fpss$ field.
Each script $\pi$ in $\fpss$ is executed to check whether $\pi(\sigma) = \true$, that is whether the transaction, including its $\forge$ field, is admissible.
\ifootnote{%
  In fact we have a slightly different $\sigma$ here, which we elaborate on in Appendix~\ref{app:model}.%
}

\subsection{Constraint emitting machines}
\label{sec:cem-example}
In the \EUTXO\ paper~\cite{eutxo-1-paper}, we explained how we can map \emph{Constraint Emitting Machines} (CEMs) ---a variation on Mealy machines--- onto an \EUTXO\ ledger. A CEM consists of its type of states \s{S} and inputs
\s{I}, predicates $\s{initial}, \s{final} : \s{S} \rightarrow \B$
indicating which states are initial and final, respectively, and a valid set of transitions,
given as a partial function $\s{step} : \s{S} \rightarrow \s{I} \rightarrow
\s{Maybe}\ (\s{S} \times \s{TxConstraints})$ from source state and input symbol to
target state and constraints.
\ifootnote{%
  The result may be \s{Nothing}, in case no valid transitions exist from a given state/input.%
}
%
One could present CEMs using the traditional five-tuple notation $(Q, \Sigma, \delta, q_0, F)$,
but we opt for functional notation to avoid confusion with standard \textit{finite state machines}
(see \cite{eutxo-1-paper} on how CEMs differ from FSMs),
as well as being consistent with our other definitions.

A sequence of CEM state transitions, each of the form $\CStepArrow{s}{i}{\txeq}$, is mapped to a sequence of transactions, where each machine state $s$ is represented by one transaction $\tx_s$. Each such transaction contains a \emph{state machine output} $o_s$ whose validator $\nu_s$ implements the CEM transition relation and whose datum $\delta_s$ encodes the CEM state $s$.

The transition $\tx_{s'}$, representing the successor state, spends $o_s$ with an input that provides the CEM input $i$ as its redeemer $\rho_i$. Finally, the constraints $\txeq$ generated by the state transition need to be met by the successor transition $\tx_{s'}$. (We will define the correspondence precisely in \S\ref{sec:formalization}.)

\begin{figure}[t]
  \centering
  \begin{tikzpicture}[
    state/.style =
    { shape        = circle,
      fill         = gray!40,
      align        = center,
      font         = \large,
      minimum size = 2.5cm },
    transition/.style =
    { ->,
      thick },
    move/.style =
    { align  = center,
      anchor = center,
      font   = \small }
  ]
  \node[state] (a) {\Holding};
  \node[state, right = 3cm of a] (b) {\msf{Collecting}\\\normalsize ($v$, $p$, $d$, $sigs$)};

  \path
  (a.north east) edge[transition, bend left = 15]
    node[move, above] {$\Propose{v}{p}{d}$\\$sigs' = \{\}$}
  (b.north west)
  (b) edge[transition, out = 30, in = -30, looseness = 3]
      node[move, right] {\Add{sig}\\$sigs' = sigs \cup sig$\\ if $sig \in sigs_{auth}$}
      (b)
      edge[transition, bend left = 15]
      node[move, above] {\Pay\\if $|sigs| \geq n$}
      (a)
      edge[transition, bend left = 30]
      node[move, below] {\Cancel\\if $d$ expired}
      (a)
  ;
  \end{tikzpicture}
  \caption{Transition diagram for the multi-signature state machine;
    edges labelled with input from redeemer and transition constraints.}
  \label{fig:multisig-machine}
\end{figure}

A simple example for such a state machine is an on-chain $n$--of--$m$ multi-signature contract. Specifically, we have a given amount
$\val_\msc$ of some cryptocurrency and we require the approval of at
least $n$ out of an \textit{a priori} fixed set of $m \geq n$ owners to spend
$\val_\msc$. With plain \UTXO{} (e.g., on Bitcoin), a multi-signature
scheme requires out-of-band (off-chain) communication to collect all
$n$ signatures to spend $\val_\msc$. On Ethereum, and also in the
\EUTXO{} model, we can collect the signatures on-chain, without any
out-of-band communication. To do so, we use a state machine operating
according to the transition diagram in
Figure~\ref{fig:multisig-machine}, where we assume that the threshold
$n$ and authorised signatures $\sigs_\auth$ with \(|\sigs_\auth| = m\)
are baked into the contract code.

In the multi-signature state machine's implementation in the \EUTXO{} model, we use a validator
function $\nu_\msc$ accompanied by the datum $\delta_\msc$ to lock
$\val_\msc$. The datum $\delta_\msc$ stores the machine state,
which is of the form \(\Holding\) when only holding the locked value
or \(\Collecting{\val}{\kappa}{d}{\sigs}\) when collecting
signatures $\sigs$ for a payment of $\val$ to $\kappa$ by the deadline
$d$. The initial output for the contract is \((\nu_\msc, \val_\msc,
\Holding)\).

The validator $\nu_\msc$ implements the state transition diagram from
Figure~\ref{fig:multisig-machine} by using the redeemer of the spending input to determine the transition that needs to be taken. That redeemer (state machine input) can take four forms:
\begin{inparaenum}[(1)]
\item \(\Propose{\val}{\kappa}{d}\) to propose a payment of $\val$ to $\kappa$
  by the deadline $d$,
\item \(\Add{\sig}\) to add a signature $\sig$ to a payment,
\item $\Cancel$ to cancel a proposal after its deadline expired, and
\item $\Pay$ to make a payment once all required signatures have been collected.
\end{inparaenum}
It then validates that the spending transaction $\mi{tx}$ is a valid
representation of the newly reached machine state. This implies that
$\mi{tx}$ needs to keep $\val_\msc$ locked by $\nu_\msc$ and that the
state in the datum $\delta^{\prime}_\msc$ needs to be the successor state
of $\delta_\msc$ according to the transition diagram.

While the state machine in Figure~\ref{fig:multisig-machine} is fine, its mapping to \EUTXO\ transactions comes with a subtle caveat: what if, for a 2--of--3 contract, somebody posts a transition $\tx_{\mathrm{bad}}$ corresponding to the state \(\Collecting{\val}{\kappa}{d}{\{\sig_1, \sig_2\}}\) onto the chain \emph{without} going through any of the previous states, including without starting in $\Holding$?
Given that $\Pay$ merely checks \(|\sigs| \geq 2\), the payment would be processed when requested on $\tx_{\mathrm{bad}}$, even if \(\{\sig_1, \sig_2\}\) are invalid signatures.
We would not have been allowed to add the invalid signatures $\sig_1$ and $\sig_2$ by way of \(\Add{\sig}\) since its state transition checks signature validity, but by initialising the state machine in an intermediate state $s$ with \(\s{initial}(s) = \false\), we were able to circumvent that check.

In the plain \EUTXO\ model, there is no simple way for the validator implementing a state machine to assert that the state it is operating on arose out of a succession of predecessor states rooted in an initial state.
As a consequence of this limitation, the formal result presented in the \EUTXO\ paper~\cite{eutxo-1-paper} is not as strong as one might hope.
More precisely, this previous work did establish soundness and completeness for a weak bisimulation between CEMs and transactions on a \EUTXO\ ledger;
however, it fell short in that it did not show that an inductive property met by the states of a CEM may also be asserted for the corresponding states on the ledger.
The reason for this omission is precisely the problem we just discussed: for a ledger-representation of a CEM state, we can never be sure that it arose out of a transaction sequence rooted in an initial CEM state.

\subsection{Token provenance}
\label{sec:state-machine-provenance}

In the present work, we solve the problem described above. We will show that non-fungible tokens can be used to identify a unique trace of transactions through an \EUTXOma\ ledger that corresponds to all the states of the corresponding CEM. Moreover, we introduce a notion of \emph{token provenance} that enables us to identify the first CEM state in such a trace and to ensure that it is a state accepted by \(\s{initial} : \s{S} \rightarrow \B\). Together, these allow a state machine validator to ensure that a current CEM state indeed arose out of a trace of transactions rooted in a transaction corresponding to an initial CEM state merely by checking that the non-fungible token associated with this state machine instance is contained in the $\val$ of the state machine output that it locks: this would be $\val_\msc$ for the multi-signature contract of \S\ref{sec:cem-example}.


\chapter{Conclusion and Perspectives}
\label{chap:9}
In this chapter, we conclude this thesis by summarizing the achievements and pointing out
interesting future working directions.

\section{Achievements}
\subsection*{Knowledge Based Optimization Approach}
In this thesis, we presented an intermediate distributed representation (Send/Receive model) for
distributed ream-time systems. This representation proposes an implementation method for
systems with multiparty interactions through simpler primitives such as
messages passing. It also provides a scheduling mechanism, more appropriate to distributed
real-time systems, since it is based on partial information of a given system.

Our first contribution was to propose an optimization methods for such intermediate
representation. We presented a methods that relies on invariants in order to refine the
set of conflicting interactions, required for building the Send/Receive model.
Based on the original model, an approximation of the set of reachable states of a timed system
is derived on the form of invariants. The latter are used later on for checking the
simultaneous enabledness of two potentially conflicting interactions.
Based on the obtained results, either the potential conflict between two interactions is cleared
out meaning that both interactions are never enabled at the same time, or the real conflict
cannot be attested which in this case a counter-example is proposed.
This optimization aims particularly at reducing the effort of scheduling interactions
by removing any unnecessary exchange of messages or evaluation computations.

\subsection*{Modeling Communication Delays}
The Send/Receive model presented in Chapter~\ref{chap:3} assumes that the communication
mechanisms are fast enough to not impact the behavior of the overall system. Effectively, this
is due to the zero delay between the decision of executing interactions in schedulers and
the concrete execution of the corresponding actions in the participating components.
The resulting model was proven to be observationally equivalent to the initial model.
To reduce the impact of communication delays on the system behavior,~\cite{ahlem_these} proposed
an approach based on the idea of \emph{early decision making}. In this solution, schedulers
plan ahead the execution of interactions and notify the corresponding components in advance.
Moreover, it was suggested that schedulers are required to observe an additional subset of
components called \emph{observed components}, not participating in the planned interactions,
in order to achieve global deadlines.
However, besides the fact that this method is restricted to systems where components have non
decreasing deadlines, the characterization of the set of observed components is incomplete. In
fact this set is greater than the presented characterization, and in many cases is equal to
all the component of the system. This is mainly due to the nature of the location invariants:
Local constraints that propagate on the global level.

Our second contribution was to propose a method, based on the same idea of early decision making,
but that differs from the approach of~\cite{ahlem_these} in the following points:
\begin{itemize}
  \item No restriction on components constraints was made
  \item No restriction on the form of timing constraints (In ~\cite{ahlem_these} timing
    constraints are restricted to constraints of the form $x\le k$ or $x\ge k$)
  \item Our method works on the semantics level conversely to the aforementioned method that
    relies directly on transformations and model construction. Effectively, we introduced
    the local planning semantics that plan the execution of interactions based only on
    the set of its participating components. The planning operations are constrained by
    the worst estimation of communication delays as well as the planned interactions. This
    semantics is suited for distributed real-time systems since it is based on local (partial)
    information. We also provided a proof for weak simulation, and a strategy based on
    sufficient conditions guaranteeing the preservation of the system behavior from deadlocks.
    Finally, we presented an alternative method based on real-time controller synthesis
    paradigm and discussed its convenience with respect to our method.
\end{itemize}

\subsection*{Robustness to Clock Imperfections}
We studied in Chapter~\ref{chap:6} the effect of clock imperfections (clock drift) on the
behavior of a timed system. We considered a perturbation model where clock rates are not
perfect (not equal and may change during the execution) but under the assumption that clocks
are resynchronized which induces that their difference of clock values will stay within a certain
threshold.
Our robustness analysis approach was based on the characterization of potential bad states
that invalidates the $\epsilon$-simulation between the initial model and the perturbated model.
We proposed a solution for verifying the robustness of a given timed system based on
shrinkability analysis and suggested the \texttt{Shrinktech} tool for achieving such analysis
which is basically based on parameter synthesis.

\section{Future Works}
\subsection*{Partitioning and Mapping}

In this thesis, we presented the partitioning of interactions as being an important parameter
of the Send/Receive transformation. Interaction partitioning is of importance since the
set of conflicting interactions is calculated based on the latter. The immediate question is
whether a given partitioning is better than an other. In other terms, how can we evaluate
if a given partition of interaction is good or bad. Instinctively, the choice of partitioning
interactions is based on two main factors, namely the degree of parallelism and the effort
for solving conflicts (in terms of messages and computational evaluation).
This choice is generally guided by the choice of a specific target platform: how expensive
is the communication? This introduce necessarily the problem of mapping an application
on a given target platform~\cite{map}. This question is of great importance since its answer
will define how each application process will be mapped to the platform interconnected
processing nodes. Consequently, it decides on workload of each processing nodes and
the communication volume induced by such mapping.
Thus an optimal partition would be a partition that takes into account the target platform
and proposes a partitioning that optimize all the above points. This can be done either
by computing directly the optimal solution or by tuning a proposed partition by merging or
splitting some processes of the application.

\subsection*{Invariants for Distributed Real-Time Systems}

In Chapter~\ref{chap:5} and Chapter~\ref{chap:6}, we presented different semantics reflecting
the behavior of a real-time system in a distributed setting (under communication delays or
with clock drift).

In Chapter~\ref{chap:5}, we relied on the invariants of the initial model
to verify the sufficient conditions for deadlock freedom of the local planning semantics.
This usage is due to the fact that invariants of the system under the standard semantics
are proven to be invariants of the system under the local planning semantics.
An interesting direction is to try to derive invariants characterizing specifically the reachable
states of the planning semantics. This will help directly in the verification process in term of
results precision.

In Chapter~\ref{chap:6}, we proposed the \texttt{Shrinktech} tool for the robustness analysis.
However, such tool relies on the computation of the region graph of a timed automaton, which
in term of complexity suffers from the state explosion problem when the increasing the number of
clocks. A solution to reduce this cost is to compute a parametric invariant of the system
with drifting clocks. The latter represents a cheap over-approximations may in some cases
allow to avoid overly eager and expensive computations of the precise parametric images of
the set of reachable states.

\subsection*{Modeling vs Semantics}

Model-based development is one promising approach in building real-time systems today.
This paradigm relies on models with well defined semantics when building systems all the way
form the design phase until reaching a concrete implementation.
This approach is really important when working with large scale heterogeneous systems since
it reduces both the engineering efforts and the development costs and time.
Nevertheless, a model represents only an abstraction of the reality and is often based
on idealized assumptions, which will not hold at a given stage of the model-based workflow,
precisely when reaching the implementation point.
In this thesis, we tried to bridge this gap by introducing new semantics to tackle the different
issues inherent to the distributed context.
An interesting working direction would be to answer the following question:
Can similar results be obtained without introducing new semantics, but using modeling
instead?
This question is of a big interest since it can indicate which direction efforts need to be made.
For instance, the introduction of a new semantics can be in some case complicated and
errors-prone whereas modeling is known to be more general, much easier and trivial to understand.
Also, modeling has also the benefit of being modular in the sense that if we change
the target execution platform on will have just to replace the corresponding model.

\subsection*{Scheduling Distributed Real-Time Systems}
In this thesis, we often mentioned the words \say{schedulers or scheduling} but without
referring to any scheduling scheme or policy. An interesting working direction is to refine
the behavior of given system by imposing some scheduling constraints. In fact, since we presented
methods based on over-approximations and sufficient conditions, the results of our analysis may
in some cases yield counter-examples that are either false-positives or real counter-examples.
The idea is to identify scheduling schemes that could identify the needs, based on a given set
of properties, in order to achieve a correct behavior.


\section{Systematic uncertainties}
\label{sec:syst}

\subsection{Theory uncertainties}
\label{ssec:theoryuncert}
The estimation of the CP BSM parameters from the OO shape requires the precise knowledge of the SM contributions and related uncertainties. This includes both SM gluon-gluon fusion (background) and SM VBF (signal).
 Therefore, the different theoretical uncertainties affecting the SM predictions are included in the fitting likelihood. This includes uncertainties from PDF, QCD order and $\alpha_s$.

For the gluon-fusion production mode, nine uncertainty sources are used to model the QCD theory
uncertainties, following the recommendation of the LHC Higgs cross section working group~\cite{LHCXS_4}. These sources are:
\begin{itemize}
\item two sources correspond to yield uncertainties related to the total cross section. Their magnitude is taken from the
STWZ-BLPTW predictions~\cite{ggF_qcd_unc_1,ggF_qcd_unc_2,LHCXS_4} and their impact on the different bins is evaluated using
NNLOPS.
\item two sources correspond to migration uncertainties related to splitting the phase space by jet multiplicity. Their magnitude and impact are derived similarly to the yield uncertainties
\item two uncertainty sources are related to the $p_\mathrm{T}^H$ shape and are estimated from scale
variations in NNLOPS, including variations of the HNNLO input scales and the renormalization
and factorization scales in Powheg.
\item two uncertainty sources related to the enhancement of uncertainties for events with typical VBF topology (due to explicit or implicit third-jet vetos), and are estimated by scale variations in MCFM~\cite{MCFM}, and the corresponding uncertainties are estimated using the same procedure use for yield and migration uncertainties.
\item one uncertainty source is related to the treatment of $m_t$ and is most important at large $p_\mathrm{T}^H$.
\end{itemize}

Following the recommendations of PDF4LHC~\cite{pdf4lhc}, the PDF uncertainties are evaluated using the 30 eigenvectors set and treating each of them as an uncorrelated source. One additional nuisance parameter accounts for the uncertainties in $\alpha_{s}$.

For the $VBF+VH$ production modes, QCD uncertainties are estimated as an envelope of the scale variations available in Powheg~\cite{Nason:2009ai,VBFVH_theoryUnc}. Uncertainties from the choice of the PDF set and $\alpha_\mathrm{s}$ are evaluated similar to the gluon-fusion case.
A summary of the magnitude of these uncertainties in the different categories and OO bins is shown in the Figure ~\ref{fig:theoryUnc_ggF} ~\ref{fig:theoryUnc_VBF}.

\begin{figure}[htbp]
\centering
  \subfloat[TT ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/ggF_theoryUnc_TT_d_0.pdf} }
  \subfloat[TL ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/ggF_theoryUnc_TL_d_0.pdf} }
  \subfloat[LT ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/ggF_theoryUnc_LT_d_0.pdf} }
  \subfloat[LL ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/ggF_theoryUnc_LL_d_0.pdf} }
  \caption{Theory uncertainty in different OO bins for ggF process}
  \label{fig:theoryUnc_ggF}
\end{figure}

\begin{figure}[htbp]
\centering
  \subfloat[TT ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/VBF_theoryUnc_TT_d_0.pdf} }
  \subfloat[TL ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/VBF_theoryUnc_TL_d_0.pdf} }
  \subfloat[LT ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/VBF_theoryUnc_LT_d_0.pdf} }
  \subfloat[LL ]{ \includegraphics[width= 0.23\textwidth]{figure/TheorySyst/VBF_theoryUnc_LL_d_0.pdf} }
  \caption{Theory uncertainty in different OO bins for VBF process}
  \label{fig:theoryUnc_VBF}
\end{figure}

\subsection{Uncertainties from signal and background modeling}
\label{ssec:modeluncert}

\paragraph{} The Higgs peak described by double-side crystal ball function can be influence by several experimental effects.
Photon energy scale uncertainties shift the position of signal peak by between $\pm0.2\%$ and $\pm0.4\%$, while the photon resolution uncertainties change the width of signal peak by between $\pm 6\%$ and $\pm 15\%$, following Ref ~\cite{ref:phscaleres}.
Uncertainty due to knowledge of Higgs boson mass of 0.24GeV ~\cite{ref:mHerror} would also affect the signal peak position.
These sources are considered independently into systematic uncertainties.
\# \textcolor{red}{NUMBER NEED CHECK}

\paragraph{} The uncertainty due to the background choice is taken to be the spurious signal yield discussed in \Sect{\ref{ssec:spurious_signal}}, and assumed to be uncorrelated in each bins.

\subsection{Experimental systematic uncertainties affecting the expected signal yields}
\label{ssec:expuncert}

\paragraph{} With data taken during 2015-2018, the uncertainty from integrate luminosity is 2.0\%. Other sources of experimental uncertainty affecting the expected signal yields include: the efficiency of diphoton trigger, the photon identification and isolation efficiencies, the photon energy scale and resolution, the modelling of pile-up in the simulation, the jet energy scale and resolution, the efficiency of the jet vertex tagger. Among them the dominant one is jet flavor composition \texttt{ATLAS\_JET\_Flavor\_Composition} which contributes 5.5\%. \\

The considered systematic uncertainty terms are shown in Figure ~\ref{fig:syst_ranking}.

\begin{figure}[h]
  \centering
  \includegraphics[width=.9\textwidth]{figure/ranking.pdf}
  \caption{Ranking plot for all systematic uncertainty terms. }
  \label{fig:syst_ranking}
\end{figure}