def test_build_up_breadth(self): germs = germsel.build_up_breadth(self.neighbors, self.germ_set, **self.options) # TODO assert correctness algorithm_kwargs = dict( germsList=self.germ_set, **self.options ) germs_driver = germsel.generate_germs( self.mdl_target_noisy, randomize=False, algorithm='greedy', algorithm_kwargs=algorithm_kwargs )
def test_grasp_germ_set_optimization(self): soln = germsel.grasp_germ_set_optimization( self.neighbors, self.germ_set, alpha=0.1, **self.options ) # TODO assert correctness best, initial, local = germsel.grasp_germ_set_optimization( self.neighbors, self.germ_set, alpha=0.1, returnAll=True, **self.options ) # TODO shouldn't this pass? # self.assertEqual(soln, best) algorithm_kwargs = dict( germsList=self.germ_set, **self.options ) soln_driver = germsel.generate_germs( self.mdl_target_noisy, randomize=False, algorithm='grasp', algorithm_kwargs=algorithm_kwargs )
def test_optimize_integer_germs_slack_with_fixed_slack(self): finalGerms = germsel.optimize_integer_germs_slack( self.mdl_target_noisy, self.germ_set, fixedSlack=0.1, verbosity=4 ) # TODO assert correctness finalGerms_all, weights, scores = germsel.optimize_integer_germs_slack( self.mdl_target_noisy, self.germ_set, fixedSlack=0.1, returnAll=True, verbosity=4 ) self.assertEqual(finalGerms, finalGerms_all) algorithm_kwargs = dict( germsList=self.germ_set, fixedSlack=0.1 ) finalGerms_driver = germsel.generate_germs( self.mdl_target_noisy, randomize=False, algorithm='slack', algorithm_kwargs=algorithm_kwargs, verbosity=4 ) self.assertEqual(finalGerms_driver, finalGerms)
def test_auto_experiment_desgin(self): # Let's construct a 1-qubit $X(\pi/2)$, $Y(\pi/2)$, $I$ gateset for which we will need to find germs and fiducials. gs_target = constr.build_gateset([2], [('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"], prepLabels=['rho0'], prepExpressions=["0"], effectLabels=['E0'], effectExpressions=["1"], spamdefs={'plus': ('rho0', 'E0'), 'minus': ('rho0', 'remainder')}) # ## Hands-off # We begin by demonstrating the most hands-off approach. # We can generate a germ set simply by providing the target gateset. germs = germsel.generate_germs(gs_target) # In the same way we can generate preparation and measurement fiducials. prepFiducials, measFiducials = fidsel.generate_fiducials(gs_target) # Now that we have germs and fiducials, we can construct the list of experiments we need to perform in # order to do GST. The only new things to provide at this point are the sizes for the experiments we want # to perform (in this case we want to perform between 0 and 256 gates between fiducial pairs, going up # by a factor of 2 at each stage). maxLengths = [0] + [2**n for n in range(8 + 1)] listOfExperiments = constr.make_lsgst_experiment_list(gs_target.gates.keys(), prepFiducials, measFiducials, germs, maxLengths) # The list of `GateString` that the previous function gave us isn't necessarily the most readable # form to present the information in, so we can write the experiment list out to an empty data # file to be filled in after the experiments are performed. graspGerms = germsel.generate_germs(gs_target, algorithm='grasp', algorithm_kwargs={'iterations': 1}) slackPrepFids, slackMeasFids = fidsel.generate_fiducials(gs_target, algorithm='slack', algorithm_kwargs={'slackFrac': 0.25}) max([len(germ) for germ in germs]) germsMaxLength5 = germsel.generate_germs(gs_target, maxGermLength=5) max([len(germ) for germ in germsMaxLength5]) germsMaxLength3 = germsel.generate_germs(gs_target, maxGermLength=3) uniformPrepFids, uniformMeasFids = fidsel.generate_fiducials(gs_target, maxFidLength=3, algorithm='grasp', algorithm_kwargs={'iterations': 100}) incompletePrepFids, incompleteMeasFids = fidsel.generate_fiducials(gs_target, maxFidLength=1) nonSingletonGerms = germsel.generate_germs(gs_target, forceSingletons=False, maxGermLength=4, algorithm='grasp', algorithm_kwargs={'iterations': 5}) omitIdentityPrepFids, omitIdentityMeasFids = fidsel.generate_fiducials(gs_target, omitIdentity=False, gatesToOmit=['Gi'])
def test_generate_germs_raises_on_bad_algorithm(self): with self.assertRaises(ValueError): germsel.generate_germs(self.mdl_target_noisy, algorithm='foobar')
def test_generate_germs_with_candidate_germ_counts(self): germs = germsel.generate_germs( self.mdl_target_noisy, randomize=False, candidateGermCounts={3: 'all upto', 4: 10, 5: 10, 6: 10} )
def test_auto_experiment_design(self): # Let's construct a 1-qubit $X(\pi/2)$, $Y(\pi/2)$, $I$ gateset for which we will need to find germs and fiducials. gs_target = constr.build_gateset([2], [('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) # ## Hands-off # We begin by demonstrating the most hands-off approach. # We can generate a germ set simply by providing the target gateset. (and seed so it's deterministic) germs = germsel.generate_germs(gs_target, seed=2017) # In the same way we can generate preparation and measurement fiducials. prepFiducials, measFiducials = fidsel.generate_fiducials(gs_target) #test returnAll - this just prints more info... p,m = fidsel.generate_fiducials(gs_target, algorithm_kwargs={'returnAll': True}) #test invalid algorithm with self.assertRaises(ValueError): fidsel.generate_fiducials(gs_target, algorithm='foobar') # Now that we have germs and fiducials, we can construct the list of experiments we need to perform in # order to do GST. The only new things to provide at this point are the sizes for the experiments we want # to perform (in this case we want to perform between 0 and 256 gates between fiducial pairs, going up # by a factor of 2 at each stage). maxLengths = [0] + [2**n for n in range(8 + 1)] listOfExperiments = constr.make_lsgst_experiment_list(gs_target.gates.keys(), prepFiducials, measFiducials, germs, maxLengths) # The list of `GateString` that the previous function gave us isn't necessarily the most readable # form to present the information in, so we can write the experiment list out to an empty data # file to be filled in after the experiments are performed. graspGerms = germsel.generate_germs(gs_target, algorithm='grasp', seed=2017, numGSCopies=2, candidateGermCounts={3: 'all upto', 4:10, 5:10, 6:10}, candidateSeed=2017, algorithm_kwargs={'iterations': 1}) slackPrepFids, slackMeasFids = fidsel.generate_fiducials(gs_target, algorithm='slack', algorithm_kwargs={'slackFrac': 0.25}) fidsel.generate_fiducials(gs_target, algorithm='slack') # slacFrac == 1.0 if don't specify either slackFrac or fixedSlack germsMaxLength3 = germsel.generate_germs(gs_target, candidateGermCounts={3: 'all upto'}, seed=2017) uniformPrepFids, uniformMeasFids = fidsel.generate_fiducials(gs_target, maxFidLength=3, algorithm='grasp', algorithm_kwargs={'iterations': 100}) incompletePrepFids, incompleteMeasFids = fidsel.generate_fiducials(gs_target, maxFidLength=1) nonSingletonGerms = germsel.generate_germs(gs_target, numGSCopies=2, force=None, candidateGermCounts={4: 'all upto'}, algorithm='grasp', algorithm_kwargs={'iterations': 5}, seed=2017) omitIdentityPrepFids, omitIdentityMeasFids = fidsel.generate_fiducials(gs_target, omitIdentity=False, gatesToOmit=['Gi'])
def test_auto_experiment_desgin(self): # Let's construct a 1-qubit $X(\pi/2)$, $Y(\pi/2)$, $I$ gateset for which we will need to find germs and fiducials. gs_target = constr.build_gateset([2], [('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"], prepLabels=['rho0'], prepExpressions=["0"], effectLabels=['E0'], effectExpressions=["1"], spamdefs={ 'plus': ('rho0', 'E0'), 'minus': ('rho0', 'remainder') }) # ## Hands-off # We begin by demonstrating the most hands-off approach. # We can generate a germ set simply by providing the target gateset. germs = germsel.generate_germs(gs_target) # In the same way we can generate preparation and measurement fiducials. prepFiducials, measFiducials = fidsel.generate_fiducials(gs_target) # Now that we have germs and fiducials, we can construct the list of experiments we need to perform in # order to do GST. The only new things to provide at this point are the sizes for the experiments we want # to perform (in this case we want to perform between 0 and 256 gates between fiducial pairs, going up # by a factor of 2 at each stage). maxLengths = [0] + [2**n for n in range(8 + 1)] listOfExperiments = constr.make_lsgst_experiment_list( gs_target.gates.keys(), prepFiducials, measFiducials, germs, maxLengths) # The list of `GateString` that the previous function gave us isn't necessarily the most readable # form to present the information in, so we can write the experiment list out to an empty data # file to be filled in after the experiments are performed. graspGerms = germsel.generate_germs(gs_target, algorithm='grasp', algorithm_kwargs={'iterations': 1}) slackPrepFids, slackMeasFids = fidsel.generate_fiducials( gs_target, algorithm='slack', algorithm_kwargs={'slackFrac': 0.25}) max([len(germ) for germ in germs]) germsMaxLength5 = germsel.generate_germs(gs_target, maxGermLength=5) max([len(germ) for germ in germsMaxLength5]) germsMaxLength3 = germsel.generate_germs(gs_target, maxGermLength=3) uniformPrepFids, uniformMeasFids = fidsel.generate_fiducials( gs_target, maxFidLength=3, algorithm='grasp', algorithm_kwargs={'iterations': 100}) incompletePrepFids, incompleteMeasFids = fidsel.generate_fiducials( gs_target, maxFidLength=1) nonSingletonGerms = germsel.generate_germs( gs_target, force=None, maxGermLength=4, algorithm='grasp', algorithm_kwargs={'iterations': 5}) omitIdentityPrepFids, omitIdentityMeasFids = fidsel.generate_fiducials( gs_target, omitIdentity=False, gatesToOmit=['Gi'])