Exemple #1
0
        def make_lsgst_lists(opLabels, fiducialList, germList, maxLengthList):
            singleOps = pc.to_circuits([(g, ) for g in opLabels])
            lgstStrings = pc.create_lgst_circuits(fiducialList, fiducialList,
                                                  opLabels)
            lsgst_list = pc.to_circuits([
                ()
            ])  # running list of all strings so far

            if maxLengthList[0] == 0:
                lsgst_listOfLists = [lgstStrings]
                maxLengthList = maxLengthList[1:]
            else:
                lsgst_listOfLists = []

            for maxLen in maxLengthList:
                lsgst_list += pc.create_circuits("f0+R(germ,N)+f1",
                                                 f0=fiducialList,
                                                 f1=fiducialList,
                                                 germ=germList,
                                                 N=maxLen,
                                                 R=pc.repeat_with_max_length,
                                                 order=('germ', 'f0', 'f1'))
                lsgst_listOfLists.append(
                    lt.remove_duplicates(lgstStrings + lsgst_list))

            print("%d LSGST sets w/lengths" % len(lsgst_listOfLists),
                  map(len, lsgst_listOfLists))
            return lsgst_listOfLists
 def test_grasp_germ_set_optimization_force_strings(self):
     forceStrs = pc.to_circuits([('Gx', ), ('Gy')])
     soln = germsel.find_germs_grasp(self.neighbors,
                                     self.germ_set,
                                     alpha=0.1,
                                     force=forceStrs,
                                     **self.options)
     for string in forceStrs:
         self.assertIn(string, soln)
 def test_optimize_integer_germs_slack_force_strings(self):
     forceStrs = pc.to_circuits([('Gx', ), ('Gy')])
     finalGerms = germsel.find_germs_integer_slack(
         self.mdl_target_noisy,
         self.germ_set,
         fixed_slack=0.1,
         force=forceStrs,
         verbosity=4,
     )
 def test_optimize_integer_fiducials_slack_insufficient_fiducials(self):
     insuff_fids = pc.to_circuits([('Gx', )])
     weights = np.ones(len(insuff_fids), 'i')
     fiducials = fs._find_fiducials_integer_slack(self.model,
                                                  insuff_fids,
                                                  fixed_slack=0.1,
                                                  initial_weights=weights,
                                                  **self.options)
     self.assertIsNone(fiducials)
Exemple #5
0
    def test_bulk_evaltree(self):
        # Test tree construction
        circuits = pc.to_circuits([('Gx', ), ('Gy', ), ('Gx', 'Gy'),
                                   ('Gy', 'Gy'), ('Gy', 'Gx'),
                                   ('Gx', 'Gx', 'Gx'), ('Gx', 'Gy', 'Gx'),
                                   ('Gx', 'Gy', 'Gy'), ('Gy', 'Gy', 'Gy'),
                                   ('Gy', 'Gx', 'Gx')])

        layout = self.model.sim.create_layout(circuits)
Exemple #6
0
 def setUpClass(cls):
     super(DirectXTester, cls).setUpClass()
     cls._tgt = fixtures.model.copy()
     cls.prepStrs = fixtures.fiducials
     cls.effectStrs = fixtures.fiducials
     cls.strs = pc.to_circuits([
         (),  # always need empty string
         ('Gx', ),
         ('Gy', ),
         ('Gi', ),  # need these for include_target_ops=True
         ('Gx', 'Gx'),
         ('Gx', 'Gy', 'Gx')  # additional
     ])
     expstrs = pc.create_circuits("f0+base+f1",
                                  order=['f0', 'f1', 'base'],
                                  f0=fixtures.fiducials,
                                  f1=fixtures.fiducials,
                                  base=cls.strs)
     cls._ds = pdata.simulate_data(fixtures.datagen_gateset.copy(),
                                   expstrs,
                                   1000,
                                   'multinomial',
                                   seed=_SEED)
 def test_build_up_breadth_force_strings(self):
     forceStrs = pc.to_circuits([('Gx', ), ('Gy')])
     germs = germsel.find_germs_breadthfirst(self.neighbors,
                                             self.germ_set,
                                             force=forceStrs,
                                             **self.options)
Exemple #8
0
def run_linear_gst(data_filename_or_set,
                   target_model_filename_or_object,
                   prep_fiducial_list_or_filename,
                   meas_fiducial_list_or_filename,
                   gauge_opt_params=None,
                   advanced_options=None,
                   comm=None,
                   mem_limit=None,
                   output_pkl=None,
                   verbosity=2):
    """
    Perform Linear Gate Set Tomography (LGST).

    This function differs from the lower level :function:`run_lgst` function
    in that it may perform a post-LGST gauge optimization and this routine
    returns a :class:`Results` object containing the LGST estimate.

    Overall, this is a high-level driver routine which can be used similarly
    to :function:`run_long_sequence_gst`  whereas `run_lgst` is a low-level
    routine used when building your own algorithms.

    Parameters
    ----------
    data_filename_or_set : DataSet or string
        The data set object to use for the analysis, specified either directly
        or by the filename of a dataset file (assumed to be a pickled `DataSet`
        if extension is 'pkl' otherwise assumed to be in pyGSTi's text format).

    target_model_filename_or_object : Model or string
        The target model specifying the gates and SPAM elements that LGST is to be run on,
        given either directly or by the filename of a model file (text format).

    prep_fiducial_list_or_filename : (list of Circuits) or string
        The state preparation fiducial circuits, specified either directly
        or by the filename of a circuit list file (text format).

    meas_fiducial_list_or_filename : (list of Circuits) or string or None
        The measurement fiducial circuits, specified either directly or by
        the filename of a circuit list file (text format).  If ``None``,
        then use the same strings as specified by prep_fiducial_list_or_filename.

    gauge_opt_params : dict, optional
        A dictionary of arguments to :func:`gaugeopt_to_target`, specifying
        how the final gauge optimization should be performed.  The keys and
        values of this dictionary may correspond to any of the arguments
        of :func:`gaugeopt_to_target` *except* for the first `model`
        argument, which is specified internally.  The `target_model` argument,
        *can* be set, but is specified internally when it isn't.  If `None`,
        then the dictionary `{'item_weights': {'gates':1.0, 'spam':0.001}}`
        is used.  If `False`, then then *no* gauge optimization is performed.

    advanced_options : dict, optional
        Specifies advanced options most of which deal with numerical details of
        the objective function or expert-level functionality.  See
        :function:`run_long_sequence_gst`.

    comm : mpi4py.MPI.Comm, optional
        When not ``None``, an MPI communicator for distributing the computation
        across multiple processors.  In this LGST case, this is just the gauge
        optimization.

    mem_limit : int or None, optional
        A rough memory limit in bytes which restricts the amount of memory
        used (per core when run on multi-CPUs).

    output_pkl : str or file, optional
        If not None, a file(name) to `pickle.dump` the returned `Results` object
        to (only the rank 0 process performs the dump when `comm` is not None).

    verbosity : int, optional
        The 'verbosity' option is an integer specifying the level of
        detail printed to stdout during the calculation.

    Returns
    -------
    Results
    """
    printer = _baseobjs.VerbosityPrinter.create_printer(verbosity, comm)
    advanced_options = _GSTAdvancedOptions(advanced_options or {})
    ds = _load_dataset(data_filename_or_set, comm, printer)
    target_model = _load_model(target_model_filename_or_object)

    if isinstance(target_model, _ProcessorSpec):  # for backward compatibility
        _warnings.warn((
            "You passed a processor spec to 'run_linear_gst' when you really should have passed a"
            " model.  Trying to create an explicit model from the pspec w/Pauli prod basis and use it."
        ))
        target_model = _create_explicit_model(target_model,
                                              None,
                                              ideal_gate_type='full',
                                              basis='pp')

    germs = _circuits.to_circuits(
        [()] +
        [(gl, )
         for gl in target_model.primitive_op_labels])  # just the single gates
    max_lengths = [1]  # we only need maxLength == 1 when doing LGST

    exp_design = _proto.StandardGSTDesign(
        target_model.create_processor_spec(),
        prep_fiducial_list_or_filename,
        meas_fiducial_list_or_filename,
        germs,
        max_lengths,
        sequenceRules=advanced_options.get('string_manipulation_rules', None),
        op_label_aliases=advanced_options.get('op_label_aliases', None),
        dscheck=ds,
        actionIfMissing='raise',
        verbosity=printer)

    data = _proto.ProtocolData(exp_design, ds)

    if gauge_opt_params is None:
        gauge_opt_params = {'item_weights': {'gates': 1.0, 'spam': 0.001}}
    gopt_suite = {'go0': gauge_opt_params} if gauge_opt_params else None

    proto = _proto.LinearGateSetTomography(
        target_model,
        gopt_suite,
        None,
        _get_badfit_options(advanced_options),
        printer,
        name=advanced_options.get('estimate_label', None))
    proto.profile = advanced_options.get('profile', 1)
    proto.record_output = advanced_options.get('record_output', 1)
    proto.oplabels = advanced_options.get('op_labels', 'default')
    proto.oplabel_aliases = advanced_options.get('op_label_aliases', None)
    proto.unreliable_ops = advanced_options.get(
        'unreliable_ops', ['Gcnot', 'Gcphase', 'Gms', 'Gcn', 'Gcx', 'Gcz'])

    results = proto.run(data, mem_limit, comm)
    _output_to_pickle(results, output_pkl, comm)
    return results
Exemple #9
0
    def setUp(self):
        # TODO optimize
        self.model = models.create_explicit_model_from_expressions(
            [('Q0', )], ['Gi', 'Gx', 'Gy'],
            ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"])
        self.depolGateset = self.model.depolarize(op_noise=0.1)

        def make_lsgst_lists(opLabels, fiducialList, germList, maxLengthList):
            singleOps = pc.to_circuits([(g, ) for g in opLabels])
            lgstStrings = pc.create_lgst_circuits(fiducialList, fiducialList,
                                                  opLabels)
            lsgst_list = pc.to_circuits([
                ()
            ])  # running list of all strings so far

            if maxLengthList[0] == 0:
                lsgst_listOfLists = [lgstStrings]
                maxLengthList = maxLengthList[1:]
            else:
                lsgst_listOfLists = []

            for maxLen in maxLengthList:
                lsgst_list += pc.create_circuits("f0+R(germ,N)+f1",
                                                 f0=fiducialList,
                                                 f1=fiducialList,
                                                 germ=germList,
                                                 N=maxLen,
                                                 R=pc.repeat_with_max_length,
                                                 order=('germ', 'f0', 'f1'))
                lsgst_listOfLists.append(
                    lt.remove_duplicates(lgstStrings + lsgst_list))

            print("%d LSGST sets w/lengths" % len(lsgst_listOfLists),
                  map(len, lsgst_listOfLists))
            return lsgst_listOfLists

        gates = ['Gi', 'Gx', 'Gy']
        fiducials = pc.to_circuits([(), ('Gx', ), ('Gy', ), ('Gx', 'Gx'),
                                    ('Gx', 'Gx', 'Gx'), ('Gy', 'Gy', 'Gy')
                                    ])  # fiducials for 1Q MUB
        germs = pc.to_circuits([('Gx', ), ('Gy', ), ('Gi', ), (
            'Gx',
            'Gy',
        ), (
            'Gx',
            'Gy',
            'Gi',
        ), (
            'Gx',
            'Gi',
            'Gy',
        ), (
            'Gx',
            'Gi',
            'Gi',
        ), (
            'Gy',
            'Gi',
            'Gi',
        ), (
            'Gx',
            'Gx',
            'Gi',
            'Gy',
        ), (
            'Gx',
            'Gy',
            'Gy',
            'Gi',
        ), (
            'Gx',
            'Gx',
            'Gy',
            'Gx',
            'Gy',
            'Gy',
        )])
        maxLengths = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256]
        self.lsgst_lists = make_lsgst_lists(gates, fiducials, germs,
                                            maxLengths)
        self.circuit_list = self.lsgst_lists[-1]
        self.dataset = pdata.simulate_data(self.depolGateset,
                                           self.circuit_list,
                                           num_samples=1000,
                                           sample_error='binomial',
                                           seed=100)
 def setUp(self):
     super(LogLTester, self).setUp()
     self.circuits = circuits.to_circuits([('Gx', ), ('Gy', ),
                                           ('Gx', 'Gx')])
 def setUp(self):
     super(FiducialPairReductionSmallData, self).setUp()
     self.preps = pc.to_circuits([('Gx', )])
     self.effects = self.preps
     self.germs = pc.to_circuits([('Gx', ), ('Gy', )])
     self.fiducial_pairs = [(0, 0)]
 def test_find_sufficient_fiducial_pairs_per_germ_raises_on_insufficient_fiducials(
         self):
     insuff_fids = pc.to_circuits([('Gx', )])
     with self.assertRaises(ValueError):
         fpr.find_sufficient_fiducial_pairs_per_germ(
             self.model, insuff_fids, insuff_fids, self.germs)