Ejemplo n.º 1
0
    def test_stdgst_terms(self):
        # Using term-based (path integral) calculation
        # This performs a map-based unitary evolution along each path.
        target_model = std.target_model().copy()
        target_model.set_all_parameterizations("H+S terms")
        target_model.set_simtype(
            'termorder:1'
        )  # this is the default set by set_all_parameterizations above
        results = pygsti.do_long_sequence_gst(self.ds,
                                              target_model,
                                              std.prepStrs,
                                              std.effectStrs,
                                              self.germs,
                                              self.maxLengths,
                                              verbosity=4)

        #RUN BELOW LINES TO SAVE GATESET (UNCOMMENT to regenerate)
        #pygsti.io.json.dump(results.estimates['default'].models['go0'],
        #                    open(compare_files + "/test2Qcalc_std_terms.model",'w'))

        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               5,
                               delta=1.0)
        mdl_compare = pygsti.io.json.load(
            open(compare_files + "/test2Qcalc_std_terms.model"))
        self.assertAlmostEqual(np.linalg.norm(
            results.estimates['default'].models['go0'].to_vector() -
            mdl_compare.to_vector()),
                               0,
                               places=3)
Ejemplo n.º 2
0
    def test_stdgst_matrix(self):
        # Using matrix-based calculations
        target_model = std.target_model().copy()
        target_model.set_all_parameterizations("CPTP")
        target_model.set_simtype(
            'matrix')  # the default for 1Q, so we could remove this line
        results = pygsti.do_long_sequence_gst(self.ds,
                                              target_model,
                                              std.prepStrs,
                                              std.effectStrs,
                                              self.germs,
                                              self.maxLengths,
                                              advancedOptions=self.advOpts,
                                              verbosity=4)
        #RUN BELOW LINES TO SAVE GATESET (UNCOMMENT to regenerate)
        #pygsti.io.write_model(results.estimates['default'].models['go0'],
        #                        compare_files + "/test2Qcalc_std_exact.model","Saved Standard-Calc 2Q test model")

        #Note: expected nSigma of 143 is so high b/c we use very high tol of 1e-2 => result isn't very good
        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               143,
                               delta=2.0)
        mdl_compare = pygsti.io.load_model(compare_files +
                                           "/test2Qcalc_std_exact.model")
        self.assertAlmostEqual(
            results.estimates['default'].models['go0'].frobeniusdist(
                mdl_compare),
            0,
            places=3)
Ejemplo n.º 3
0
    def test_stdgst_map(self):
        # Using map-based calculation
        target_model = std.target_model().copy()
        target_model.set_all_parameterizations("CPTP")
        target_model.set_simtype('map')
        results = pygsti.do_long_sequence_gst(self.ds,
                                              target_model,
                                              std.prepStrs,
                                              std.effectStrs,
                                              self.germs,
                                              self.maxLengths,
                                              advancedOptions=self.advOpts,
                                              verbosity=4)

        #Note: expected nSigma of 143 is so high b/c we use very high tol of 1e-2 => result isn't very good
        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               143,
                               delta=2.0)
        mdl_compare = pygsti.io.load_model(compare_files +
                                           "/test2Qcalc_std_exact.model")
        self.assertAlmostEqual(
            results.estimates['default'].models['go0'].frobeniusdist(
                mdl_compare),
            0,
            places=3)
Ejemplo n.º 4
0
 def setUpClass(cls):
     cls.target_model = std2Q_XYCNOT.target_model()
     cls.prepStrs = std2Q_XYCNOT.prepStrs
     cls.measStrs = std2Q_XYCNOT.effectStrs
     cls.germs = std2Q_XYCNOT.germs
     cls.maxLens = [1, 2, 4]
     super(EvalTree2QBase, cls).setUpClass()
Ejemplo n.º 5
0
    def setUpClass(cls):
        """
        Handle all once-per-class (slow) computation and loading,
         to avoid calling it for each test (like setUp).  Store
         results in class variable for use within setUp.
        """
        super(CalcMethods2QTestCase, cls).setUpClass()

        #Change to test_packages directory (since setUp hasn't been called yet...)
        origDir = os.getcwd()
        os.chdir(os.path.abspath(os.path.dirname(__file__)))
        os.chdir('..')  # The test_packages directory

        #Note: std is a 2Q model
        cls.maxLengths = [1]
        #cls.germs = std.germs_lite
        cls.germs = pygsti.construction.circuit_list([
            (gl, ) for gl in std.target_model().operations
        ])
        cls.mdl_datagen = std.target_model().depolarize(op_noise=0.1,
                                                        spam_noise=0.001)
        cls.listOfExperiments = pygsti.construction.make_lsgst_experiment_list(
            std.target_model(), std.prepStrs, std.effectStrs, cls.germs,
            cls.maxLengths)

        #RUN BELOW FOR DATAGEN (UNCOMMENT to regenerate)
        #ds = pygsti.construction.generate_fake_data(cls.mdl_datagen, cls.listOfExperiments,
        #                                            nSamples=1000, sampleError="multinomial", seed=1234)
        #ds.save(compare_files + "/calcMethods2Q.dataset")

        cls.ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files +
                                        "/calcMethods2Q.dataset")
        cls.advOpts = {'tolerance': 1e-2}

        #Reduced model GST dataset
        cls.nQubits = 2
        cls.mdl_redmod_datagen = pc.build_nqnoise_model(cls.nQubits,
                                                        geometry="line",
                                                        maxIdleWeight=1,
                                                        maxhops=1,
                                                        extraWeight1Hops=0,
                                                        extraGateWeight=1,
                                                        sparse=False,
                                                        sim_type="matrix",
                                                        verbosity=1,
                                                        gateNoise=(1234, 0.01),
                                                        prepNoise=(456, 0.01),
                                                        povmNoise=(789, 0.01))

        #Create a reduced set of fiducials and germs
        opLabels = list(cls.mdl_redmod_datagen.operations.keys())
        fids1Q = std1Q_XY.fiducials[0:2]  # for speed
        cls.redmod_fiducials = []
        for i in range(cls.nQubits):
            cls.redmod_fiducials.extend(
                pygsti.construction.manipulate_circuit_list(
                    fids1Q, [((L('Gx'), ), (L('Gx', i), )),
                             ((L('Gy'), ), (L('Gy', i), ))]))
        #print(redmod_fiducials, "Fiducials")

        cls.redmod_germs = pygsti.construction.circuit_list([
            (gl, ) for gl in opLabels
        ])
        cls.redmod_maxLs = [1]
        expList = pygsti.construction.make_lsgst_experiment_list(
            cls.mdl_redmod_datagen, cls.redmod_fiducials, cls.redmod_fiducials,
            cls.redmod_germs, cls.redmod_maxLs)

        #RUN BELOW FOR DATAGEN (UNCOMMENT to regenerate)
        #redmod_ds = pygsti.construction.generate_fake_data(cls.mdl_redmod_datagen, expList, 1000, "round", seed=1234)
        #redmod_ds.save(compare_files + "/calcMethods2Q_redmod.dataset")

        cls.redmod_ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files +
                                               "/calcMethods2Q_redmod.dataset")

        #print(len(expList)," reduced model sequences")

        #Random starting points - little kick so we don't get hung up at start
        np.random.seed(1234)
        cls.rand_start18 = np.random.random(18) * 1e-6
        cls.rand_start206 = np.random.random(206) * 1e-6
        cls.rand_start228 = np.random.random(228) * 1e-6

        os.chdir(origDir)  # return to original directory