예제 #1
0
 def test_build_model(self):
     # TODO this isn't a unit test
     stateSpace = [(4,)]  # density matrix is a 2x2 matrix
     spaceLabels = [('Q0',)]  # interpret the 2x2 density matrix as a single qubit named 'Q0'
     model1 = pygsti.objects.ExplicitOpModel(['Q0'])
     model1['rho0'] = mc.build_vector(stateSpace, spaceLabels, "0")
     model1['Mdefault'] = pygsti.obj.UnconstrainedPOVM([('0', mc.build_vector(stateSpace, spaceLabels, "0")),
                                                        ('1', mc.build_vector(stateSpace, spaceLabels, "1"))])
     model1['Gi'] = mc.build_operation(stateSpace, spaceLabels, "I(Q0)")
     model1['Gx'] = mc.build_operation(stateSpace, spaceLabels, "X(pi/2,Q0)")
     model1['Gy'] = mc.build_operation(stateSpace, spaceLabels, "Y(pi/2,Q0)")
예제 #2
0
    def test_construct_gates_full(self):
        self._construct_gates('full')

        self.leakA = mc.build_operation([(1,), (1,), (1,)], [('L0',), ('L1',), ('L2',)],
                                        "LX(pi,0,1)", self.basis, 'full')
        self.rotLeak = mc.build_operation([(4,), (1,)], [('Q0',), ('L0',)],
                                          "X(pi,Q0):LX(pi,0,2)", self.basis, 'full')
        self.leakB = mc.build_operation([(4,), (1,)], [('Q0',), ('L0',)], "LX(pi,0,2)", self.basis, 'full')
        self.rotXb = mc.build_operation([(4,), (1,), (1,)], [('Q0',), ('L0',), ('L1',)],
                                        "X(pi,Q0)", self.basis, 'full')
        self.CnotB = mc.build_operation([(4, 4), (1,)], [('Q0', 'Q1'), ('L0',)], "CX(pi,Q0,Q1)", self.basis, 'full')
예제 #3
0
 def test_rotate_1q(self):
     rotXPi = build_operation([(4, )], [('Q0', )], "X(pi,Q0)")
     rotXPiOv2 = build_operation([(4, )], [('Q0', )], "X(pi/2,Q0)")
     rotYPiOv2 = build_operation([(4, )], [('Q0', )], "Y(pi/2,Q0)")
     gateset_rot = self.model.rotate(
         (np.pi / 2, 0, 0))  # rotate all gates by pi/2 about X axis
     self.assertArraysAlmostEqual(gateset_rot['Gi'], rotXPiOv2)
     self.assertArraysAlmostEqual(gateset_rot['Gx'], rotXPi)
     self.assertArraysAlmostEqual(gateset_rot['Gx'],
                                  np.dot(rotXPiOv2, rotXPiOv2))
     self.assertArraysAlmostEqual(gateset_rot['Gy'],
                                  np.dot(rotXPiOv2, rotYPiOv2))
예제 #4
0
 def test_raises_on_LX_with_bad_basis_spec(self):
     with self.assertRaises(AssertionError):
         mc.build_operation([(4,), (1,)], [('Q0',), ('L0',)], "LX(pi,0,2)", "foobar", 'std')
예제 #5
0
 def test_raises_on_qubit_state_space_mismatch(self):
     with self.assertRaises(ValueError):
         mc.build_operation([(4,), (4,)], [('Q0',), ('Q1',)], "CZ(pi,Q0,Q1)", self.basis, 'std')
예제 #6
0
 def test_raises_on_state_space_dim_mismatch(self):
     with self.assertRaises(TypeError):
         mc.build_operation([2], [('Q0',)], "I(Q0)", self.basis, 'std')
예제 #7
0
 def test_raises_on_bad_label(self):
     with self.assertRaises(KeyError):
         mc.build_operation([(4,)], [('Q0', 'L0')], "I(Q0,A0)", self.basis, 'std')
예제 #8
0
 def test_raises_on_bad_state_spec(self):
     with self.assertRaises(KeyError):
         mc.build_operation([(4,)], [('A0',)], "I(Q0)", self.basis, 'std')
예제 #9
0
 def test_raises_on_bad_gate_name(self):
     with self.assertRaises(ValueError):
         mc.build_operation([(4,)], [('Q0',)], "FooBar(Q0)", self.basis, 'std')
예제 #10
0
 def test_raises_on_bad_basis(self):
     with self.assertRaises(AssertionError):
         mc.build_operation([(4,)], [('Q0',)], "X(pi/2,Q0)", "FooBar", 'std')
예제 #11
0
    def _construct_gates(self, param):
        # TODO these aren't really unit tests
        #CNOT gate
        Ucnot = np.array([[1, 0, 0, 0],
                          [0, 1, 0, 0],
                          [0, 0, 0, 1],
                          [0, 0, 1, 0]], 'd')
        cnotMx = pygsti.tools.unitary_to_process_mx(Ucnot)
        self.CNOT_chk = pygsti.tools.change_basis(cnotMx, "std", self.basis)

        #CPHASE gate
        Ucphase = np.array([[1, 0, 0, 0],
                            [0, 1, 0, 0],
                            [0, 0, 1, 0],
                            [0, 0, 0, -1]], 'd')
        cphaseMx = pygsti.tools.unitary_to_process_mx(Ucphase)
        self.CPHASE_chk = pygsti.tools.change_basis(cphaseMx, "std", self.basis)
        self.ident = mc.build_operation([(4,)], [('Q0',)], "I(Q0)", self.basis, param)
        self.rotXa = mc.build_operation([(4,)], [('Q0',)], "X(pi/2,Q0)", self.basis, param)
        self.rotX2 = mc.build_operation([(4,)], [('Q0',)], "X(pi,Q0)", self.basis, param)
        self.rotYa = mc.build_operation([(4,)], [('Q0',)], "Y(pi/2,Q0)", self.basis, param)
        self.rotZa = mc.build_operation([(4,)], [('Q0',)], "Z(pi/2,Q0)", self.basis, param)
        self.rotNa = mc.build_operation([(4,)], [('Q0',)], "N(pi/2,1.0,0.5,0,Q0)", self.basis, param)
        self.iwL = mc.build_operation([(4, 1)], [('Q0', 'L0')], "I(Q0)", self.basis, param)
        self.CnotA = mc.build_operation([(4, 4)], [('Q0', 'Q1')], "CX(pi,Q0,Q1)", self.basis, param)
        self.CY = mc.build_operation([(4, 4)], [('Q0', 'Q1')], "CY(pi,Q0,Q1)", self.basis, param)
        self.CZ = mc.build_operation([(4, 4)], [('Q0', 'Q1')], "CZ(pi,Q0,Q1)", self.basis, param)
        self.CNOT = mc.build_operation([(4, 4)], [('Q0', 'Q1')], "CNOT(Q0,Q1)", self.basis, param)
        self.CPHASE = mc.build_operation([(4, 4)], [('Q0', 'Q1')], "CPHASE(Q0,Q1)", self.basis, param)
예제 #12
0
 def test_build_operation_raises_on_bad_parameterization(self):
     with self.assertRaises(ValueError):
         mc.build_operation([(4, 4)], [('Q0', 'Q1')], "X(pi,Q0)", "gm", parameterization="FooBar")