Exemplo n.º 1
0
 def test_long_sequence_gst_raises_on_bad_profile_options(self):
     #check invalid profile options
     with self.assertRaises(ValueError):
         ls.run_long_sequence_gst(self.ds,
                                  self.model,
                                  self.fiducials,
                                  self.fiducials,
                                  self.germs,
                                  self.maxLens,
                                  advanced_options={'profile': 3})
Exemplo n.º 2
0
 def test_long_sequence_gst_raises_on_bad_badfit_options(self):
     with self.assertRaises(ValueError):
         ls.run_long_sequence_gst(self.ds,
                                  self.model,
                                  self.fiducials,
                                  self.fiducials,
                                  self.germs,
                                  self.maxLens,
                                  advanced_options={
                                      'bad_fit_threshold': -100,
                                      'on_bad_fit': ["foobar"]
                                  })
Exemplo n.º 3
0
 def test_long_sequence_gst(self):
     result = ls.run_long_sequence_gst(self.ds,
                                       self.model,
                                       self.fiducials,
                                       self.fiducials,
                                       self.germs,
                                       self.maxLens,
                                       advanced_options=self.options)
Exemplo n.º 4
0
 def test_long_sequence_gst_chi2(self):
     self.options.update(objective='chi2')
     result = ls.run_long_sequence_gst(self.ds,
                                       self.model,
                                       self.fiducials,
                                       self.fiducials,
                                       self.germs,
                                       self.maxLens,
                                       advanced_options=self.options)
Exemplo n.º 5
0
 def test_long_sequence_gst_raises_on_bad_advanced_options(self):
     with self.assertRaises(ValueError):
         ls.run_long_sequence_gst(self.ds,
                                  self.model,
                                  self.fiducials,
                                  None,
                                  self.germs,
                                  self.maxLens,
                                  advanced_options={'objective': "FooBar"
                                                    })  # bad objective
     with self.assertRaises(ValueError):
         ls.run_long_sequence_gst(
             self.ds,
             self.model,
             self.fiducials,
             None,
             self.germs,
             self.maxLens,
             advanced_options={'starting_point':
                               "FooBar"})  # bad starting point
Exemplo n.º 6
0
 def test_long_sequence_gst_advanced_options(self):
     # TODO what exactly is being tested?
     self.options.update({
         #'starting point': self.model,  #this is deprecated now - need to use protocol objects
         'depolarize_start': 0.05,
         'cptp_penalty_factor': 1.0
     })
     result = ls.run_long_sequence_gst(self.ds,
                                       self.model,
                                       self.fiducials,
                                       None,
                                       self.germs,
                                       self.maxLens,
                                       advanced_options=self.options)
Exemplo n.º 7
0
    def test_long_sequence_gst_with_file_args(self, ds_path, model_path,
                                              fiducial_path, germ_path):
        io.write_dataset(ds_path, self.ds, self.lsgstStrings[-1])
        io.write_model(self.model, model_path)
        io.write_circuit_list(fiducial_path, self.fiducials)
        io.write_circuit_list(germ_path, self.germs)

        self.options.update(
            randomize_start=1e-6,
            profile=2,
        )
        result = ls.run_long_sequence_gst(ds_path,
                                          model_path,
                                          fiducial_path,
                                          fiducial_path,
                                          germ_path,
                                          self.maxLens,
                                          advanced_options=self.options,
                                          verbosity=10)
Exemplo n.º 8
0
def create_bootstrap_models(num_models,
                            input_data_set,
                            generation_method,
                            fiducial_prep,
                            fiducial_measure,
                            germs,
                            max_lengths,
                            input_model=None,
                            target_model=None,
                            start_seed=0,
                            outcome_labels=None,
                            lsgst_lists=None,
                            return_data=False,
                            verbosity=2):
    """
    Creates a series of "bootstrapped" Models.

    Models are created from a single DataSet (and possibly Model) and are
    typically used for generating bootstrapped error bars.  The resulting Models
    are obtained by performing MLGST on data generated by repeatedly calling
    :function:`create_bootstrap_dataset` with consecutive integer seed values.

    Parameters
    ----------
    num_models : int
        The number of models to create.

    input_data_set : DataSet
        The data set to use for generating the "bootstrapped" data set.

    generation_method : { 'nonparametric', 'parametric' }
        The type of data to generate.  'parametric' generates DataSets
        with the same circuits and sample counts as input_data_set but
        using the probabilities in input_model (which must be provided).
        'nonparametric' generates DataSets with the same circuits
        and sample counts as input_data_set using the count frequencies of
        input_data_set as probabilities.

    fiducial_prep : list of Circuits
        The state preparation fiducial circuits used by MLGST.

    fiducial_measure : list of Circuits
        The measurement fiducial circuits used by MLGST.

    germs : list of Circuits
        The germ circuits used by MLGST.

    max_lengths : list of ints
        List of integers, one per MLGST iteration, which set truncation lengths
        for repeated germ strings.  The list of circuits for the i-th LSGST
        iteration includes the repeated germs truncated to the L-values *up to*
        and including the i-th one.

    input_model : Model, optional
        The model used to compute the probabilities for circuits when
        generation_method is set to 'parametric'.  If 'nonparametric' is selected,
        this argument must be set to None (the default).

    target_model : Model, optional
        Mandatory model to use for as the target model for MLGST when
        generation_method is set to 'nonparametric'.  When 'parametric'
        is selected, this should be the ideal version of `input_model`.

    start_seed : int, optional
        The initial seed value for numpy's random number generator when
        generating data sets.  For each succesive dataset (and model)
        that are generated, the seed is incremented by one.

    outcome_labels : list, optional
        The list of Outcome labels to include in the output dataset.  If None
        are specified, defaults to the effect labels of `input_data_set`.

    lsgst_lists : list of circuit lists, optional
        Provides explicit list of circuit lists to be used in analysis;
        to be given if the dataset uses "incomplete" or "reduced" sets of
        circuit.  Default is None.

    return_data : bool
        Whether generated data sets should be returned in addition to
        models.

    verbosity : int
        Level of detail printed to stdout.

    Returns
    -------
    models : list
        The list of generated Model objects.
    data : list
        The list of generated DataSet objects, only returned when
        return_data == True.
    """

    if max_lengths is None:
        print("No max_lengths value specified; using [0,1,2,4,...,1024]")
        max_lengths = [0] + [2**k for k in range(10)]

    if (input_model is None and target_model is None):
        raise ValueError("Must supply either input_model or target_model!")
    #if (input_model is not None and target_model is not None):
    #    raise ValueError("Cannot supply both input_model and target_model!")

    if generation_method == 'parametric' and target_model is None:
        target_model = input_model

    datasetList = []
    print("Creating DataSets: ")
    for run in range(num_models):
        print("%d " % run, end='')
        datasetList.append(
            create_bootstrap_dataset(input_data_set, generation_method,
                                     input_model, start_seed + run,
                                     outcome_labels))

    modelList = []
    print("Creating Models: ")
    for run in range(num_models):
        print("Running MLGST Iteration %d " % run)
        if lsgst_lists is not None:
            results = _longseq.run_long_sequence_gst_base(datasetList[run],
                                                          target_model,
                                                          lsgst_lists,
                                                          verbosity=verbosity)
        else:
            results = _longseq.run_long_sequence_gst(datasetList[run],
                                                     target_model,
                                                     fiducial_prep,
                                                     fiducial_measure,
                                                     germs,
                                                     max_lengths,
                                                     verbosity=verbosity)
        modelList.append(
            results.estimates.get(
                'default',
                next(iter(results.estimates.values()))).models['go0'])

    if not return_data:
        return modelList
    else:
        return modelList, datasetList