コード例 #1
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
    def test_change_gate_library(self):
        # Change gate library using an ordinary dict with every gate as a key. (we test
        # changing gate library using a CompilationLibrary elsewhere in the tests).
        labels = circuit.Circuit(None, stringrep="[Gz:Q0Gy:Q1][Gy:Q0Gz:Q1]Gz:Q0Gi:Q1")
        c = circuit.Circuit(layer_labels=labels, line_labels=['Q0', 'Q1'], editable=True)
        comp = {}
        comp[Label('Gz', 'Q0')] = circuit.Circuit(layer_labels=[Label('Gx', 'Q0')], line_labels=['Q0'])
        comp[Label('Gy', 'Q0')] = circuit.Circuit(layer_labels=[Label('Gx', 'Q0')], line_labels=['Q0'])
        comp[Label('Gz', 'Q1')] = circuit.Circuit(layer_labels=[Label('Gx', 'Q1')], line_labels=['Q1'])
        comp[Label('Gy', 'Q1')] = circuit.Circuit(layer_labels=[Label('Gx', 'Q1')], line_labels=['Q1'])
        comp[Label('Gi', 'Q1')] = circuit.Circuit(layer_labels=[Label('Gi', 'Q1')], line_labels=['Q1'])

        c.change_gate_library(comp)
        self.assertTrue(Label('Gx', 'Q0') in c[0].components)
コード例 #2
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
 def test_append_circuit(self):
     # Test appending
     c2 = circuit.Circuit(layer_labels=[Label('Gx', 'Q0')], line_labels=['Q0', ], editable=True)
     self.c.append_circuit_inplace(c2)
     self.assertEqual(self.c.depth, 6)
     self.assertEqual(self.c[5, 'Q0'], Label('Gx', 'Q0'))
コード例 #3
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
 def test_prefix_circuit(self):
     c2 = circuit.Circuit(layer_labels=[Label('Gx', 'Q0')], line_labels=['Q0', ], editable=True)
     self.c.prefix_circuit_inplace(c2)
     self.assertEqual(self.c.depth, 6)
     self.assertEqual(self.c[0, 'Q0'], Label('Gx', 'Q0'))
コード例 #4
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
 def test_insert_circuit_label_collision(self):
     # Test inserting a circuit when they are over the same labels.
     c_copy = self.c.copy()
     self.c.insert_circuit_inplace(c_copy, 2)
     self.assertTrue(Label('Gx', 'Q0') in self.c[2].components)
コード例 #5
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
 def test_insert_circuit_with_qubit_subset(self):
     # Test inserting a circuit that is on *less* qubits.
     c2 = circuit.Circuit(layer_labels=[Label('Gx', 'Q0')], line_labels=['Q0', ])
     self.c.insert_circuit_inplace(c2, 1)
     self.assertEqual(self.c.line_labels, ('Q0', 'Q1'))
     self.assertEqual(self.c.num_lines, 2)
コード例 #6
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
 def test_replace_layer_with_layer(self):
     # Test replacing a layer with a layer.
     newlayer = [Label('Gx', 'Q0')]
     self.c[1] = newlayer
     self.assertEqual(self.c.depth, 5)
コード例 #7
0
ファイル: test_circuit.py プロジェクト: sethmerkel/pyGSTi
 def test_empty_tuple_makes_idle_layer(self):
     c = circuit.Circuit(['Gi', Label(())])
     self.assertEqual(len(c), 2)
コード例 #8
0
                                      qubit_labels=fixture_2Q.qubit_labels,
                                      geometry='line')
fixture_2Q.clifford_abs = CliffordCompilationRules.create_standard(
    fixture_2Q.pspec,
    compile_type="absolute",
    what_to_compile=("1Qcliffords", "paulis"),
    verbosity=1)
fixture_2Q.clifford_peq = CliffordCompilationRules.create_standard(
    fixture_2Q.pspec,
    compile_type="paulieq",
    what_to_compile=("1Qcliffords", "allcnots"),
    verbosity=1)

# Totally arbitrary CNOT circuit
fixture_2Q.cnot_circuit = Circuit(layer_labels=[
    Label('CNOT', ('Q1', 'Q0')),
    Label('CNOT', ('Q1', 'Q0')),
    Label('CNOT', ('Q0', 'Q1')),
    Label('CNOT', ('Q1', 'Q0'))
],
                                  line_labels=fixture_2Q.qubit_labels)
fixture_2Q.cnot_circuit_sym, fixture_2Q.cnot_circuit_phase = \
    symplectic.symplectic_rep_of_clifford_circuit(fixture_2Q.cnot_circuit)

fixture_3Q = Namespace(
    n=3,
    qubit_labels=['Q0', 'Q1', 'Q2'],
    availability={'Gcnot': [('Q0', 'Q1'), ('Q1', 'Q2')]},
    gate_names=['Gh', 'Gp', 'Gxpi', 'Gpdag', 'Gcnot'],
    # generated as before:
    clifford_sym=np.array([[0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 1, 0],
コード例 #9
0
ファイル: test_rb.py プロジェクト: stjordanis/pyGSTi
 def test_sample(self):
     
     # -- pspecs to use in all the tests. They cover a variety of possibilities -- #
     
     n_1 = 4
     glist = ['Gi','Gxpi2','Gypi2','Gcnot']
     pspec_1 = pygsti.obj.ProcessorSpec(n_1,glist,verbosity=0,qubit_labels=['Q0','Q1','Q2','Q3'])
 
     n_2 = 3
     glist = ['Gi','Gxpi','Gypi','Gzpi','Gh','Gp','Gcphase']
     availability = {'Gcphase':[(0,1),(1,2)]}
     pspec_2 = pygsti.obj.ProcessorSpec(n_2,glist,availability=availability,verbosity=0)
     
     # Tests Clifford RB samplers
     lengths = [0,2,5]
     circuits_per_length = 2
     subsetQs = ['Q1','Q2','Q3']
     out = rb.sample.clifford_rb_experiment(pspec_1, lengths, circuits_per_length, subsetQs=subsetQs, randomizeout=False, 
                                        citerations=2, compilerargs=[], descriptor='A Clifford RB experiment', verbosity=0)
     for key in list(out['idealout'].keys()):
         self.assertEqual(out['idealout'][key], (0,0,0))
 
     self.assertEqual(len(out['circuits']), circuits_per_length * len(lengths))
 
     out = rb.sample.clifford_rb_experiment(pspec_2, lengths, circuits_per_length, subsetQs=None, randomizeout=True, 
                                        citerations=1, compilerargs=[], descriptor='A Clifford RB experiment',verbosity=0)
     
     # --- Tests of the circuit layer samplers --- #
 
     # Tests for the sampling by pairs function
     layer = rb.sample.circuit_layer_by_pairing_qubits(pspec_1, twoQprob=0.0, oneQgatenames='all', twoQgatenames='all', 
                                       gatesetname = 'clifford')
     self.assertEqual(len(layer), n_1)
     layer = rb.sample.circuit_layer_by_pairing_qubits(pspec_1, twoQprob=1.0, oneQgatenames='all', twoQgatenames='all', 
                                       gatesetname = 'clifford')
     self.assertEqual(len(layer), n_1//2)
     layer = rb.sample.circuit_layer_by_pairing_qubits(pspec_1, twoQprob=0.0, oneQgatenames=['Gx',], twoQgatenames='all', 
                                       gatesetname = 'target')
     self.assertEqual(layer[0].name, 'Gx')
 
     layer = rb.sample.circuit_layer_by_Qelimination(pspec_2, twoQprob=0.0, oneQgates='all', twoQgates='all',
                                                     gatesetname='clifford')
     self.assertEqual(len(layer), n_2)
     layer = rb.sample.circuit_layer_by_Qelimination(pspec_2, twoQprob=1.0, oneQgates='all', twoQgates='all',
                                                     gatesetname='clifford')
     self.assertEqual(len(layer), (n_2 % 2) + n_2//2)
     layer = rb.sample.circuit_layer_by_pairing_qubits(pspec_1, twoQprob=0.0, oneQgatenames=['Gxpi'], twoQgatenames='all', 
                                       gatesetname = 'target')
     self.assertEqual(layer[0].name, 'Gxpi')
 
     # Tests for the sampling by co2Qgates function
     C01 = Label('Gcnot',('Q0','Q1'))
     C23 = Label('Gcnot',('Q2','Q3'))
     co2Qgates = [[],[C01,C23]]
     layer = rb.sample.circuit_layer_by_co2Qgates(pspec_1, None, co2Qgates, co2Qgatesprob='uniform', twoQprob=1.0, 
                                                oneQgatenames='all', gatesetname='clifford')
     self.assertTrue(len(layer) == n_1 or len(layer) == n_1//2)
     layer = rb.sample.circuit_layer_by_co2Qgates(pspec_1, None, co2Qgates, co2Qgatesprob=[0.,1.], twoQprob=1.0, 
                                                oneQgatenames='all', gatesetname='clifford')
     self.assertEqual(len(layer), n_1//2)
     layer = rb.sample.circuit_layer_by_co2Qgates(pspec_1, None, co2Qgates, co2Qgatesprob=[1.,0.], twoQprob=1.0, 
                                                oneQgatenames=['Gx',], gatesetname='clifford')
     self.assertEqual(len(layer), n_1)
     self.assertEqual(layer[0].name, 'Gx')
     
     co2Qgates = [[],[C23,]]
     layer = rb.sample.circuit_layer_by_co2Qgates(pspec_1, ['Q2','Q3'], co2Qgates, co2Qgatesprob=[0.25,0.75], twoQprob=0.5, 
                                                oneQgatenames='all', gatesetname='clifford')
     co2Qgates = [[C01,]]
     layer = rb.sample.circuit_layer_by_co2Qgates(pspec_1, None, co2Qgates, co2Qgatesprob=[1.], twoQprob=1.0, 
                                                oneQgatenames='all', gatesetname='clifford')
     self.assertEqual(layer[0].name, 'Gcnot')
     self.assertEqual(len(layer), 3)
     
     # Tests the nested co2Qgates option.
     co2Qgates = [[],[[C01,C23],[C01,]]]
     layer = rb.sample.circuit_layer_by_co2Qgates(pspec_1, None, co2Qgates, co2Qgatesprob='uniform', twoQprob=1.0, 
                                                oneQgatenames='all', gatesetname='clifford')
     # Tests for the sampling a layer of 1Q gates.
     layer = rb.sample.circuit_layer_of_oneQgates(pspec_1, oneQgatenames='all', pdist='uniform',
                                                 gatesetname='clifford')
     self.assertEqual(len(layer), n_1)
     layer = rb.sample.circuit_layer_of_oneQgates(pspec_1, subsetQs=['Q1','Q2'], oneQgatenames=['Gx','Gy'], pdist=[1.,0.],
                                                 gatesetname='clifford')
     self.assertEqual(len(layer), 2)
     self.assertEqual(layer[0].name, 'Gx')
     layer = rb.sample.circuit_layer_of_oneQgates(pspec_1, subsetQs=['Q2'],oneQgatenames=['Gx'], pdist=[3.,],
                                                 gatesetname='clifford')
     self.assertEqual(layer[0], Label('Gx','Q2'))
     self.assertEqual(len(layer), 1)
     layer = rb.sample.circuit_layer_of_oneQgates(pspec_1, oneQgatenames=['Gx'], pdist='uniform',
                                                 gatesetname='clifford')
     
     # Tests of the random_circuit sampler that is a wrap-around for the circuit-layer samplers
     
     C01 = Label('Gcnot',('Q0','Q1'))
     C23 = Label('Gcnot',('Q2','Q3'))
     co2Qgates = [[],[[C01,C23],[C01,]]]
     circuit = rb.sample.random_circuit(pspec_1, length=100, sampler='Qelimination')
     self.assertEqual(circuit.depth(), 100)
     circuit = rb.sample.random_circuit(pspec_2, length=100, sampler='Qelimination', samplerargs=[0.1,], addlocal = True)
     self.assertEqual(circuit.depth(), 201)
     self.assertLessEqual(len(circuit.get_layer(0)), n_2)
     circuit = rb.sample.random_circuit(pspec_1, length=100, sampler='pairingQs')
     circuit = rb.sample.random_circuit(pspec_1, length=10, sampler='pairingQs', samplerargs=[0.1,['Gx',]])
 
     circuit = rb.sample.random_circuit(pspec_1, length=100, sampler='co2Qgates', samplerargs=[co2Qgates])
     circuit = rb.sample.random_circuit(pspec_1, length=100, sampler='co2Qgates', samplerargs=[co2Qgates,[0.1,0.2],0.1], 
                                 addlocal = True, lsargs=[['Gx',]])
     self.assertEqual(circuit.depth(), 201)
     circuit = rb.sample.random_circuit(pspec_1, length=5, sampler='local')
     self.assertEqual(circuit.depth(), 5)
     circuit = rb.sample.random_circuit(pspec_1, length=5, sampler='local',samplerargs=[['Gx']])
     self.assertEqual(circuit.line_items[0][0].name, 'Gx')
     
     lengths = [0,2,5]
     circuits_per_length = 2
     # Test DRB experiment with all defaults.
     exp = rb.sample.direct_rb_experiment(pspec_2, lengths, circuits_per_length, verbosity=0)
     
     exp = rb.sample.direct_rb_experiment(pspec_2, lengths, circuits_per_length, subsetQs=[0,1], sampler='pairingQs',
                                         cliffordtwirl=False, conditionaltwirl=False, citerations=2, partitioned=True,
                                         verbosity=0)
     
     exp = rb.sample.direct_rb_experiment(pspec_2, lengths, circuits_per_length, subsetQs=[0,1], sampler='co2Qgates',
                                          samplerargs = [[[],[Label('Gcphase',(0,1)),]],[0.,1.]],
                                         cliffordtwirl=False, conditionaltwirl=False, citerations=2, partitioned=True,
                                         verbosity=0)
     
     exp = rb.sample.direct_rb_experiment(pspec_2, lengths, circuits_per_length, subsetQs=[0,1], sampler='local',
                                         cliffordtwirl=False, conditionaltwirl=False, citerations=2, partitioned=True,
                                         verbosity=0)
     
     # Tests of MRB : gateset must have self-inverses in the gate-set.
     n_1 = 4
     glist = ['Gi','Gxpi2','Gxmpi2','Gypi2','Gympi2','Gcnot']
     pspec_inv = pygsti.obj.ProcessorSpec(n_1, glist, verbosity=0, qubit_labels=['Q0','Q1','Q2','Q3'])
     lengths = [0,4,8]
     circuits_per_length = 10
     exp = rb.sample.mirror_rb_experiment(pspec_inv, lengths, circuits_per_length, subsetQs=['Q1','Q2','Q3'],
                                          sampler='Qelimination', samplerargs=[], localclifford=True, 
                                          paulirandomize=True)
     
     exp = rb.sample.mirror_rb_experiment(pspec_inv, lengths, circuits_per_length, subsetQs=['Q1','Q2','Q3'],
                                          sampler='Qelimination', samplerargs=[], localclifford=True, 
                                          paulirandomize=False)
     
     exp = rb.sample.mirror_rb_experiment(pspec_inv, lengths, circuits_per_length, subsetQs=['Q1','Q2','Q3'],
                                          sampler='Qelimination', samplerargs=[], localclifford=False, 
                                          paulirandomize=False)
  
     exp = rb.sample.mirror_rb_experiment(pspec_inv, lengths, circuits_per_length, subsetQs=['Q1','Q2','Q3'],
                                          sampler='Qelimination', samplerargs=[], localclifford=False, 
                                          paulirandomize=True)
コード例 #10
0
    def test_time_estimation(self):
        edesign = smq2Q_XYICNOT.create_gst_experiment_design(256)
        
        # Dummy test: No time
        time0 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_1Q=0,
            gate_time_2Q=0,
            measure_reset_time=0,
            interbatch_latency=0,
        )
        self.assertAlmostEqual(time0, 0.0)
    
        # Dummy test: 1 second for each circuit shot
        time0 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_1Q=0,
            gate_time_2Q=0,
            measure_reset_time=1,
            interbatch_latency=0,
            total_shots_per_circuit=1000
        )
        self.assertAlmostEqual(time0, 1000*len(edesign.all_circuits_needing_data))

        # Dummy test: 1 second for each circuit shot, + 10 s for each circuit due to batching
        time0 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_1Q=0,
            gate_time_2Q=0,
            measure_reset_time=1,
            interbatch_latency=10,
            total_shots_per_circuit=1000,
            circuits_per_batch=1
        )
        self.assertAlmostEqual(time0, 1010*len(edesign.all_circuits_needing_data))

        # Dummy test: 1 second for each circuit shot, + (10 s for each circuit due to batching x 10 rounds)
        time0 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_1Q=0,
            gate_time_2Q=0,
            measure_reset_time=1,
            interbatch_latency=10,
            total_shots_per_circuit=1000,
            shots_per_circuit_per_batch=100,
            circuits_per_batch=1
        )
        self.assertAlmostEqual(time0, 1100*len(edesign.all_circuits_needing_data))


        # Try dict version of trapped ion example
        gate_times = {
            'Gxpi2': 10e-6,
            'Gypi2': 10e-6,
            'Gcnot': 100e-6,
            Label(()): 10e-6,
        }
        time1 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_dict=gate_times,
            measure_reset_time=500e-6,
            interbatch_latency=0.1,
            total_shots_per_circuit=1000,
            shots_per_circuit_per_batch=100,
            circuits_per_batch=200
        )

        # Try equivalent gate time version
        time2 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_1Q=10e-6,
            gate_time_2Q=100e-6,
            measure_reset_time=500e-6,
            interbatch_latency=0.1,
            total_shots_per_circuit=1000,
            shots_per_circuit_per_batch=100,
            circuits_per_batch=200
        )
        self.assertAlmostEqual(time1, time2)

        # Qubit-specific overload
        gate_times2 = {
            'Gxpi2': 10e-6,
            ('Gxpi2', 0): 20e-6,
            'Gypi2': 10e-6,
            'Gcnot': 100e-6,
            Label(()): 10e-6,
        }
        time3 = et.calculate_edesign_estimated_runtime(
            edesign,
            gate_time_dict=gate_times2,
            measure_reset_time=500e-6,
            interbatch_latency=0.1,
            total_shots_per_circuit=1000,
            shots_per_circuit_per_batch=100,
            circuits_per_batch=200
        )
        self.assertGreater(time3, time1)