Beispiel #1
0
 def test_expectation(self, backend):
     qstate = statevector.computational_zeros(6, backend=backend)
     qstate.apply_circuit([
         Gate('X', [], [0]),
         Gate('CX', [], [0, 3]),
         Gate('H', [], [2]),
     ])
     observable = 1.5 * Observable.sum([
         Observable.Z(0) * 2,
         Observable.Z(1),
         Observable.Z(2) * 2,
         Observable.Z(3),
     ])
     self.assertTrue(np.isclose(qstate.expectation(observable), -3))
Beispiel #2
0
 def test_expectation_single_layer(self, backend):
     qstate = peps.computational_zeros(2, 3, backend=backend)
     qstate.apply_circuit([
         Gate('X', [], [0]),
         Gate('CX', [], [0,3]),
         Gate('H', [], [2]),
     ])
     observable = 1.5 * Observable.sum([
         Observable.Z(0) * 2,
         Observable.Z(1),
         Observable.Z(2) * 2,
         Observable.Z(3),
     ])
     contract_option = peps.SingleLayer(ImplicitRandomizedSVD(rank=2))
     self.assertTrue(backend.isclose(qstate.expectation(observable, contract_option=contract_option), -3))
Beispiel #3
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))
Beispiel #4
0
 def test_expectation_use_cache(self, backend):
     qstate = peps.computational_zeros(2, 3, backend=backend)
     qstate.apply_circuit([
         Gate('X', [], [0]),
         Gate('CX', [], [0, 3]),
         Gate('H', [], [2]),
     ])
     observable = 1.5 * Observable.sum([
         Observable.Z(0) * 2,
         Observable.Z(1),
         Observable.Z(2) * 2,
         Observable.Z(3),
     ])
     self.assertTrue(
         backend.isclose(qstate.expectation(observable, use_cache=True),
                         -3))