def test_reductions_pmps(nr_sites, local_dim, rank, max_red_width, rgen): pmps = factory.random_mpa(nr_sites, (local_dim, local_dim), rank, dtype=np.complex_, randstate=rgen) op = mm.pmps_to_mpo(pmps).to_array_global() start, stop, red = _get_reductions(mm.reductions_pmps, pmps, max_red_width) for start, stop, reduced_pmps in zip(start, stop, red): # Check that startsites/stopsites and width produce the same result: reduced_pmps2 = tuple(mm.reductions_pmps(pmps, stop - start))[start] # NB: reduced_pmps and reduced_pmps2 are in general not equal, # but red and red2 are. red = mm.pmps_to_mpo(reduced_pmps).to_array_global() red2 = mm.pmps_to_mpo(reduced_pmps2).to_array_global() assert_array_almost_equal(red, red2) traceout = tuple(range(start)) + tuple(range(stop, nr_sites)) red_from_op = utils.partial_trace(op, traceout) assert_array_almost_equal(red, red_from_op, err_msg="not equal at {}:{}".format( start, stop)) # check default argument for startsite assert len(list(mm.reductions_pmps(pmps, max_red_width))) \ == nr_sites - max_red_width + 1
def test_pmps_reduction_dm_to_array(nr_sites, local_dim, rank, keep, rgen): pmps = factory.random_mpa(nr_sites, (local_dim, local_dim), rank, dtype=np.complex_, randstate=rgen) rho = mm.pmps_to_mpo(pmps).to_array_global() traceout = [pos for pos in range(nr_sites) if pos not in keep] red = utils.partial_trace(rho, traceout) pmps_red = mm.pmps_reduction(pmps, keep) red2 = mm.pmps_dm_to_array(pmps_red, True) assert_array_almost_equal(red2, red)
def test_pmps_to_mpo(nr_sites, local_dim, rank, rgen): if (nr_sites % 2) != 0: return nr_sites = nr_sites // 2 pmps = factory.random_mpa(nr_sites, (local_dim, local_dim), rank, dtype=np.complex_, randstate=rgen) rho_mp = mm.pmps_to_mpo(pmps).to_array_global() # Local form is what we will use: One system site, one ancilla site, etc purification = pmps.to_array() # Convert to a density matrix purification = np.outer(purification, purification.conj()) purification = purification.reshape((local_dim,) * (2 * 2 * nr_sites)) # Trace out the ancilla sites traceout = tuple(range(1, 2 * nr_sites, 2)) rho_np = utils.partial_trace(purification, traceout) # Here, we need global form assert_array_almost_equal(rho_mp, rho_np)
def test_reductions_mpo(nr_sites, local_dim, rank, max_red_width, rgen): mpo = factory.random_mpo(nr_sites, local_dim, rank, randstate=rgen) op = mpo.to_array_global() start, stop, red = _get_reductions(mm.reductions_mpo, mpo, max_red_width) for start, stop, reduced_mpo in zip(start, stop, red): # Check that startsites/stopsites and width produce the same result: reduced_mpo2 = tuple(mm.reductions_mpo(mpo, stop - start))[start] assert_array_almost_equal(reduced_mpo.to_array(), reduced_mpo2.to_array()) traceout = tuple(range(start)) + tuple(range(stop, nr_sites)) red_from_op = utils.partial_trace(op, traceout) assert_array_almost_equal( reduced_mpo.to_array_global(), red_from_op, err_msg="not equal at {}:{}".format(start, stop)) # check default argument for startsite assert len(list(mm.reductions_mpo(mpo, max_red_width))) \ == nr_sites - max_red_width + 1
def test_reductions_pmps(nr_sites, local_dim, rank, max_red_width, rgen): pmps = factory.random_mpa(nr_sites, (local_dim, local_dim), rank, dtype=np.complex_, randstate=rgen) op = mm.pmps_to_mpo(pmps).to_array_global() start, stop, red = _get_reductions(mm.reductions_pmps, pmps, max_red_width) for start, stop, reduced_pmps in zip(start, stop, red): # Check that startsites/stopsites and width produce the same result: reduced_pmps2 = tuple(mm.reductions_pmps(pmps, stop - start))[start] # NB: reduced_pmps and reduced_pmps2 are in general not equal, # but red and red2 are. red = mm.pmps_to_mpo(reduced_pmps).to_array_global() red2 = mm.pmps_to_mpo(reduced_pmps2).to_array_global() assert_array_almost_equal(red, red2) traceout = tuple(range(start)) + tuple(range(stop, nr_sites)) red_from_op = utils.partial_trace(op, traceout) assert_array_almost_equal( red, red_from_op, err_msg="not equal at {}:{}".format(start, stop)) # check default argument for startsite assert len(list(mm.reductions_pmps(pmps, max_red_width))) \ == nr_sites - max_red_width + 1