Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions wfns/backend/test/test_math_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,24 @@ def test_unitary_matrix():
assert np.allclose(unitary_matrix(np.zeros(3)), np.identity(3))
assert np.allclose(unitary_matrix(np.zeros(6)), np.identity(4))

# FIXME: tests fail for some random numbers
np.random.seed(424242)

antiherm_elements = np.random.rand(1)
# test with "randomly" generated numbers
antiherm_elements = np.array([0.49683116])
matrix = unitary_matrix(antiherm_elements, norm_threshold=1e-8)
assert np.allclose(matrix.dot(matrix.T), np.identity(2))
assert np.allclose(matrix.T.dot(matrix), np.identity(2))

antiherm_elements = np.random.rand(6)
antiherm_elements = np.array([0.49683116, 0.74836718, 0.32115768,
0.42125731, 0.75843053, 0.15089059])
matrix = unitary_matrix(antiherm_elements, norm_threshold=1e-8)
assert np.allclose(matrix.dot(matrix.T), np.identity(4))
assert np.allclose(matrix.T.dot(matrix), np.identity(4))

antiherm_elements = np.random.rand(6) * 10
antiherm_elements = np.array([0.49683116, 0.74836718, 0.32115768,
0.42125731, 0.75843053, 0.15089059]) * 10
matrix = unitary_matrix(antiherm_elements, norm_threshold=1e-8)
assert np.allclose(matrix.dot(matrix.T), np.identity(4))
assert np.allclose(matrix.T.dot(matrix), np.identity(4))

antiherm_elements = np.random.rand(6) * 14
antiherm_elements = np.array([0.49683116, 0.74836718, 0.32115768,
0.42125731, 0.75843053, 0.15089059]) * 14
assert_raises(ValueError, unitary_matrix, antiherm_elements)
17 changes: 15 additions & 2 deletions wfns/ham/test/test_generalized_chemical.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,21 @@ def test_integrate_wfn_sd_h4_sto6g():
nspin = 8
sds = sd_list(4, 4, num_limit=None, exc_orders=None)
wfn = CIWavefunction(nelec, nspin, sd_vec=sds)
np.random.seed(1000)
wfn.assign_params(np.random.rand(len(sds)))

# create "random" parameters
params = np.array([0.31631948, 0.40947866, 0.68708901, 0.70223529, 0.44619794, 0.42032208,
0.80263059, 0.53861757, 0.92350049, 0.06190754, 0.36758345, 0.97039877,
0.69910395, 0.89097558, 0.25355272, 0.72552711, 0.20349443, 0.53751182,
0.236943, 0.43649216, 0.79802451, 0.30840916, 0.62151663, 0.43964812,
0.91332371, 0.6586859, 0.65363145, 0.35845778, 0.52294157, 0.04508731,
0.09430966, 0.92161219, 0.0730445, 0.92941735, 0.71701514, 0.62231055,
0.75498971, 0.14166991, 0.7938222, 0.72540315, 0.54143928, 0.48258449,
0.47647761, 0.44603283, 0.81607006, 0.27435149, 0.06196201, 0.96029634,
0.45811813, 0.75789206, 0.6811586, 0.54177793, 0.13283249, 0.25320563,
0.44385559, 0.55874991, 0.81386435, 0.31782834, 0.39704509, 0.89016825,
0.82541621, 0.10668708, 0.15977588, 0.65121931, 0.56906421, 0.98408367,
0.74915901, 0.80239963, 0.22830988, 0.51871345])
wfn.assign_params(params)

restricted_one_int = np.load(find_datafile('test/h4_square_hf_sto6g_oneint.npy'))
restricted_two_int = np.load(find_datafile('test/h4_square_hf_sto6g_twoint.npy'))
Expand Down
3 changes: 3 additions & 0 deletions wfns/wfn/ci/test/test_doci.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def test_doci_h4_hf_sto6g():

obj = OneSidedEnergy(doci, ham, param_selection=[(doci, np.ones(doci.nparams, dtype=bool)),
(ham, np.ones(ham.nparams, dtype=bool))])

# FIXME: random number generator in cma must be seeded to ensure that the same energy is found
# from the optimization (but this is system dependent)
results = cma(obj, sigma0=0.01, options={'ftarget': None, 'timeout': np.inf, 'tolfun': 1e-11,
'verb_filenameprefix': 'outcmaes', 'verb_log': 0})
energy = results['function']
Expand Down
4 changes: 4 additions & 0 deletions wfns/wfn/geminal/test/test_rank2_approx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def test_rank2_geminal_params_from_full():
atol=0.1, rtol=0)


# FIXME: THIS TEST FAILS SOMETIMES. The random seed cannot be removed because random numbers are
# generated within the property template_params and is immediately processed afterwards
# i.e. we cannot manually insert the "random" numbers that was chosen beforehand.
# This may be solved by simplifying/refactoring the template_params property
@np.testing.dec.skipif(True, 'Test does not always pass (depends on random noise).')
def test_rank2_geminal_template_params():
"""Test RankTwoGeminal.template_params."""
Expand Down