Beispiel #1
0
 def test_amplitude_nonlocal(self, backend):
     update_options = [
         None,
         peps.DirectUpdate(ImplicitRandomizedSVD(rank=2)),
         peps.QRUpdate(rank=2),
         peps.LocalGramQRUpdate(rank=2),
         peps.LocalGramQRSVDUpdate(rank=2),
     ]
     for option in update_options:
         with self.subTest(update_option=option):
             qstate = peps.computational_zeros(2, 3, backend=backend)
             qstate.apply_circuit([
                 Gate('X', [], [0]),
                 Gate('H', [], [1]),
                 Gate('CX', [], [0, 5]),
                 Gate('CX', [], [1, 3]),
                 Gate('S', [], [1]),
             ],
                                  update_option=option)
             self.assertTrue(
                 np.isclose(qstate.amplitude([1, 0, 0, 0, 0, 1]),
                            1 / np.sqrt(2)))
             self.assertTrue(
                 np.isclose(qstate.amplitude([1, 1, 0, 1, 0, 1]),
                            1j / np.sqrt(2)))
Beispiel #2
0
 def test_inner_approx(self, backend):
     psi = peps.computational_zeros(2, 3, backend=backend)
     psi.apply_circuit([
         Gate('H', [], [0]),
         Gate('CX', [], [0,3]),
         Gate('H', [], [3]),
     ], update_option=peps.DirectUpdate(ImplicitRandomizedSVD(rank=2)))
     phi = peps.computational_zeros(2, 3, backend=backend)
     contract_option = peps.BMPS(ReducedSVD(rank=2))
     self.assertTrue(backend.isclose(psi.inner(phi, contract_option), 0.5))
Beispiel #3
0
 def test_amplitude_approx(self, backend):
     qstate = peps.computational_zeros(2, 3, backend=backend)
     qstate.apply_circuit([
         Gate('X', [], [0]),
         Gate('H', [], [1]),
         Gate('CX', [], [0,3]),
         Gate('CX', [], [1,4]),
         Gate('S', [], [1]),
     ], update_option=peps.DirectUpdate(ImplicitRandomizedSVD(rank=2)))
     contract_option = peps.BMPS(ReducedSVD(rank=2))
     self.assertTrue(backend.isclose(qstate.amplitude([1,0,0,1,0,0], contract_option), 1/np.sqrt(2)))
     self.assertTrue(backend.isclose(qstate.amplitude([1,1,0,1,1,0], contract_option), 1j/np.sqrt(2)))
Beispiel #4
0
 def test_expectation_use_cache_approx(self, backend):
     qstate = peps.computational_zeros(2, 3, backend=backend)
     qstate.apply_circuit([
         Gate('X', [], [0]),
         Gate('CX', [], [0,3]),
         Gate('H', [], [2]),
     ], update_option=peps.DirectUpdate(ImplicitRandomizedSVD(rank=2)))
     observable = 1.5 * Observable.sum([
         Observable.Z(0) * 2,
         Observable.Z(1),
         Observable.Z(2) * 2,
         Observable.Z(3),
     ])
     contract_option = peps.BMPS(ReducedSVD(rank=2))
     self.assertTrue(backend.isclose(qstate.expectation(observable, use_cache=True, contract_option=contract_option), -3))