예제 #1
0
def test_rand_super_bcsz_cptp():
    """
    Random Qobjs: Tests that BCSZ-random superoperators are CPTP.
    """
    random_qobj = rand_super_bcsz(5)
    assert random_qobj.issuper
    assert random_qobj.iscptp
예제 #2
0
def entropy_stationary(steps, d):
    for _ in range(steps):
        phi = q.rand_super_bcsz(int(np.sqrt(d)))
        vals, vecs = np.linalg.eig(phi.data.todense())
        idx = np.where(np.isclose(vals, 1.))[0]
        rho = unres(vecs[:, idx])
        rho = q.Qobj(rho/np.trace(rho))
        q.entropy_vn(rho)
예제 #3
0
 def test_sparse_against_dense_random(self, dimension):
     """
     Test sparse versus dense dnorm calculation for random superoperators.
     """
     A = rand_super_bcsz(dimension)
     dense_run_result = dnorm(A, force_solve=True, sparse=False)
     sparse_run_result = dnorm(A, force_solve=True, sparse=True)
     assert dense_run_result == pytest.approx(sparse_run_result, abs=1e-7)
예제 #4
0
def entropy_stationary(steps, d):
    for _ in range(steps):
        phi = q.rand_super_bcsz(int(np.sqrt(d)))
        vals, vecs = np.linalg.eig(phi.data.todense())
        idx = np.where(np.isclose(vals, 1.))[0]
        rho = unres(vecs[:, idx])
        rho = q.Qobj(rho / np.trace(rho))
        q.entropy_vn(rho)
예제 #5
0
 def _sample(self):
     # Since the dense representation of S is a matrix and not an array,
     # flattening in FORTRAN order gives MATLAB-like behavior (implicitly
     # two-index). Thus, we need to index away the first axis.
     return np.real(
         conjugate(
             self._basis,
             qt.rand_super_bcsz(self._dims,
                                enforce_tp=self._enforce_tp,
                                rank=self._rank).data.todense().view(
                                    np.ndarray)))[1:, :].flatten(order='F')
예제 #6
0
 def _sample(self):
     # Since the dense representation of S is a matrix and not an array,
     # flattening in FORTRAN order gives MATLAB-like behavior (implicitly
     # two-index). Thus, we need to index away the first axis.
     return np.real(
         conjugate(self._basis,
             qt.rand_super_bcsz(
                 self._dims, enforce_tp=self._enforce_tp, rank=self._rank
             ).data.todense().view(np.ndarray)
         )
     )[1:, :].flatten(order='F')
예제 #7
0
 def test_cptp(self, dimension, sparse):
     """Check that the diamond norm is one for CPTP maps."""
     A = rand_super_bcsz(dimension)
     assert A.iscptp
     assert dnorm(A, sparse=sparse) == pytest.approx(1, abs=1e-7)
예제 #8
0
 def test_qubit_triangle(self, dimension):
     """Check that dnorm(A + B) <= dnorm(A) + dnorm(B)."""
     A = rand_super_bcsz(dimension)
     B = rand_super_bcsz(dimension)
     assert dnorm(A + B) <= dnorm(A) + dnorm(B) + 1e-7
예제 #9
0
 def test_qubit_scalar(self, dimension):
     """dnorm(a * A) == a * dnorm(A) for scalar a, qobj A."""
     a = np.random.random()
     A = rand_super_bcsz(dimension)
     B = rand_super_bcsz(dimension)
     assert dnorm(a * A, a * B) == pytest.approx(a * dnorm(A, B), abs=1e-7)
예제 #10
0
 def test_bounded(self, dimension, sparse):
     """dnorm(A - B) in [0, 2] for random superops A, B."""
     tol = 1e-7
     A, B = rand_super_bcsz(dimension), rand_super_bcsz(dimension)
     assert -tol <= dnorm(A, B, sparse=sparse) <= 2 + tol
예제 #11
0
 def test_bounded(self, n_qubits):
     tol = 1e-7
     operator = rand_super_bcsz(2**n_qubits)
     assert -tol <= unitarity(operator) <= 1 + tol
예제 #12
0
 def test_bounded(self, dimension):
     tol = 1e-7
     channel = rand_super_bcsz(dimension)
     assert -tol <= average_gate_fidelity(channel) <= 1 + tol
예제 #13
0
def random_channel(steps, d):
    for _ in range(steps):
        q.rand_super_bcsz(int(np.sqrt(d)))
예제 #14
0
 def _sample_dm(self):
     return qt.to_choi(
         qt.rand_super_bcsz(self._hdim, self._enforce_tp, self._rank)
     ).unit()
예제 #15
0
def random_channel(steps, d):
    for _ in range(steps):
        q.rand_super_bcsz(int(np.sqrt(d)))