Ejemplo n.º 1
0
 def test_force_solve(self, dimension, generator):
     """
     Metrics: checks that special cases for dnorm agree with SDP solutions.
     """
     A, B = generator(dimension), generator(dimension)
     assert (dnorm(A, B, force_solve=False) == pytest.approx(dnorm(
         A, B, force_solve=True),
                                                             abs=1e-5))
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def test_sparse_against_dense_adc(self, variable):
     """
     Test sparse versus dense dnorm calculation for a sample of
     amplitude-damping channels.
     """
     # Choi matrix for identity channel on 1 qubit
     A = kraus_to_choi([qeye(2)])
     B = adc_choi(variable)
     dense = dnorm(A, B, force_solve=True, sparse=False)
     sparse = dnorm(A, B, force_solve=True, sparse=True)
     assert dense == pytest.approx(sparse, abs=1e-7)
Ejemplo n.º 4
0
 def test_qubit_known_cases(self, variable, expected, generator, sparse):
     """
     Test cases based on comparisons to pre-existing dnorm implementations.
     In particular, the targets for the following test cases were generated
     using QuantumUtils for MATLAB (https://goo.gl/oWXhO9).
     """
     id_chan = to_choi(qeye(2))
     channel = generator(variable)
     assert (dnorm(channel, id_chan,
                   sparse=sparse) == pytest.approx(expected, abs=1e-7))
Ejemplo n.º 5
0
 def test_qubit_simple_known_cases(self, sparse):
     """Check agreement for known qubit channels."""
     id_chan = to_choi(qeye(2))
     X_chan = to_choi(sigmax())
     depol = to_choi(
         Qobj(
             qeye(4),
             dims=[[[2], [2]], [[2], [2]]],
             superrep='chi',
         ))
     # We need to restrict the number of iterations for things on the
     # boundary, such as perfectly distinguishable channels.
     assert (dnorm(id_chan, X_chan,
                   sparse=sparse) == pytest.approx(2, abs=1e-7))
     assert (dnorm(id_chan, depol,
                   sparse=sparse) == pytest.approx(1.5, abs=1e-7))
     # Finally, we add a known case from Johnston's QETLAB documentation,
     #   || Phi - I ||_♢,
     # where Phi(X) = UXU⁺ and U = [[1, 1], [-1, 1]] / sqrt(2).
     U = np.sqrt(0.5) * Qobj([[1, 1], [-1, 1]])
     assert (dnorm(U, qeye(2), sparse=sparse) == pytest.approx(np.sqrt(2),
                                                               abs=1e-7))
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
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