def __init__(self, fiducial_distribution, mean):
        super(GADFLIDistribution, self).__init__(fiducial_distribution.basis)
        self._fid = fiducial_distribution
        mean = (
            qt.to_choi(mean).unit()
            if mean.type == 'super' and not mean.superrep == 'choi' else
            mean
        )
        self._mean = mean

        alpha = 1
        lambda_min = min(mean.eigenenergies())
        if lambda_min < 0:
            raise ValueError("Negative eigenvalue {} in informative mean.".format(lambda_min))
        d = self.dim
        beta = (
            1 / (d * lambda_min - 1) - 1
        ) if lambda_min > 0.5 else (
            (d * lambda_min) / (1 - d * lambda_min)
        )
        if beta < 0:
            raise ValueError("Beta < 0 for informative mean.")
        self._alpha = alpha
        self._beta = beta

        eye = qt.qeye(self._dim).unit()
        eye.dims = mean.dims
        self._rho_star = (alpha + beta) / alpha * (
            mean - (beta) / (alpha + beta) * eye.unit()
        )
Exemple #2
0
def verify_CPTP(U):
    # args: U(Qobj): superoperator or unitary
    # returns: trace dist of the partial trace that should be the identity, i.e. trace dist should be zero for TP maps
    choi = qtp.to_choi(U)
    candidate_identity = choi.ptrace([0, 1])  # 3 since we have a qutrit
    ptrace = qtp.tracedist(candidate_identity,
                           qtp.tensor(qtp.qeye(3), qtp.qeye(3)))
    return ptrace
Exemple #3
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))
Exemple #4
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))
Exemple #5
0
def had_mixture(x):
    id_chan = to_choi(qeye(2))
    S_eye = to_super(id_chan)
    S_H = to_super(hadamard_transform())
    return (1 - x) * S_eye + x * S_H
 def _sample_dm(self):
     return qt.to_choi(
         qt.rand_super_bcsz(self._hdim, self._enforce_tp, self._rank)
     ).unit()