Coverage for tests/test_LJ_cpu.py: 5%
79 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1import pytest
3@pytest.mark.gamdpy_cpu
4def test_cpu(nconf='1', integrator_type='NVE', potential='KABLJ'):
5 import os
6 import sys
7 sys.path.append(os.getcwd())
8 os.environ["NUMBA_ENABLE_CUDASIM"] = "1"
9 os.environ["NUMBA_DISABLE_JIT"] = "1"
10 os.environ["NUMBA_CUDA_DEBUGINFO"] = "1"
11 import gamdpy as gp
12 import numpy as np
13 import numba
14 from numba import cuda
15 print(f"Testing configuration={nconf}, integrator_type={integrator_type} and potential={potential}, numba version: {numba.__version__}")
17 # Generate configurations with a FCC lattice
18 # NOTE: if nx,ny,nz are lower than 4,2,4 fails (in any order)
19 # NOTE: some combinations systematically fails as 4,5,4
20 configuration = gp.Configuration(D=3)
21 if nconf == '1':
22 configuration.make_lattice(gp.unit_cells.FCC, cells=[4, 4, 2], rho=0.8442)
23 configuration['m'] = 1.0
24 configuration.randomize_velocities(temperature=1.44)
25 elif nconf == '2':
26 configuration.make_lattice(gp.unit_cells.FCC, cells=[4, 3, 4], rho=1.2000)
27 configuration['m'] = 1.0
28 configuration.randomize_velocities(temperature=0.44)
29 elif nconf == '3':
30 configuration.make_lattice(gp.unit_cells.FCC, cells=[4, 4, 4], rho=0.8442)
31 configuration['m'] = 1.0
32 configuration.randomize_velocities(temperature=2.44)
33 else:
34 print("wrong input")
35 exit()
36 isinstance(configuration, gp.Configuration)
38 # Make pair potentials
39 if potential == 'LJ':
40 pairfunc = gp.apply_shifted_force_cutoff(gp.LJ_12_6_sigma_epsilon)
41 sig, eps, cut = 1.0, 1.0, 2.5
42 pairpot = gp.PairPotential(pairfunc, params=[sig, eps, cut], max_num_nbs=1000)
43 elif potential == 'KABLJ':
44 pairfunc = gp.apply_shifted_potential_cutoff(gp.LJ_12_6_sigma_epsilon)
45 sig = [[1.00, 0.80],
46 [0.80, 0.88]]
47 eps = [[1.00, 1.50],
48 [1.50, 0.50]]
49 cut = np.array(sig)*2.5
50 pairpot = gp.PairPotential(pairfunc, params=[sig, eps, cut], max_num_nbs=1000)
51 else:
52 print("wrong input")
53 exit()
54 isinstance(pairpot, gp.PairPotential)
56 # Make integrators
57 dt = 0.005 # timestep
58 temperature = 0.7 # Not used for NVE
59 pressure = 1.2 # Not used for NV*
61 if integrator_type == 'NVE':
62 integrator = gp.integrators.NVE(dt=dt)
63 assert isinstance(integrator, gp.integrators.NVE)
64 elif integrator_type == 'NVT':
65 integrator = gp.integrators.NVT(temperature=temperature, tau=0.2, dt=dt)
66 assert isinstance(integrator, gp.integrators.NVT)
67 elif integrator_type == 'NPT_Atomic':
68 integrator = gp.integrators.NPT_Atomic(temperature=temperature, tau=0.4, pressure=pressure, tau_p=20, dt=dt)
69 assert isinstance(integrator, gp.integrators.NPT_Atomic)
70 elif integrator_type == 'NVT_Langevin':
71 integrator = gp.integrators.NVT_Langevin(temperature=temperature, alpha=0.2, dt=dt, seed=2023)
72 assert isinstance(integrator, gp.integrators.NVT_Langevin)
73 elif integrator_type == 'NPT_Langevin':
74 integrator = gp.integrators.NPT_Langevin(temperature=temperature, pressure=pressure,
75 alpha=0.1, alpha_baro=0.0001, mass_baro=0.0001,
76 volume_velocity=0.0, barostatModeISO = True , boxFlucCoord = 2,
77 dt=dt, seed=2023)
78 assert isinstance(integrator, gp.integrators.NPT_Langevin)
79 else:
80 print("wrong input")
81 exit()
83 if configuration.N > 128:
84 steps_in_kernel_test = 0
85 else:
86 steps_in_kernel_test = 1
88 runtime_actions = [gp.TrajectorySaver(),
89 gp.ScalarSaver(),
90 gp.MomentumReset(100)]
92 ev = gp.Evaluator(configuration, pairpot)
93 sim = gp.Simulation(configuration, pairpot, integrator, runtime_actions,
94 num_timeblocks=64, steps_per_timeblock=1024, storage='memory',
95 steps_in_kernel_test=steps_in_kernel_test)
96 assert isinstance(sim, gp.Simulation)
97 cuda.simulator.reset()
98 del os.environ["NUMBA_ENABLE_CUDASIM"]
99 del os.environ["NUMBA_DISABLE_JIT"]
100 del os.environ["NUMBA_CUDA_DEBUGINFO"]
102if __name__ == '__main__':
103 for configuration in ['1', '2', '3']:
104 for integrator in ['NVE', 'NVT', 'NPT_Atomic']:
105 for potential in ['LJ', 'KABLJ']:
106 test_cpu(nconf=configuration, integrator_type=integrator, potential=potential)