@@ -396,3 +396,52 @@ def test_double_factorized_t2_alpha_beta_random():
396
396
orbital_rotations [:, 0 , 0 ], orbital_rotations [:, 3 , 0 ].conj (), atol = 1e-8
397
397
)
398
398
# TODO add the rest of the relations
399
+
400
+
401
+ def test_double_factorized_t2_alpha_beta_tol_max_vecs ():
402
+ """Test double-factorized decomposition alpha-beta error threshold and max vecs."""
403
+ mol = gto .Mole ()
404
+ mol .build (
405
+ atom = [["H" , (0 , 0 , 0 )], ["O" , (0 , 0 , 1.1 )]],
406
+ basis = "6-31g" ,
407
+ spin = 1 ,
408
+ symmetry = "Coov" ,
409
+ )
410
+ hartree_fock = scf .ROHF (mol ).run ()
411
+
412
+ ccsd = cc .CCSD (hartree_fock ).run ()
413
+ _ , t2ab , _ = ccsd .t2
414
+ nocc_a , nocc_b , nvrt_a , _ = t2ab .shape
415
+ norb = nocc_a + nvrt_a
416
+
417
+ # test max_vecs
418
+ max_vecs = 25
419
+ diag_coulomb_mats , orbital_rotations = ffsim .linalg .double_factorized_t2_alpha_beta (
420
+ t2ab , max_vecs = max_vecs
421
+ )
422
+ reconstructed = reconstruct_t2_alpha_beta (
423
+ diag_coulomb_mats , orbital_rotations , norb = norb , nocc_a = nocc_a , nocc_b = nocc_b
424
+ )
425
+ assert len (diag_coulomb_mats ) == max_vecs
426
+ np .testing .assert_allclose (reconstructed , t2ab , atol = 1e-4 )
427
+
428
+ # test error threshold
429
+ tol = 1e-3
430
+ diag_coulomb_mats , orbital_rotations = ffsim .linalg .double_factorized_t2_alpha_beta (
431
+ t2ab , tol = tol
432
+ )
433
+ reconstructed = reconstruct_t2_alpha_beta (
434
+ diag_coulomb_mats , orbital_rotations , norb = norb , nocc_a = nocc_a , nocc_b = nocc_b
435
+ )
436
+ assert len (diag_coulomb_mats ) <= 23
437
+ np .testing .assert_allclose (reconstructed , t2ab , atol = tol )
438
+
439
+ # test error threshold and max vecs
440
+ diag_coulomb_mats , orbital_rotations = ffsim .linalg .double_factorized_t2_alpha_beta (
441
+ t2ab , tol = tol , max_vecs = max_vecs
442
+ )
443
+ reconstructed = reconstruct_t2_alpha_beta (
444
+ diag_coulomb_mats , orbital_rotations , norb = norb , nocc_a = nocc_a , nocc_b = nocc_b
445
+ )
446
+ assert len (orbital_rotations ) <= 23
447
+ np .testing .assert_allclose (reconstructed , t2ab , atol = tol )
0 commit comments