def test_gst(self): comm = self.ralloc.comm exp_design = std.get_gst_experiment_design(4) mdl_datagen = std.target_model().depolarize(op_noise=0.1, spam_noise=0.01) ds = pygsti.data.simulate_data(mdl_datagen, exp_design, 1000, seed=1234, comm=comm) data = pygsti.protocols.ProtocolData(exp_design, ds) initial_model = std.target_model("full TP") proto = pygsti.protocols.GateSetTomography( initial_model, verbosity=1, optimizer={ 'maxiter': 100, 'serial_solve_proc_threshold': 100 }) results_serial = proto.run(data, comm=None) results_parallel = proto.run(data, comm=comm) # compare resulting models if comm is None or comm.rank == 0: best_params_serial = results_serial.estimates[ "GateSetTomography"].models['stdgaugeopt'].to_vector() best_params_parallel = results_parallel.estimates[ "GateSetTomography"].models['stdgaugeopt'].to_vector() assert np.allclose(best_params_serial, best_params_parallel)
def setUp(self): self.gst_design = smq1Q_XYI.get_gst_experiment_design(4, qubit_labels=[0]) nQubits = 2 self.pspec_2Q = QubitProcessorSpec( nQubits, ('Gx', 'Gy', 'Gcnot'), geometry="line", qubit_labels=['qb{}'.format(i) for i in range(nQubits)])
def setUpClass(cls): cls.gst_design = smq1Q_XYI.get_gst_experiment_design(max_max_length=4) cls.mdl_target = smq1Q_XYI.target_model() cls.mdl_datagen = cls.mdl_target.depolarize(op_noise=0.05, spam_noise=0.025) ds = simulate_data(cls.mdl_datagen, cls.gst_design.all_circuits_needing_data, 1000, sample_error='none') cls.gst_data = ProtocolData(cls.gst_design, ds)
def setUpClass(cls): #Construct a results object gst_design = smq1Q_XYI.get_gst_experiment_design(max_max_length=4) mdl_target = smq1Q_XYI.target_model() mdl_datagen = mdl_target.depolarize(op_noise=0.05, spam_noise=0.025) ds = simulate_data(mdl_datagen, gst_design.all_circuits_needing_data, 1000, seed=2020) data = ProtocolData(gst_design, ds) cls.results = gst.ModelEstimateResults(data, Protocol("test-protocol")) cls.results.add_estimate(Estimate.create_gst_estimate( cls.results, mdl_target, mdl_target, [mdl_datagen] * len(gst_design.circuit_lists), parameters={'objective': 'logl'}), estimate_key="test-estimate") cls.target_model = mdl_target
def test_simulate_data(self): comm = self.ralloc.comm exp_design = std.get_gst_experiment_design(4) mdl_datagen = std.target_model().depolarize(op_noise=0.1, spam_noise=0.01) ds_serial = pygsti.data.simulate_data(mdl_datagen, exp_design, 1000, seed=1234, comm=None) ds_parallel = pygsti.data.simulate_data(mdl_datagen, exp_design, 1000, seed=1234, comm=comm) if comm is None or comm.rank == 0: assert (set(ds_serial.keys()) == set(ds_parallel.keys())) for key in ds_serial.keys(): assert (ds_serial[key].to_dict() == ds_parallel[key].to_dict())
def run_objfn_values(self, sim, objfn, natoms): comm = self.ralloc.comm mdl = std.target_model() exp_design = std.get_gst_experiment_design(1) mdl_datagen = mdl.depolarize(op_noise=0.01, spam_noise=0.01) ds = pygsti.data.simulate_data(mdl_datagen, exp_design, 1000, seed=1234, comm=comm) builder = pygsti.objectivefns.ObjectiveFunctionBuilder.create_from( objfn) builder.additional_args['array_types'] = ('EP', 'EPP' ) # HACK - todo this better if sim == 'map': mdl.sim = pygsti.forwardsims.MapForwardSimulator(num_atoms=natoms) elif sim == 'matrix': mdl.sim = pygsti.forwardsims.MatrixForwardSimulator( num_atoms=natoms) else: raise RuntimeError( "Improper sim type passed by test_objfn_generator") circuits = exp_design.all_circuits_needing_data[0:10] objfn_parallel = builder.build(mdl, ds, circuits, self.ralloc, verbosity=0) objfn_serial = builder.build(mdl, ds, circuits, None, verbosity=0) #LSVEC TEST v_ref = objfn_serial.lsvec() v = objfn_parallel.lsvec() globalv = objfn_parallel.layout.gather_local_array('e', v) if comm is None or comm.rank == 0: finalv = np.empty_like(globalv) off = 0 for c in circuits: indices, outcomes = objfn_parallel.layout.global_layout.indices_and_outcomes( c) assert (outcomes == (('0', ), ('1', )) ) # I think this should always be the ordering (?) finalv[off:off + len(outcomes)] = globalv[indices] off += len(outcomes) finalv_ref = np.empty_like(v_ref) off = 0 for c in circuits: indices, outcomes = objfn_serial.layout.indices_and_outcomes(c) assert (outcomes == (('0', ), ('1', )) ) # I think this should always be the ordering (?) finalv_ref[off:off + len(outcomes)] = v_ref[indices] off += len(outcomes) assert np.allclose(finalv, finalv_ref) #TODO: DLSVEC? #HESSIAN TEST hessian_ref = objfn_serial.hessian() hessian = objfn_parallel.hessian( ) # already a global qty, just on root proc bhessian_ref = objfn_serial.hessian_brute() bhessian = objfn_parallel.hessian_brute() if comm is None or comm.rank == 0: assert np.allclose(bhessian_ref, hessian_ref) assert np.allclose(hessian, hessian_ref) assert np.allclose(bhessian, bhessian_ref)
def setUpClass(cls): cls.gst_design = std.get_gst_experiment_design(4)
def setUp(self): self.edesign = smq1Q_XYI.get_gst_experiment_design(max_max_length=2) self.target_model = smq1Q_XYI.target_model()