Exemple #1
0
def simple_est_rb(data,
                  interleaved=False,
                  p_min=0.0,
                  p_max=1.0,
                  n_particles=8000,
                  return_all=False):
    r"""
    Estimates the fidelity of a gateset from a standard or interleaved randomized benchmarking
    experiment.
    
    :param data: Data to be used in estimating the gateset fidelity.
    :type data: see :ref:`simple_est_data_arg`
    :param float p_min: Minimum value of the parameter :math:`p`
        to consider feasible.
    :param float p_max: Minimum value of the parameter :math:`p`
        to consider feasible.
    :param int n_particles: The number of particles to be used in estimating
        the randomized benchmarking model.
    :param bool return_all: Controls whether additional return
        values are provided, such as the updater.

    :column counts (int): How many sequences of length :math:`m` were observed to
        survive.
    :column m (int): How many gates were used for sequences in this row of the data.
    :column n_shots (int): How many different sequences of length :math:`m`
        were measured.
    :column reference (bool): `True` if this row represents reference sequences, or
        `False` if the gate of interest is interleaved. Note that this column is omitted
        if ``interleaved`` is `False`.

    :return mean: Bayesian mean estimator for the model vector
        :math:`(p, A, B)`, or :math:`(\tilde{p}, p_{\text{ref}}, A, B)`
        for the interleaved case.
    :return var: Variance of the final posterior over RB model vectors.
    :return extra: See :ref:`simple_est_extra_return`. Only returned
        if ``return_all`` is `True`.
    """
    model = BinomialModel(RandomizedBenchmarkingModel(interleaved=interleaved))
    prior = PostselectedDistribution(
        UniformDistribution(
            [[p_min, p_max], [0, 1], [0, 1]] if not interleaved else
            [[p_min, p_max], [p_min, p_max], [0, 1], [0, 1]]), model)

    data = load_data_or_txt(data, [('counts', 'uint'), ('m', 'uint'),
                                   ('n_shots', 'uint')] +
                            ([('reference', 'uint')] if interleaved else []))

    cols_expparams = {'m': (1, 'm'), 'n_meas': (2, 'n_shots')}
    if interleaved:
        cols_expparams['reference'] = (3, 'reference')

    outcomes, expparams = data_to_params(data,
                                         model.expparams_dtype,
                                         cols_expparams=cols_expparams)

    return do_update(model, n_particles, prior, outcomes, expparams,
                     return_all)
Exemple #2
0
def simple_est_prec(data, freq_min=0.0, freq_max=1.0, n_particles=6000, return_all=False):
    """
    Estimates a simple precession (cos²) from experimental data.
    Note that this model is mainly for testing purposes, as it does not
    consider the phase or amplitude of precession, leaving only the frequency.

    :param data: Data to be used in estimating the precession frequency.
    :type data: see :ref:`simple_est_data_arg`
    :param float freq_min: The minimum feasible frequency to consider.
    :param float freq_max: The maximum feasible frequency to consider.
    :param int n_particles: The number of particles to be used in estimating
        the precession frequency.
    :param bool return_all: Controls whether additional return
        values are provided, such as the updater.

    :column counts (int): How many counts were observed at the sampled
        time.
    :column t (float): The evolutions time at which the samples
        were collected.
    :column n_shots (int): How many samples were collected at the
        given evolution time.

    :return mean: Bayesian mean estimator for the precession frequency.
    :return var: Variance of the final posterior over frequency.
    :return extra: See :ref:`simple_est_extra_return`. Only returned
        if ``return_all`` is `True`.
    """
    model = BinomialModel(SimplePrecessionModel(freq_min))
    prior = UniformDistribution([0, freq_max])

    data = load_data_or_txt(data, [
        ('counts', 'uint'),
        ('t', float),
        ('n_shots', 'uint')
    ])

    outcomes, expparams = data_to_params(data,
        model.expparams_dtype,
        cols_expparams={
            'x': (1, 't'),
            'n_meas': (2, 'n_shots')
        }
    )

    return do_update(
        model, n_particles, prior, outcomes, expparams,
        return_all
    )
Exemple #3
0
    def run_estimate(data, freq,
                     n_particles=10000, return_all=False):
        """this is a copy of qinfer.simple_

        Args:
            data:
            n_particles:
            return_all:

        Returns:

        """
        model = BinomialModel(AmplitudeEstimator(freq))
        
#         prior =  PostselectedDistribution(
#         UniformDistribution(
#             [
#                 [0.30, 0.5],
#                 [0.30, 0.5]
#              ]),
#            model,
#            maxiters=10000
#         )

        prior = MyDistribution()


        data = load_data_or_txt(data, [
            ('counts', 'uint'),
            ('t', float),
            ('n_shots', 'uint')
        ])

        outcomes, expparams = data_to_params(data,
            model.expparams_dtype,
            cols_expparams={
                't': (1, 't'),
                'n_meas': (2, 'n_shots')
            }
        )

        return do_update(
            model, n_particles, prior, outcomes, expparams,
            return_all
        )