Beispiel #1
0
    def test_reducedmod_cterm(self):
        # Using term-based calcs using map-based stabilizer-state propagation
        target_model = pc.build_nqnoise_model(
            self.nQubits,
            geometry="line",
            maxIdleWeight=1,
            maxhops=1,
            extraWeight1Hops=0,
            extraGateWeight=1,
            sparse=False,
            verbosity=1,
            sim_type="termorder:1",
            parameterization="H+S clifford terms")
        target_model.from_vector(self.rand_start228)
        results = pygsti.do_long_sequence_gst(
            self.redmod_ds,
            target_model,
            self.redmod_fiducials,
            self.redmod_fiducials,
            self.redmod_germs,
            self.redmod_maxLs,
            verbosity=4,
            advancedOptions={'tolerance': 1e-3})

        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               3.0,
                               delta=1.0)
        mdl_compare = pygsti.io.json.load(
            open(compare_files + "/test2Qcalc_redmod_terms.model"))
        self.assertAlmostEqual(np.linalg.norm(
            results.estimates['default'].models['go0'].to_vector() -
            mdl_compare.to_vector()),
                               0,
                               places=3)
Beispiel #2
0
    def test_reducedmod_map2(self):
        # Using sparse embedded matrices and map-based calcs
        target_model = pc.build_nqnoise_model(self.nQubits,
                                              geometry="line",
                                              maxIdleWeight=1,
                                              maxhops=1,
                                              extraWeight1Hops=0,
                                              extraGateWeight=1,
                                              sparse=True,
                                              sim_type="map",
                                              verbosity=1)
        target_model.from_vector(self.rand_start206)
        results = pygsti.do_long_sequence_gst(
            self.redmod_ds,
            target_model,
            self.redmod_fiducials,
            self.redmod_fiducials,
            self.redmod_germs,
            self.redmod_maxLs,
            verbosity=4,
            advancedOptions={'tolerance': 1e-3})

        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               1.0,
                               delta=1.0)
        mdl_compare = pygsti.io.json.load(
            open(compare_files + "/test2Qcalc_redmod_exact.model"))
        self.assertAlmostEqual(np.linalg.norm(
            results.estimates['default'].models['go0'].to_vector() -
            mdl_compare.to_vector()),
                               0,
                               places=1)
Beispiel #3
0
    def test_reducedmod_map1(self):
        # Using dense embedded matrices and map-based calcs (maybe not really necessary to include?)
        target_model = pc.build_nqnoise_model(self.nQubits,
                                              geometry="line",
                                              max_idle_weight=1,
                                              maxhops=1,
                                              extra_weight_1_hops=0,
                                              extra_gate_weight=1,
                                              sparse=False,
                                              sim_type="map",
                                              verbosity=1)
        target_model.from_vector(self.rand_start206)
        results = pygsti.run_long_sequence_gst(
            self.redmod_ds,
            target_model,
            self.redmod_fiducials,
            self.redmod_fiducials,
            self.redmod_germs,
            self.redmod_maxLs,
            verbosity=4,
            advanced_options={'tolerance': 1e-3})

        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               1.0,
                               delta=1.0)
        mdl_compare = pygsti.serialization.json.load(
            open(compare_files + "/test2Qcalc_redmod_exact.model"))
        self.assertAlmostEqual(
            results.estimates['default'].models['go0'].frobeniusdist(
                mdl_compare),
            0,
            places=1)
Beispiel #4
0
    def test_reducedmod_svterm(self):
        # Using term-based calcs using map-based state-vector propagation
        target_model = pc.build_nqnoise_model(self.nQubits,
                                              geometry="line",
                                              max_idle_weight=1,
                                              maxhops=1,
                                              extra_weight_1_hops=0,
                                              extra_gate_weight=1,
                                              sparse=False,
                                              verbosity=1,
                                              sim_type="termorder:1",
                                              parameterization="H+S terms")
        target_model.from_vector(self.rand_start228)
        results = pygsti.run_long_sequence_gst(
            self.redmod_ds,
            target_model,
            self.redmod_fiducials,
            self.redmod_fiducials,
            self.redmod_germs,
            self.redmod_maxLs,
            verbosity=4,
            advanced_options={'tolerance': 1e-3})

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

        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               3.0,
                               delta=1.0)
        mdl_compare = pygsti.serialization.json.load(
            open(compare_files + "/test2Qcalc_redmod_terms.model"))
        self.assertAlmostEqual(np.linalg.norm(
            results.estimates['default'].models['go0'].to_vector() -
            mdl_compare.to_vector()),
                               0,
                               places=3)
Beispiel #5
0
    def test_reducedmod_matrix(self):
        # Using dense matrices and matrix-based calcs
        target_model = pc.build_nqnoise_model(self.nQubits,
                                              geometry="line",
                                              maxIdleWeight=1,
                                              maxhops=1,
                                              extraWeight1Hops=0,
                                              extraGateWeight=1,
                                              sparse=False,
                                              sim_type="matrix",
                                              verbosity=1)
        target_model.from_vector(self.rand_start206)
        results = pygsti.do_long_sequence_gst(
            self.redmod_ds,
            target_model,
            self.redmod_fiducials,
            self.redmod_fiducials,
            self.redmod_germs,
            self.redmod_maxLs,
            verbosity=4,
            advancedOptions={'tolerance': 1e-3})

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

        print("MISFIT nSigma = ", results.estimates['default'].misfit_sigma())
        self.assertAlmostEqual(results.estimates['default'].misfit_sigma(),
                               1.0,
                               delta=1.0)
        mdl_compare = pygsti.io.json.load(
            open(compare_files + "/test2Qcalc_redmod_exact.model"))
        self.assertAlmostEqual(
            results.estimates['default'].models['go0'].frobeniusdist(
                mdl_compare),
            0,
            places=3)
Beispiel #6
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