コード例 #1
0
ファイル: test_samples.py プロジェクト: XanaduAI/thewalrus
def test_seed():
    """Tests that seed method does reset the random number generators"""
    n_samples = 10
    mean_n = 1.0
    r = np.arcsinh(np.sqrt(mean_n))
    V = np.array([[np.exp(2 * r), 0.0], [0.0, np.exp(-2 * r)]])
    seed(137)
    first_sample = hafnian_sample_state(V, n_samples)
    second_sample = hafnian_sample_state(V, n_samples)
    seed(137)
    first_sample_p = hafnian_sample_state(V, n_samples)
    second_sample_p = hafnian_sample_state(V, n_samples)
    assert np.array_equal(first_sample, first_sample_p)
    assert np.array_equal(second_sample, second_sample_p)
コード例 #2
0
ファイル: test_samples.py プロジェクト: XanaduAI/thewalrus
    hafnian_sample_state,
    hafnian_sample_graph,
    torontonian_sample_state,
    torontonian_sample_graph,
    hafnian_sample_classical_state,
    torontonian_sample_classical_state,
    seed,
    photon_number_sampler,
    generate_hafnian_sample,
    generate_torontonian_sample,
    hafnian_sample_graph_rank_one,
)
from thewalrus.quantum import gen_Qmat_from_graph, density_matrix_element, probabilities
from thewalrus.symplectic import two_mode_squeezing

seed(137)

rel_tol = 3.0
abs_tol = 1.0e-10


def TMS_cov(r, phi, hbar=2):
    """returns the covariance matrix of a TMS state"""

    S = two_mode_squeezing(r, phi)

    return S @ S.T * hbar / 2


class TestHafnianSampling:
    """Tests for hafnian sampling"""