예제 #1
0
def ewl_fixed() -> EWL:
    i = sp.I
    pi = sp.pi
    sqrt2 = sp.sqrt(2)
    psi = (Qubit('00') + i * Qubit('11')) / sqrt2
    alice = U_theta_alpha_beta(theta=pi / 2, alpha=pi / 2, beta=0)
    bob = U_theta_alpha_beta(theta=0, alpha=0, beta=0)
    return EWL(psi=psi, C=C, D=D, players=[alice, bob])
예제 #2
0
def ewl_parametrized() -> EWL:
    i = sp.I
    sqrt2 = sp.sqrt(2)
    theta1, alpha1, beta1, theta2, alpha2, beta2 = sp.symbols(
        'theta1 alpha1 beta1 theta2 alpha2 beta2', real=True)
    psi = (Qubit('00') + i * Qubit('11')) / sqrt2
    alice = U_theta_alpha_beta(theta=theta1, alpha=alpha1, beta=beta1)
    bob = U_theta_alpha_beta(theta=theta2, alpha=alpha2, beta=beta2)
    return EWL(psi=psi, C=C, D=D, players=[alice, bob])
예제 #3
0
파일: test_ewl.py 프로젝트: tomekzaw/ewl
def test_fix(ewl_parametrized_00_11: EWL, ewl: EWL):
    ewl_fixed = ewl_parametrized_00_11.fix(theta1=pi / 2,
                                           alpha1=pi / 2,
                                           beta1=0,
                                           theta2=0,
                                           alpha2=0,
                                           beta2=0)
    assert ewl_fixed.psi == ewl.psi
    assert ewl_fixed.players[0] == ewl.players[0]
    assert ewl_fixed.players[1] == ewl.players[1]
예제 #4
0
파일: test_ewl.py 프로젝트: tomekzaw/ewl
def test_amplitudes_parametrized(ewl_parametrized_00_11: EWL):
    assert ewl_parametrized_00_11.amplitudes() == Matrix([
        cos(alpha1 + alpha2) * cos(theta1 / 2) * cos(theta2 / 2) +
        sin(beta1 + beta2) * sin(theta1 / 2) * sin(theta2 / 2),
        sin(alpha2 - beta1) * sin(theta1 / 2) * cos(theta2 / 2) +
        cos(alpha1 - beta2) * cos(theta1 / 2) * sin(theta2 / 2),
        cos(alpha2 - beta1) * sin(theta1 / 2) * cos(theta2 / 2) +
        sin(alpha1 - beta2) * cos(theta1 / 2) * sin(theta2 / 2),
        -sin(alpha1 + alpha2) * cos(theta1 / 2) * cos(theta2 / 2) +
        cos(beta1 + beta2) * sin(theta1 / 2) * sin(theta2 / 2),
    ])
예제 #5
0
파일: test_ewl.py 프로젝트: tomekzaw/ewl
def test_probs_parametrized(ewl_parametrized_01_10: EWL):
    assert ewl_parametrized_01_10.probs() == Matrix([
        (cos(alpha1 - alpha2) * cos(theta1 / 2) * cos(theta2 / 2) +
         sin(beta1 - beta2) * sin(theta1 / 2) * sin(theta2 / 2))**2,
        (sin(alpha2 + beta1) * sin(theta1 / 2) * cos(theta2 / 2) -
         cos(alpha1 + beta2) * cos(theta1 / 2) * sin(theta2 / 2))**2,
        (cos(alpha2 + beta1) * sin(theta1 / 2) * cos(theta2 / 2) +
         sin(alpha1 + beta2) * cos(theta1 / 2) * sin(theta2 / 2))**2,
        (-sin(alpha1 - alpha2) * cos(theta1 / 2) * cos(theta2 / 2) +
         cos(beta1 - beta2) * sin(theta1 / 2) * sin(theta2 / 2))**2,
    ])
예제 #6
0
def make_Quantum_Prisoners_Dilemma_Frackiewicz_Pykacz() -> EWL:
    """
    Quantum Prisoner's Dilemma with Frąckiewicz-Pykacz parametrization
    from "Quantum games with strategies induced by basis change rules" by Piotr Frąckiewicz and Jarosław Pykacz
    (https://www.researchgate.net/publication/317754594_Quantum_Games_with_Strategies_Induced_by_Basis_Change_Rules/fulltext/59601fed0f7e9b8194fc0d96/Quantum-Games-with-Strategies-Induced-by-Basis-Change-Rules.pdf)
    """
    alice = U_Frackiewicz_Pykacz(theta=theta_A, phi=phi_A)
    bob = U_Frackiewicz_Pykacz(theta=theta_B, phi=phi_B)

    C = U_Frackiewicz_Pykacz(theta=0, phi=0)
    D = U_Frackiewicz_Pykacz(theta=pi, phi=0)

    return EWL(psi=psi, C=C, D=D, players=[alice, bob], payoff_matrix=payoff_matrix)
예제 #7
0
def make_Quantum_Prisoners_Dilemma_Szopa() -> EWL:
    """
    Quantum Prisoner's Dilemma with full SU(2) parametrization
    from "Dlaczego w dylemat więźnia warto grać kwantowo?" by Marek Szopa
    (https://www.ue.katowice.pl/fileadmin/_migrated/content_uploads/11_M.Szopa__Dlaczego_w_dylemat_wieznia....pdf)
    """
    alice = U_theta_phi_alpha(theta=theta_A, phi=phi_A, alpha=alpha_A)
    bob = U_theta_phi_alpha(theta=theta_B, phi=phi_B, alpha=alpha_B)

    C = U_theta_phi_alpha(theta=0, phi=0, alpha=0)
    D = U_theta_phi_alpha(theta=pi, phi=0, alpha=0)

    return EWL(psi=psi, C=C, D=D, players=[alice, bob], payoff_matrix=payoff_matrix)
예제 #8
0
def make_Quantum_Prisoners_Dilemma_Chen() -> EWL:
    """
    Quantum Prisoner's Dilemma with full SU(2) parametrization
    from "How Well Do People Play a Quantum Prisoner's Dilemma?" by Kay-Yut Chen and Tad Hogg
    (https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.73.1344&rep=rep1&type=pdf)
    """
    alice = U_theta_phi_alpha(theta=theta_A, phi=phi_A, alpha=alpha_A)
    bob = U_theta_phi_alpha(theta=theta_B, phi=phi_B, alpha=alpha_B)

    C = U_theta_phi_alpha(theta=0, phi=0, alpha=0)
    D = U_theta_phi_alpha(theta=pi, phi=0, alpha=pi / 2)

    return EWL(psi=psi, C=C, D=D, players=[alice, bob], payoff_matrix=payoff_matrix)
예제 #9
0
def make_Quantum_Prisoners_Dilemma_Eisert_Wilkens_Lewenstein() -> EWL:
    """
    Quantum Prisoner's Dilemma with original EWL parametrization
    from "Quantum Games and Quantum Strategies" by Jens Eisert, Martin Wilkens and Maciej Lewenstein
    (https://arxiv.org/pdf/quant-ph/9806088.pdf)
    """
    alice = U_Eisert_Wilkens_Lewenstein(theta=theta_A, phi=phi_A)
    bob = U_Eisert_Wilkens_Lewenstein(theta=theta_B, phi=phi_B)

    C = U_Eisert_Wilkens_Lewenstein(theta=0, phi=0)
    D = U_Eisert_Wilkens_Lewenstein(theta=pi, phi=0)

    return EWL(psi=psi, C=C, D=D, players=[alice, bob], payoff_matrix=payoff_matrix)
예제 #10
0
def plot_payoff_function(ewl: EWL, *, player: Optional[int],
                         x: sp.Symbol, x_min, x_max, y: sp.Symbol, y_min, y_max, n: int = 20,
                         figsize=(8, 8), cmap=plt.cm.coolwarm, **kwargs) -> plt.Figure:
    f = sp.lambdify([x, y], ewl.payoff_function(player=player))

    xs = np.linspace(x_min, x_max, n)
    ys = np.linspace(y_min, y_max, n)
    X, Y = np.meshgrid(xs, ys)
    Z = f(X, Y)

    fig = plt.figure(figsize=figsize)
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_surface(X, Y, Z, cmap=cmap, antialiased=True)
    ax.set(xlim=(x_min, x_max), ylim=(y_min, y_max),
           xlabel=f'${sp.latex(x)}$', ylabel=f'${sp.latex(y)}$',
           zlabel='expected payoff', **kwargs)
    return fig
예제 #11
0
def check_classical_payoffs(ewl: EWL) -> None:
    # from Fig. 1 in https://arxiv.org/pdf/quant-ph/0004076.pdf
    assert ewl.play(ewl.C, ewl.C).payoffs() == (3, 3)
    assert ewl.play(ewl.C, ewl.D).payoffs() == (0, 5)
    assert ewl.play(ewl.D, ewl.C).payoffs() == (5, 0)
    assert ewl.play(ewl.D, ewl.D).payoffs() == (1, 1)
예제 #12
0
파일: test_ewl.py 프로젝트: tomekzaw/ewl
def test_calculate_probs(ewl: EWL):
    assert ewl.probs() == Matrix([0, 0, 1 / 2, 1 / 2])
예제 #13
0
파일: test_ewl.py 프로젝트: tomekzaw/ewl
def ewl_parametrized_01_10() -> EWL:
    psi = (Qubit('01') + i * Qubit('10')) / sqrt2
    alice = U_theta_alpha_beta(theta=theta1, alpha=alpha1, beta=beta1)
    bob = U_theta_alpha_beta(theta=theta2, alpha=alpha2, beta=beta2)
    return EWL(psi=psi, C=C, D=D, players=[alice, bob])
예제 #14
0
파일: test_ewl.py 프로젝트: tomekzaw/ewl
def ewl() -> EWL:
    psi = (Qubit('00') + i * Qubit('11')) / sqrt2
    alice = U_theta_alpha_beta(theta=pi / 2, alpha=pi / 2, beta=0)
    bob = U_theta_alpha_beta(theta=0, alpha=0, beta=0)
    return EWL(psi=psi, C=C, D=D, players=[alice, bob])