@@ -185,6 +185,51 @@ def test_n_edges_scalers_batched(ar_double_sim_state: ts.SimState) -> None:
185185 assert all (v >= 0 for v in result )
186186
187187
188+ @pytest .fixture
189+ def mixed_many_sim_state (
190+ ar_supercell_sim_state : ts .SimState , si_sim_state : ts .SimState
191+ ) -> ts .SimState :
192+ """Batched state of alternating large and small periodic systems."""
193+ return ts .concatenate_states (
194+ [ar_supercell_sim_state , si_sim_state , si_sim_state , ar_supercell_sim_state ],
195+ device = si_sim_state .device ,
196+ )
197+
198+
199+ @pytest .mark .parametrize ("max_atoms_per_chunk" , [1 , 16 , 40 , 10_000 ])
200+ def test_n_edges_scalers_chunked_matches_single_pass (
201+ mixed_many_sim_state : ts .SimState , max_atoms_per_chunk : int
202+ ) -> None :
203+ """Splitting the neighbor-list pass leaves every per-system edge count unchanged."""
204+ state = mixed_many_sim_state
205+ single = _n_edges_scalers (state , cutoff = 5.0 , max_atoms_per_chunk = state .n_atoms )
206+ chunked = _n_edges_scalers (state , cutoff = 5.0 , max_atoms_per_chunk = max_atoms_per_chunk )
207+ assert chunked == single
208+
209+
210+ @pytest .mark .parametrize ("max_atoms_per_chunk" , [1 , 16 , 40 , 10_000 ])
211+ def test_n_edges_scalers_chunk_bounds (
212+ mixed_many_sim_state : ts .SimState ,
213+ max_atoms_per_chunk : int ,
214+ monkeypatch : pytest .MonkeyPatch ,
215+ ) -> None :
216+ """Each pass holds whole systems and exceeds the bound only for a lone system."""
217+ passes : list [tuple [int , int ]] = []
218+ real_nl = ts .autobatching .torchsim_nl
219+
220+ def recording_nl (** kwargs : Any ) -> Any :
221+ passes .append ((int (kwargs ["system_idx" ].max ()) + 1 , kwargs ["positions" ].shape [0 ]))
222+ return real_nl (** kwargs )
223+
224+ monkeypatch .setattr (ts .autobatching , "torchsim_nl" , recording_nl )
225+ state = mixed_many_sim_state
226+ _n_edges_scalers (state , cutoff = 5.0 , max_atoms_per_chunk = max_atoms_per_chunk )
227+
228+ assert sum (n_sys for n_sys , _ in passes ) == state .n_systems
229+ assert sum (n_at for _ , n_at in passes ) == state .n_atoms
230+ assert all (n_at <= max_atoms_per_chunk or n_sys == 1 for n_sys , n_at in passes )
231+
232+
188233@pytest .mark .parametrize ("items" , [[], {}])
189234def test_to_constant_volume_bins_empty_input (
190235 items : list [Any ] | dict [int , float ],
0 commit comments