Ejemplo n.º 1
0
    def setUpClass(cls):
        #OK for these tests, since we test user interface?
        #Set Model objects to "strict" mode for testing
        ExplicitOpModel._strict = False
        cls._model = models.create_explicit_model_from_expressions(
            [('Q0', )], ['Gi', 'Gx', 'Gy'],
            ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], **cls.build_options)

        super(ModelBase, cls).setUpClass()
Ejemplo n.º 2
0
def create_parameterized_rpe_model(alpha_true,
                                   epsilon_true,
                                   aux_rot,
                                   spam_depol,
                                   gate_depol=None,
                                   with_id=True,
                                   rpeconfig_inst=None):
    """
    Make a model for simulating RPE, paramaterized by rotation angles.  Note
    that the output model also has thetaTrue, alpha_true, and epsilon_true
    added attributes.

    Parameters
    ----------
    alpha_true : float
       Angle of rotation about "fixed axis"

    epsilon_true : float
       Angle of rotation about "loose axis"

    aux_rot : float
       Angle of rotation about the axis perpendicular to fixed and loose axes,
       that, by similarity transformation, changes loose axis.

    spam_depol : float
       Amount to depolarize SPAM by.

    gate_depol : float, optional
       Amount to depolarize gates by (defaults to None).

    with_id : bool, optional
       Do we include (perfect) identity or no identity? (Defaults to False;
       should be False for RPE, True for GST)

    rpeconfig_inst : RPEconfig object
        Declares which model configuration RPE should be trying to fit;
        determines particular functions and values to be used.

    Returns
    -------
    Model
        The desired model for RPE; model also has attributes thetaTrue,
        alpha_true, and epsilon_true, automatically extracted.
    """

    #    if rpeconfig_inst not in rpeInstanceDict.keys():
    #        raise Exception('Need valid rpeconfig_inst!')

    #    rpeconfig_inst = rpeInstanceDict[rpeconfig_inst]

    loose_axis_gate_label = rpeconfig_inst.loose_axis_gate_label
    loose_axis_label = rpeconfig_inst.loose_axis_label
    fixed_axis_gate_label = rpeconfig_inst.fixed_axis_gate_label
    fixed_axis_label = rpeconfig_inst.fixed_axis_label

    auxiliary_axis_gate_label = rpeconfig_inst.auxiliary_axis_gate_label
    auxiliary_axis_label = rpeconfig_inst.auxiliary_axis_label

    rhoExpressions = rpeconfig_inst.rhoExpressions
    EExpressions = rpeconfig_inst.EExpressions
    ELabels = rpeconfig_inst.ELabels

    if with_id:
        outputModel = _models.create_explicit_model_from_expressions(
            [('Q0', )], ['Gi', loose_axis_gate_label, fixed_axis_gate_label], [
                "I(Q0)", loose_axis_label + "(%s,Q0)" % epsilon_true,
                fixed_axis_label + "(%s,Q0)" % alpha_true
            ],
            prep_labels=["rho0"],
            prep_expressions=rhoExpressions,
            effect_labels=ELabels,
            effect_expressions=EExpressions)
    else:
        outputModel = _models.create_explicit_model_from_expressions(
            [('Q0', )], [loose_axis_gate_label, fixed_axis_gate_label], [
                loose_axis_label + "(%s,Q0)" % epsilon_true,
                fixed_axis_label + "(%s,Q0)" % alpha_true
            ],
            prep_labels=["rho0"],
            prep_expressions=rhoExpressions,
            effect_labels=ELabels,
            effect_expressions=EExpressions)

    if aux_rot != 0:
        modelAux1 = _models.create_explicit_model_from_expressions(
            [('Q0', )],
            ['Gi', auxiliary_axis_gate_label, fixed_axis_gate_label], [
                "I(Q0)", auxiliary_axis_label + "(%s,Q0)" % aux_rot,
                fixed_axis_label + "(pi/2,Q0)"
            ],
            prep_labels=["rho0"],
            prep_expressions=rhoExpressions,
            effect_labels=ELabels,
            effect_expressions=EExpressions)

        outputModel.operations[loose_axis_gate_label] = \
            _np.dot(_np.dot(_np.linalg.inv(modelAux1.operations[auxiliary_axis_gate_label]),
                            outputModel.operations[loose_axis_gate_label]),
                    modelAux1.operations[auxiliary_axis_gate_label])

    outputModel = outputModel.depolarize(op_noise=gate_depol,
                                         spam_noise=spam_depol)

    thetaTrue = _rpetools.extract_theta(outputModel, rpeconfig_inst)
    outputModel.thetaTrue = thetaTrue

    outputModel.alphaTrue = _rpetools.extract_alpha(outputModel,
                                                    rpeconfig_inst)
    outputModel.alphaTrue = alpha_true

    outputModel.epsilonTrue = _rpetools.extract_epsilon(
        outputModel, rpeconfig_inst)
    outputModel.epsilonTrue = epsilon_true

    return outputModel
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_strdiff(self):
     other = models.create_explicit_model_from_expressions(
         [('Q0', )], ['Gi', 'Gx', 'Gy'],
         ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"],
         gate_type='full TP')
     self.model.strdiff(other)
Ejemplo n.º 5
0
 def setUpClass(cls):
     ExplicitOpModel._strict = False
     cls.model = models.create_explicit_model_from_expressions(
         [('Q0', )], ['Gi', 'Gx', 'Gy'],
         ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"])
Ejemplo n.º 6
0
 def test_max_gram_rank_and_evals(self):
     model = models.create_explicit_model_from_expressions(
         [('Q0', )], ['Gx', 'Gy'], ["X(pi/4,Q0)", "Y(pi/4,Q0)"])
     rank, evals, tgt_evals = gm.max_gram_rank_and_eigenvalues(
         self.ds, model)
     self.assertEqual(rank, 1)