<h1>Model Violation Analysis</h1>
<p>The plots and tables on this tab summarize how well the GST estimate actually fits the data.  Although they may be less familiar to you than, say, process fidelity, these analyses are essential to understanding the GST estimate, and how much to trust it!  Real qubit systems often display behavior that isn't consistent with modeling each gate as a stationary CPTP map.  When pyGSTi tries to fit such data to its model (a single gateset), this "non-Markovianity" manifests as <em>model violation</em>.  This tab provides several views of the model violation observed for this fit, ranging from the coarse-grained (total violation) to hyper-detailed (per-circuit violation).  More observed model violation &#8658; the error metrics on other tabs should be trusted <em>less</em>.</p>

<figure id="final_model_fit_progress_bar_plot">
	<figcaption><span class="captiontitle">Model violation summary.</span> <span class="captiondetail">This plot summarizes how well GST was able to fit the data -- or subsets of it -- to a gateset.  Bars indicate the difference between the actual and expected log-likelihood values, and are given in units of standard deviations of the appropriate <span class="math">\chi^2</span> distribution. Each bar corresponds to a <em>subset</em> of the data including only circuits of length up to <span class="math">\sim L</span>; the rightmost bar corresponds to the full dataset.  Low values are better (less model violation), and bars are colored according to the <q>star</q> rating found in a later table detailing the overall model violation.</span></figcaption>
	{{ final_model_fit_progress_bar_plot|render }}
</figure>


<figure id="final_model_fit_progress_table" class='tbl'>
	<figcaption><span class="captiontitle">Detailed overall model violation.</span> <span class="captiondetail"> This table provides a detailed look at how the observed model violation -- defined by how badly the GST model fits the data -- evolves as more and more of the data are incorporated into the fit.  PyGSTi fits the data iteratively, starting by just fitting data from the shortest circuits (<span class="math">L=1</span>), and then adding longer and longer sequences.  Each subset of the data, defined by its maximum sequence length <span class="math">L</span>, yields an independent fit that is analyzed here.  The key quantity is the difference between the observed and expected maximum loglikelihood (<span class="math">\log(\mathcal{L})</span>).  If the model fits, then <span class="math">2\Delta\log(\mathcal{L})</span> should be a <span class="math">\chi^2_k</span> random variable, where <span class="math">k</span> (the degrees of freedom) is the difference between <span class="math">N_S</span> (the number of independent data points) and <span class="math">N_p</span> (the number of model parameters).  So <span class="math">2\Delta\log(\mathcal{L})</span> should lie in <span class="math">[k-\sqrt{2k},k+\sqrt{2k}]</span>, and <span class="math">N_\sigma = (2\Delta\log(\mathcal{L})-k)/\sqrt{2k}</span> quantifies how many standard deviations it falls above the mean (a <span class="math">p</span>-value can be straightforwardly derived from <span class="math">N_\sigma</span>).  The rating from 1 to 5 stars gives a very crude indication of goodness of fit.  Heading tool tips provide descriptions of each column's value.</span></figcaption>
	{{ final_model_fit_progress_table|render }}
</figure>

<figure id="final_model_fit_colorscatter_plot">
	<figcaption><span class="captiontitle">Per-circuit model violation vs. circuit length</span> <span class="captiondetail">The fit's total <span class="math">2\Delta\log(\mathcal{L})</span> is a sum over all <span class="math">N_s</span> circuits used for GST.  This plot shows <span class="math">2\Delta\log(\mathcal{L})</span> for each individual circuit, plotted against that circuit's length (on the X axis).  Certain forms of non-Markovian noise, like slow drift, produce a characteristic linear relationship.  Note that the length plotted here is the <em>actual</em> length of the circuit, not its nominal <span class="math">L</span>.</span> </figcaption>
	{{ final_model_fit_colorscatter_plot|render }}
</figure>

<figure id="final_tvd_histogram">
	<figcaption><span class="captiontitle">Histogram of per-circuit TVD.</span> <span class="captiondetail">This figure quantifies goodness-of-fit by measuring how a given estimate fails to predict each individual circuit in the dataset using the total variation distance (TVD) as the metric (<span class="math">\frac{1}{2}\sum_i|p_i-f_i|</span>). This plot shows a histogram of the those values for all the circuits in the dataset.</span> </figcaption>
    {{ final_tvd_histogram|render }}
</figure>
