Testing Models¶
Introduction¶
QInfer provides several premade models for quickly learning how to use the library, for making demonstrations, or to test new algorithms and approaches built on top of QInfer.
SimplePrecessionModel
 Model of a single qubit undergoing Larmor precession¶

class
qinfer.
SimplePrecessionModel
(min_freq=0)[source]¶ Bases:
qinfer.test_models.SimpleInversionModel
Describes the free evolution of a single qubit prepared in the \(\left+\right\rangle\) state under a Hamiltonian \(H = \omega \sigma_z / 2\), as explored in [GFWC12].
Parameters: min_freq (float) – Minimum value for \(\omega\) to accept as valid. This is used for testing techniques that mitigate the effects of degenerate models; there is no “good” reason to ever set this to be less than zero, other than to test with an explicitly broken model. Model Parameters: omega – The precession frequency \(\omega\). Experiment Parameter float: The evolution time \(t\). 
expparams_dtype
¶

UnknownT2Model
 Model of a single qubit undergoing Larmor precession with finite decoherence¶

class
qinfer.
UnknownT2Model
(allow_identical_outcomes=False, outcome_warning_threshold=0.99, n_outcomes_cutoff=None)[source]¶ Bases:
qinfer.abstract_model.FiniteOutcomeModel
Describes the free evolution of a single qubit prepared in the :math:`left+ight angle` state under a Hamiltonian
\(H = \omega \sigma_z / 2\) with an unknown \(T_2\) process, as explored in [GFWC12].
modelparam omega: The precession frequency \(\omega\). modelparam T2_inv: The decoherence strength \(T_2^{1}\). scalarexpparam float: The evolution time \(t\). 
n_modelparams
¶

modelparam_names
¶

expparams_dtype
¶

NoisyCoinModel
 Classical coin flip model corrupted by a noisy process¶

class
qinfer.
NoisyCoinModel
[source]¶ Bases:
qinfer.abstract_model.FiniteOutcomeModel
Implements the “noisy coin” model of [FB12], where the model parameter \(p\) is the probability of the noisy coin. This model has two experiment parameters, \(\alpha\) and \(\beta\), which are the probabilities of observing a “0” outcome conditoned on the “true” outcome being 0 and 1, respectively. That is, for an ideal coin, \(\alpha = 1\) and \(\beta = 0\).
Note that \(\alpha\) and \(\beta\) are implemented as experiment parameters not because we expect to design over those values, but because a specification of each is necessary to honestly describe an experiment that was performed.
Model Parameters: p – “Heads” probability \(p\).
Experiment Parameters:  alpha (float) – Visibility parameter \(\alpha\).
 beta (float) – Visibility parameter \(\beta\).

n_modelparams
¶

expparams_dtype
¶

is_n_outcomes_constant
¶
NDieModel
¶

class
qinfer.
NDieModel
(n=6, threshold=1e07)[source]¶ Bases:
qinfer.abstract_model.FiniteOutcomeModel
Implements a model of rolling a die with n sides, whose unknown model parameters are the weights of each side; a generalization of CoinModel. An experiment consists of rolling the die once. The faces of the die are zero indexed, labeled 0,1,2,…,n1.
Parameters: 
n_modelparams
¶

expparams_dtype
¶

is_n_outcomes_constant
¶ Returns
True
if and only if the number of outcomes for each experiment is independent of the experiment being performed.This property is assumed by inference engines to be constant for the lifetime of a Model instance.

n_outcomes
(expparams)[source]¶ Returns an array of dtype
uint
describing the number of outcomes for each experiment specified byexpparams
.Parameters: expparams (numpy.ndarray) – Array of experimental parameters. This array must be of dtype agreeing with the expparams_dtype
property.

Custom Models¶
Writing custom models is standard practice for QInfer users. See Implementing Custom Simulators and Models.
test_model()
 Method to run suite of tests on a model instance¶

qinfer.tests.base_test.
test_model
(model, prior, expparams, stream=<open file '<stderr>', mode 'w'>)[source]¶ Tests the given Simulatable instance for errors. Useful for debugging new or third party models.
Parameters:  model – Instance of Simulatable or a subclass thereof.
 prior – Instance of Distribution, or any other class which
implements a function
sample
that returns valid modelparams.  expparams –
np.ndarray
of experimental parameters to test with.  stream – Stream to dump the results into, default is stderr.