def cost(weights, phi, gamma, J, W, epsilon=1e-10):
    return np.trace(
        W
        @ np.linalg.inv(
            J.T @ CFIM(weights, phi, gamma) @ J + np.eye(2) * epsilon
        )
    )
Exemplo n.º 2
0
def shadow_bound(error, observables, failure_rate=0.01):
    """
    Calculate the shadow bound for the Pauli measurement scheme.

    Implements Eq. (S13) from https://arxiv.org/pdf/2002.08953.pdf

    Args:
        error (float): The error on the estimator.
        observables (list) : List of matrices corresponding to the observables we intend to
            measure.
        failure_rate (float): Rate of failure for the bound to hold.

    Returns:
        An integer that gives the number of samples required to satisfy the shadow bound and
        the chunk size required attaining the specified failure rate.
    """
    M = len(observables)
    K = 2 * np.log(2 * M / failure_rate)
    shadow_norm = (
        lambda op: np.linalg.norm(
            op - np.trace(op) / 2 ** int(np.log2(op.shape[0])), ord=np.inf
        )
        ** 2
    )
    N = 34 * max(shadow_norm(o) for o in observables) / error ** 2
    return int(np.ceil(N * K)), int(K)
Exemplo n.º 3
0
def operator_2_norm(R):
    """
    Calculate the operator 2-norm.

    Args:
        R (array): The operator whose norm we want to calculate.

    Returns:
        Scalar corresponding to the norm.
    """
    return np.sqrt(np.trace(R.conjugate().transpose() @ R))
Exemplo n.º 4
0
def TraceDistance(A, B):
    return 0.5 * np.trace(np.absolute(np.add(A, -1*B)))
 def cost(self, weights, inputs_1=None, inputs_2=None):
     ensemble_1 = self.embedding.generate_ensemble(inputs_1, weights)
     ensemble_2 = self.embedding.generate_ensemble(inputs_2, weights)
     observable = self.class_priors[0] * ensemble_1 - self.class_priors[
         1] * ensemble_2
     return 1 - np.real(np.trace(observable @ observable))