From 38749727d2ad32ec4bdc6f4344dc7152b0094618 Mon Sep 17 00:00:00 2001 From: Nico Date: Wed, 4 Dec 2024 17:02:31 +0100 Subject: [PATCH 01/12] replace set_default_type --- docs/example/scf/scf.py | 2 +- qmctorch/utils/torch_utils.py | 8 ++++---- .../jastrows/distance/test_elec_elec_distance.py | 5 +++-- .../orbital_dependent/test_generic_jastrow_orbital.py | 5 +++-- .../jastrows/elec_elec/test_generic_jastrow.py | 3 ++- .../wavefunction/jastrows/elec_elec/test_pade_jastrow.py | 3 ++- .../jastrows/elec_elec/test_pade_jastrow_polynom.py | 3 ++- .../jastrows/elec_elec/test_scaled_pade_jastrow.py | 3 ++- .../elec_elec/test_scaled_pade_jastrow_polynom.py | 3 ++- .../elec_elec_nuc/test_three_body_jastrow_boys_handy.py | 5 +++-- .../test_three_body_jastrow_fully_connected.py | 5 +++-- .../elec_nuc/test_electron_nuclei_fully_connected.py | 3 ++- .../elec_nuc/test_electron_nuclei_pade_jastrow.py | 3 ++- tests/wavefunction/jastrows/test_combined_terms.py | 3 ++- .../backflow/test_backflow_kernel_generic_pyscf.py | 3 ++- .../backflow/test_backflow_kernel_inverse_pyscf.py | 3 ++- .../backflow/test_backflow_transformation_pyscf.py | 3 ++- ...est_orbital_dependent_backflow_transformation_pyscf.py | 3 ++- tests/wavefunction/orbitals/test_ao_derivatives_adf.py | 3 ++- tests/wavefunction/orbitals/test_ao_derivatives_pyscf.py | 3 ++- .../orbitals/test_backflow_ao_derivatives_pyscf.py | 3 ++- ...est_orbital_dependent_backflow_ao_derivatives_pyscf.py | 3 ++- tests/wavefunction/test_compare_slaterjastrow_backflow.py | 4 ++-- ...st_compare_slaterjastrow_orbital_dependent_backflow.py | 2 +- .../wavefunction/test_slater_orbital_dependent_jastrow.py | 2 +- tests/wavefunction/test_slatercombinedjastrow.py | 2 +- tests/wavefunction/test_slatercombinedjastrow_backflow.py | 2 +- tests/wavefunction/test_slaterjastrow.py | 2 +- tests/wavefunction/test_slaterjastrow_backflow.py | 2 +- tests/wavefunction/test_slaterjastrow_cas.py | 2 +- tests/wavefunction/test_slaterjastrow_ee_cusp.py | 2 +- tests/wavefunction/test_slaterjastrow_generic.py | 2 +- .../test_slaterjastrow_orbital_dependent_backflow.py | 2 +- 33 files changed, 61 insertions(+), 41 deletions(-) diff --git a/docs/example/scf/scf.py b/docs/example/scf/scf.py index a609f866..ef612527 100644 --- a/docs/example/scf/scf.py +++ b/docs/example/scf/scf.py @@ -4,7 +4,7 @@ calc = ['pyscf', # pyscf 'adf', # adf 2019 'adf2019' # adf 2020+ - ][1] + ][0] # select an appropriate basis basis = { diff --git a/qmctorch/utils/torch_utils.py b/qmctorch/utils/torch_utils.py index b7eaecd5..4848fa74 100644 --- a/qmctorch/utils/torch_utils.py +++ b/qmctorch/utils/torch_utils.py @@ -6,14 +6,14 @@ def set_torch_double_precision(): """Set the default precision to double for all torch tensors.""" - torch.set_default_dtype = torch.float64 - torch.set_default_tensor_type(torch.DoubleTensor) + torch.set_default_dtype(torch.float64) + # torch.set_default_tensor_type(torch.DoubleTensor) def set_torch_single_precision(): """Set the default precision to single for all torch tensors.""" - torch.set_default_dtype = torch.float32 - torch.set_default_tensor_type(torch.FloatTensor) + torch.set_default_dtype(torch.float32) + # torch.set_default_tensor_type(torch.FloatTensor) def fast_power(x, k, mask0=None, mask2=None): diff --git a/tests/wavefunction/jastrows/distance/test_elec_elec_distance.py b/tests/wavefunction/jastrows/distance/test_elec_elec_distance.py index f0560f72..0830380b 100644 --- a/tests/wavefunction/jastrows/distance/test_elec_elec_distance.py +++ b/tests/wavefunction/jastrows/distance/test_elec_elec_distance.py @@ -1,9 +1,10 @@ import torch -from torch.autograd import Variable, grad, gradcheck +from torch.autograd import Variable, grad from qmctorch.wavefunction.jastrows.distance import ElectronElectronDistance import unittest +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec/orbital_dependent/test_generic_jastrow_orbital.py b/tests/wavefunction/jastrows/elec_elec/orbital_dependent/test_generic_jastrow_orbital.py index b0c3708b..8f401004 100644 --- a/tests/wavefunction/jastrows/elec_elec/orbital_dependent/test_generic_jastrow_orbital.py +++ b/tests/wavefunction/jastrows/elec_elec/orbital_dependent/test_generic_jastrow_orbital.py @@ -6,12 +6,13 @@ import numpy as np import torch -from torch.autograd import Variable, grad, gradcheck +from torch.autograd import Variable, grad from qmctorch.wavefunction.jastrows.elec_elec.jastrow_factor_electron_electron import JastrowFactorElectronElectron from qmctorch.wavefunction.jastrows.elec_elec.kernels.fully_connected_jastrow_kernel import FullyConnectedJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec/test_generic_jastrow.py b/tests/wavefunction/jastrows/elec_elec/test_generic_jastrow.py index 30bc2968..57bbcf00 100644 --- a/tests/wavefunction/jastrows/elec_elec/test_generic_jastrow.py +++ b/tests/wavefunction/jastrows/elec_elec/test_generic_jastrow.py @@ -10,8 +10,9 @@ from qmctorch.wavefunction.jastrows.elec_elec.jastrow_factor_electron_electron import JastrowFactorElectronElectron from qmctorch.wavefunction.jastrows.elec_elec.kernels.fully_connected_jastrow_kernel import FullyConnectedJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow.py b/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow.py index e7cbe41c..710c5ab4 100644 --- a/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow.py +++ b/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow.py @@ -5,8 +5,9 @@ from qmctorch.wavefunction.jastrows.elec_elec.jastrow_factor_electron_electron import JastrowFactorElectronElectron from qmctorch.wavefunction.jastrows.elec_elec.kernels.pade_jastrow_kernel import PadeJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow_polynom.py b/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow_polynom.py index d3589cef..befa46e1 100644 --- a/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow_polynom.py +++ b/tests/wavefunction/jastrows/elec_elec/test_pade_jastrow_polynom.py @@ -5,8 +5,9 @@ from qmctorch.wavefunction.jastrows.elec_elec.jastrow_factor_electron_electron import JastrowFactorElectronElectron from qmctorch.wavefunction.jastrows.elec_elec.kernels.pade_jastrow_polynomial_kernel import PadeJastrowPolynomialKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow.py b/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow.py index 80a88f49..2e247337 100644 --- a/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow.py +++ b/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow.py @@ -6,8 +6,9 @@ from qmctorch.wavefunction.jastrows.elec_elec.jastrow_factor_electron_electron import JastrowFactorElectronElectron from qmctorch.wavefunction.jastrows.elec_elec.kernels.pade_jastrow_kernel import PadeJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow_polynom.py b/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow_polynom.py index c43a1132..99699aa1 100644 --- a/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow_polynom.py +++ b/tests/wavefunction/jastrows/elec_elec/test_scaled_pade_jastrow_polynom.py @@ -6,8 +6,9 @@ from qmctorch.wavefunction.jastrows.elec_elec.jastrow_factor_electron_electron import JastrowFactorElectronElectron from qmctorch.wavefunction.jastrows.elec_elec.kernels.pade_jastrow_polynomial_kernel import PadeJastrowPolynomialKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_boys_handy.py b/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_boys_handy.py index b2d31fef..7791d9b9 100644 --- a/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_boys_handy.py +++ b/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_boys_handy.py @@ -2,11 +2,12 @@ import numpy as np import torch -from torch.autograd import Variable, grad, gradcheck +from torch.autograd import Variable, grad from qmctorch.wavefunction.jastrows.elec_elec_nuclei.jastrow_factor_electron_electron_nuclei import JastrowFactorElectronElectronNuclei from qmctorch.wavefunction.jastrows.elec_elec_nuclei.kernels.boys_handy_jastrow_kernel import BoysHandyJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_fully_connected.py b/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_fully_connected.py index 33d40ce4..d09926b0 100644 --- a/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_fully_connected.py +++ b/tests/wavefunction/jastrows/elec_elec_nuc/test_three_body_jastrow_fully_connected.py @@ -2,11 +2,12 @@ import numpy as np import torch -from torch.autograd import Variable, grad, gradcheck +from torch.autograd import Variable, grad from qmctorch.wavefunction.jastrows.elec_elec_nuclei.jastrow_factor_electron_electron_nuclei import JastrowFactorElectronElectronNuclei from qmctorch.wavefunction.jastrows.elec_elec_nuclei.kernels.fully_connected_jastrow_kernel import FullyConnectedJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_fully_connected.py b/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_fully_connected.py index 1fa7699e..63a44c3f 100644 --- a/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_fully_connected.py +++ b/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_fully_connected.py @@ -5,8 +5,9 @@ from torch.autograd import Variable, grad, gradcheck from qmctorch.wavefunction.jastrows.elec_nuclei.jastrow_factor_electron_nuclei import JastrowFactorElectronNuclei from qmctorch.wavefunction.jastrows.elec_nuclei.kernels import FullyConnectedJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_pade_jastrow.py b/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_pade_jastrow.py index bb4aae7d..0b5e7e6d 100644 --- a/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_pade_jastrow.py +++ b/tests/wavefunction/jastrows/elec_nuc/test_electron_nuclei_pade_jastrow.py @@ -6,8 +6,9 @@ from qmctorch.wavefunction.jastrows.elec_nuclei.jastrow_factor_electron_nuclei import JastrowFactorElectronNuclei from qmctorch.wavefunction.jastrows.elec_nuclei.kernels.pade_jastrow_kernel import PadeJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/jastrows/test_combined_terms.py b/tests/wavefunction/jastrows/test_combined_terms.py index 6c19a47c..dcb9c806 100644 --- a/tests/wavefunction/jastrows/test_combined_terms.py +++ b/tests/wavefunction/jastrows/test_combined_terms.py @@ -8,8 +8,9 @@ from qmctorch.wavefunction.jastrows.elec_elec.kernels import PadeJastrowKernel as PadeJastrowKernelElecElec from qmctorch.wavefunction.jastrows.elec_nuclei.kernels import PadeJastrowKernel as PadeJastrowKernelElecNuc from qmctorch.wavefunction.jastrows.elec_elec_nuclei.kernels import BoysHandyJastrowKernel, FullyConnectedJastrowKernel +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/orbitals/backflow/test_backflow_kernel_generic_pyscf.py b/tests/wavefunction/orbitals/backflow/test_backflow_kernel_generic_pyscf.py index 4be0c43f..b90548c0 100644 --- a/tests/wavefunction/orbitals/backflow/test_backflow_kernel_generic_pyscf.py +++ b/tests/wavefunction/orbitals/backflow/test_backflow_kernel_generic_pyscf.py @@ -9,7 +9,8 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction.orbitals.backflow.kernels import BackFlowKernelBase from qmctorch.wavefunction.jastrows.distance.electron_electron_distance import ElectronElectronDistance -torch.set_default_tensor_type(torch.DoubleTensor) +from qmctorch.utils import set_torch_double_precision +set_torch_double_precision() torch.manual_seed(101) np.random.seed(101) diff --git a/tests/wavefunction/orbitals/backflow/test_backflow_kernel_inverse_pyscf.py b/tests/wavefunction/orbitals/backflow/test_backflow_kernel_inverse_pyscf.py index 0001d1cd..3e377d56 100644 --- a/tests/wavefunction/orbitals/backflow/test_backflow_kernel_inverse_pyscf.py +++ b/tests/wavefunction/orbitals/backflow/test_backflow_kernel_inverse_pyscf.py @@ -8,7 +8,8 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction.orbitals.backflow.kernels import BackFlowKernelInverse from qmctorch.wavefunction.jastrows.distance.electron_electron_distance import ElectronElectronDistance -torch.set_default_tensor_type(torch.DoubleTensor) +from qmctorch.utils import set_torch_double_precision +set_torch_double_precision() torch.manual_seed(101) np.random.seed(101) diff --git a/tests/wavefunction/orbitals/backflow/test_backflow_transformation_pyscf.py b/tests/wavefunction/orbitals/backflow/test_backflow_transformation_pyscf.py index fa3af66a..f577f630 100644 --- a/tests/wavefunction/orbitals/backflow/test_backflow_transformation_pyscf.py +++ b/tests/wavefunction/orbitals/backflow/test_backflow_transformation_pyscf.py @@ -7,7 +7,8 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction.orbitals.backflow.backflow_transformation import BackFlowTransformation from qmctorch.wavefunction.orbitals.backflow.kernels import BackFlowKernelInverse -torch.set_default_tensor_type(torch.DoubleTensor) +from qmctorch.utils import set_torch_double_precision +set_torch_double_precision() torch.manual_seed(101) np.random.seed(101) diff --git a/tests/wavefunction/orbitals/backflow/test_orbital_dependent_backflow_transformation_pyscf.py b/tests/wavefunction/orbitals/backflow/test_orbital_dependent_backflow_transformation_pyscf.py index 9ca1c4f8..9de70ec8 100644 --- a/tests/wavefunction/orbitals/backflow/test_orbital_dependent_backflow_transformation_pyscf.py +++ b/tests/wavefunction/orbitals/backflow/test_orbital_dependent_backflow_transformation_pyscf.py @@ -7,7 +7,8 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction.orbitals.backflow.orbital_dependent_backflow_transformation import OrbitalDependentBackFlowTransformation from qmctorch.wavefunction.orbitals.backflow.kernels import BackFlowKernelInverse -torch.set_default_tensor_type(torch.DoubleTensor) +from qmctorch.utils import set_torch_double_precision +set_torch_double_precision() torch.manual_seed(101) np.random.seed(101) diff --git a/tests/wavefunction/orbitals/test_ao_derivatives_adf.py b/tests/wavefunction/orbitals/test_ao_derivatives_adf.py index 070a71c3..f0a7f2e8 100644 --- a/tests/wavefunction/orbitals/test_ao_derivatives_adf.py +++ b/tests/wavefunction/orbitals/test_ao_derivatives_adf.py @@ -6,9 +6,10 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterJastrow +from qmctorch.utils import set_torch_double_precision from ...path_utils import PATH_TEST -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/orbitals/test_ao_derivatives_pyscf.py b/tests/wavefunction/orbitals/test_ao_derivatives_pyscf.py index 7606b746..f152664a 100644 --- a/tests/wavefunction/orbitals/test_ao_derivatives_pyscf.py +++ b/tests/wavefunction/orbitals/test_ao_derivatives_pyscf.py @@ -6,8 +6,9 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterJastrow +from qmctorch.utils import set_torch_double_precision -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/orbitals/test_backflow_ao_derivatives_pyscf.py b/tests/wavefunction/orbitals/test_backflow_ao_derivatives_pyscf.py index 0299b02f..a38be2f0 100644 --- a/tests/wavefunction/orbitals/test_backflow_ao_derivatives_pyscf.py +++ b/tests/wavefunction/orbitals/test_backflow_ao_derivatives_pyscf.py @@ -8,7 +8,8 @@ from qmctorch.wavefunction import SlaterJastrow from qmctorch.wavefunction.orbitals.atomic_orbitals_backflow import AtomicOrbitalsBackFlow from qmctorch.wavefunction.orbitals.backflow.kernels import BackFlowKernelInverse -torch.set_default_tensor_type(torch.DoubleTensor) +from qmctorch.utils import set_torch_double_precision +set_torch_double_precision() torch.manual_seed(101) np.random.seed(101) diff --git a/tests/wavefunction/orbitals/test_orbital_dependent_backflow_ao_derivatives_pyscf.py b/tests/wavefunction/orbitals/test_orbital_dependent_backflow_ao_derivatives_pyscf.py index 65cedb85..94d91474 100644 --- a/tests/wavefunction/orbitals/test_orbital_dependent_backflow_ao_derivatives_pyscf.py +++ b/tests/wavefunction/orbitals/test_orbital_dependent_backflow_ao_derivatives_pyscf.py @@ -8,7 +8,8 @@ from qmctorch.wavefunction import SlaterJastrow from qmctorch.wavefunction.orbitals.atomic_orbitals_orbital_dependent_backflow import AtomicOrbitalsOrbitalDependentBackFlow from qmctorch.wavefunction.orbitals.backflow.kernels import BackFlowKernelInverse -torch.set_default_tensor_type(torch.DoubleTensor) +from qmctorch.utils import set_torch_double_precision +set_torch_double_precision() torch.manual_seed(101) np.random.seed(101) diff --git a/tests/wavefunction/test_compare_slaterjastrow_backflow.py b/tests/wavefunction/test_compare_slaterjastrow_backflow.py index f2115b95..e04ef76e 100644 --- a/tests/wavefunction/test_compare_slaterjastrow_backflow.py +++ b/tests/wavefunction/test_compare_slaterjastrow_backflow.py @@ -9,8 +9,8 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) - +# set_torch_double_precision() +set_torch_double_precision() def hess(out, pos): # compute the jacobian diff --git a/tests/wavefunction/test_compare_slaterjastrow_orbital_dependent_backflow.py b/tests/wavefunction/test_compare_slaterjastrow_orbital_dependent_backflow.py index 2e8109d3..935fe2bc 100644 --- a/tests/wavefunction/test_compare_slaterjastrow_orbital_dependent_backflow.py +++ b/tests/wavefunction/test_compare_slaterjastrow_orbital_dependent_backflow.py @@ -9,7 +9,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slater_orbital_dependent_jastrow.py b/tests/wavefunction/test_slater_orbital_dependent_jastrow.py index da636f4a..14f3c322 100644 --- a/tests/wavefunction/test_slater_orbital_dependent_jastrow.py +++ b/tests/wavefunction/test_slater_orbital_dependent_jastrow.py @@ -1,7 +1,7 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterOrbitalDependentJastrow from qmctorch.wavefunction.jastrows.elec_elec.kernels import FullyConnectedJastrowKernel -from qmctorch.utils import set_torch_double_precision, btrace +from qmctorch.utils import set_torch_double_precision from torch.autograd import grad, Variable diff --git a/tests/wavefunction/test_slatercombinedjastrow.py b/tests/wavefunction/test_slatercombinedjastrow.py index 82be80e3..6ad292ef 100644 --- a/tests/wavefunction/test_slatercombinedjastrow.py +++ b/tests/wavefunction/test_slatercombinedjastrow.py @@ -10,7 +10,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slatercombinedjastrow_backflow.py b/tests/wavefunction/test_slatercombinedjastrow_backflow.py index e591628d..c5c99b31 100644 --- a/tests/wavefunction/test_slatercombinedjastrow_backflow.py +++ b/tests/wavefunction/test_slatercombinedjastrow_backflow.py @@ -12,7 +12,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slaterjastrow.py b/tests/wavefunction/test_slaterjastrow.py index 9c297f89..fe5bf8c4 100644 --- a/tests/wavefunction/test_slaterjastrow.py +++ b/tests/wavefunction/test_slaterjastrow.py @@ -8,7 +8,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slaterjastrow_backflow.py b/tests/wavefunction/test_slaterjastrow_backflow.py index 0fef056c..3c0faac3 100644 --- a/tests/wavefunction/test_slaterjastrow_backflow.py +++ b/tests/wavefunction/test_slaterjastrow_backflow.py @@ -12,7 +12,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slaterjastrow_cas.py b/tests/wavefunction/test_slaterjastrow_cas.py index c6e8543d..05b083b4 100644 --- a/tests/wavefunction/test_slaterjastrow_cas.py +++ b/tests/wavefunction/test_slaterjastrow_cas.py @@ -8,7 +8,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slaterjastrow_ee_cusp.py b/tests/wavefunction/test_slaterjastrow_ee_cusp.py index e6e05a67..cff4a70b 100644 --- a/tests/wavefunction/test_slaterjastrow_ee_cusp.py +++ b/tests/wavefunction/test_slaterjastrow_ee_cusp.py @@ -7,7 +7,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() class TestSlaterJastrowElectronCusp(unittest.TestCase): diff --git a/tests/wavefunction/test_slaterjastrow_generic.py b/tests/wavefunction/test_slaterjastrow_generic.py index 39f0550e..e453521e 100644 --- a/tests/wavefunction/test_slaterjastrow_generic.py +++ b/tests/wavefunction/test_slaterjastrow_generic.py @@ -10,7 +10,7 @@ import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): diff --git a/tests/wavefunction/test_slaterjastrow_orbital_dependent_backflow.py b/tests/wavefunction/test_slaterjastrow_orbital_dependent_backflow.py index 3b95a5da..6c0fe76c 100644 --- a/tests/wavefunction/test_slaterjastrow_orbital_dependent_backflow.py +++ b/tests/wavefunction/test_slaterjastrow_orbital_dependent_backflow.py @@ -13,7 +13,7 @@ import torch import unittest -torch.set_default_tensor_type(torch.DoubleTensor) +set_torch_double_precision() def hess(out, pos): From f399f7c8a48dcedcd4ddb087e2701b731b43b99e Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 15:27:48 +0100 Subject: [PATCH 02/12] add osx test --- .github/workflows/build.yml | 2 +- .github/workflows/draft-pdf.yml | 23 ----------------------- 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 .github/workflows/draft-pdf.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cbf2b1bc..b7e6618a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: [push] jobs: build: name: build and test - runs-on: ubuntu-latest + runs-on: [ubuntu-latest, macos-latest] strategy: fail-fast: false diff --git a/.github/workflows/draft-pdf.yml b/.github/workflows/draft-pdf.yml deleted file mode 100644 index 65635939..00000000 --- a/.github/workflows/draft-pdf.yml +++ /dev/null @@ -1,23 +0,0 @@ -on: [push] - -jobs: - paper: - runs-on: ubuntu-latest - name: Paper Draft - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Build draft PDF - uses: openjournals/openjournals-draft-action@master - with: - journal: joss - # This should be the path to the paper within your repo. - paper-path: paper/paper.md - - name: Upload - uses: actions/upload-artifact@v1 - with: - name: paper - # This is the output path where Pandoc will write the compiled - # PDF. Note, this should be the same directory as the input - # paper.md - path: paper/paper.pdf \ No newline at end of file From 24394450762f9b19799dd9a6c7782d855957f38f Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 15:50:06 +0100 Subject: [PATCH 03/12] add osx test --- .github/workflows/build.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7e6618a..286ef429 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,13 +4,14 @@ on: [push] jobs: build: - name: build and test - runs-on: [ubuntu-latest, macos-latest] + name: build and test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - version: [3.8] + os: ['ubuntu-latest', 'macos-latest'] + python-version: [3.8] steps: - name: Cancel Previous Runs @@ -22,7 +23,7 @@ jobs: uses: s-weigand/setup-conda@v1 with: update-conda: true - python-version: ${{ matrix.version }} + python-version: ${{ matrix.python-version }} conda-channels: anaconda - name: Install essential run: | @@ -59,7 +60,7 @@ jobs: run: coveralls --service=github env: GITHUB_TOKEN: ${{ secrets.github_token }} - COVERALLS_FLAG_NAME: python-${{ matrix.version }} + COVERALLS_FLAG_NAME: python-${{ matrix.python-version }} COVERALLS_PARALLEL: true finish: From ff1f31ef5275d4b51b7182f538141e24f9e39aa1 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 15:57:30 +0100 Subject: [PATCH 04/12] osx test --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 286ef429..919f61cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,17 +20,20 @@ jobs: access_token: ${{ github.token }} - uses: actions/checkout@v4 - name: Setup conda - uses: s-weigand/setup-conda@v1 + uses: conda-incubator/etup-miniconda@v3 with: - update-conda: true + miniconda-version: "latest" + auto-update-conda: true python-version: ${{ matrix.python-version }} - conda-channels: anaconda + activate-environment: test + auto-activate-base: False - name: Install essential run: | sudo apt update sudo apt install build-essential - name: Install conda packages run: | + conda activate test conda install -c anaconda cmake conda install mpi4py h5py pytorch==2.0.0 torchvision==0.15.0 cpuonly -c pytorch -c conda-forge conda install -c conda-forge libstdcxx-ng From 6013702f9739ae63e56f18caffe6907b5d8446bb Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 16:04:44 +0100 Subject: [PATCH 05/12] osx test --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 919f61cd..741b2075 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,13 +20,13 @@ jobs: access_token: ${{ github.token }} - uses: actions/checkout@v4 - name: Setup conda - uses: conda-incubator/etup-miniconda@v3 + uses: conda-incubator/setup-miniconda@v3 with: miniconda-version: "latest" auto-update-conda: true python-version: ${{ matrix.python-version }} activate-environment: test - auto-activate-base: False + auto-activate-base: false - name: Install essential run: | sudo apt update From 3c7a432937863536ee6624bb57e12d60928f73d4 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 16:22:32 +0100 Subject: [PATCH 06/12] split test files --- .github/workflows/build.yml | 20 ++++------ .github/workflows/build_osx.yml | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/build_osx.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 741b2075..b1daed78 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,14 +4,13 @@ on: [push] jobs: build: - name: build and test on ${{ matrix.os }} - runs-on: ${{ matrix.os }} + name: build and test + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: ['ubuntu-latest', 'macos-latest'] - python-version: [3.8] + version: [3.8, 3.10] steps: - name: Cancel Previous Runs @@ -20,20 +19,17 @@ jobs: access_token: ${{ github.token }} - uses: actions/checkout@v4 - name: Setup conda - uses: conda-incubator/setup-miniconda@v3 + uses: s-weigand/setup-conda@v1 with: - miniconda-version: "latest" - auto-update-conda: true - python-version: ${{ matrix.python-version }} - activate-environment: test - auto-activate-base: false + update-conda: true + python-version: ${{ matrix.version }} + conda-channels: anaconda - name: Install essential run: | sudo apt update sudo apt install build-essential - name: Install conda packages run: | - conda activate test conda install -c anaconda cmake conda install mpi4py h5py pytorch==2.0.0 torchvision==0.15.0 cpuonly -c pytorch -c conda-forge conda install -c conda-forge libstdcxx-ng @@ -63,7 +59,7 @@ jobs: run: coveralls --service=github env: GITHUB_TOKEN: ${{ secrets.github_token }} - COVERALLS_FLAG_NAME: python-${{ matrix.python-version }} + COVERALLS_FLAG_NAME: python-${{ matrix.version }} COVERALLS_PARALLEL: true finish: diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml new file mode 100644 index 00000000..a3b8de16 --- /dev/null +++ b/.github/workflows/build_osx.yml @@ -0,0 +1,68 @@ +name: build_OSX + +on: [push] + +jobs: + build: + name: build and test on mac os + runs-on: macos-latest + + strategy: + fail-fast: false + matrix: + version: [3.8, 3.10] + include: + - os: macos-latest + CONDA_OS: osx-64 + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.12.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v4 + - name: Setup conda + uses: conda-incubator/setup-miniconda@v3 + with: + miniconda-version: "latest" + auto-update-conda: true + python-version: ${{ matrix.version }} + conda-channels: anaconda + + - name: Install conda packages + run: | + conda install -c anaconda cmake + conda install mpi4py h5py pytorch==2.0.0 torchvision==0.15.0 cpuonly -c pytorch -c conda-forge + conda install -c conda-forge libstdcxx-ng + conda install -c anaconda gxx_linux-64 + + - name: Install the package + run: python -m pip install .[test,hpc] + + + - name: Test with single thread + env: + CONDA_PREFIX: /usr/share/miniconda + run: coverage run -m pytest tests + + - name: Combine all coverage results + run: coverage combine + + - run: coverage report + + - name: Coveralls Parallel + run: coveralls --service=github + env: + GITHUB_TOKEN: ${{ secrets.github_token }} + COVERALLS_FLAG_NAME: python-${{ matrix.version }} + COVERALLS_PARALLEL: true + + finish: + needs: build + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true From ffe5a81ccfceae114a920e1823dc8ff193653c4f Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 16:25:28 +0100 Subject: [PATCH 07/12] split test files --- .github/workflows/build_osx.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml index a3b8de16..735af733 100644 --- a/.github/workflows/build_osx.yml +++ b/.github/workflows/build_osx.yml @@ -11,9 +11,9 @@ jobs: fail-fast: false matrix: version: [3.8, 3.10] - include: - - os: macos-latest - CONDA_OS: osx-64 + include: + - os: macos-latest + CONDA_OS: osx-64 steps: - name: Cancel Previous Runs From 129a2afc7fe46e18dfc7c19ea45dfffe9d88833f Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 16:40:47 +0100 Subject: [PATCH 08/12] split test files --- .github/workflows/build.yml | 2 +- .github/workflows/build_osx.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1daed78..eaaeada9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - version: [3.8, 3.10] + version: ['3.8', '3.10'] steps: - name: Cancel Previous Runs diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml index 735af733..edcc46f4 100644 --- a/.github/workflows/build_osx.yml +++ b/.github/workflows/build_osx.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - version: [3.8, 3.10] + version: ['3.8', '3.10'] include: - os: macos-latest CONDA_OS: osx-64 From d4cc30c837b9db33d1720fba0ea454744e2e12a1 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 16:44:28 +0100 Subject: [PATCH 09/12] split test files --- .github/workflows/build_osx.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml index edcc46f4..5a78e068 100644 --- a/.github/workflows/build_osx.yml +++ b/.github/workflows/build_osx.yml @@ -31,10 +31,7 @@ jobs: - name: Install conda packages run: | - conda install -c anaconda cmake - conda install mpi4py h5py pytorch==2.0.0 torchvision==0.15.0 cpuonly -c pytorch -c conda-forge - conda install -c conda-forge libstdcxx-ng - conda install -c anaconda gxx_linux-64 + conda install mpi4py h5py pytorch cpuonly -c pytorch -c conda-forge - name: Install the package run: python -m pip install .[test,hpc] From 5a30d0ed8dc4f3ecdeeb0ce4e7d16d5e9554ee12 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 16:47:03 +0100 Subject: [PATCH 10/12] split test files --- .github/workflows/build_osx.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml index 5a78e068..fa66a2d7 100644 --- a/.github/workflows/build_osx.yml +++ b/.github/workflows/build_osx.yml @@ -31,10 +31,11 @@ jobs: - name: Install conda packages run: | - conda install mpi4py h5py pytorch cpuonly -c pytorch -c conda-forge + conda install h5py -c conda-forge + conda install pytorch::pytorch -c pytorch - name: Install the package - run: python -m pip install .[test,hpc] + run: python -m pip install .[test] - name: Test with single thread From 69bb397ee7b9424102c8e4ed778ff499e1917b00 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 17:47:52 +0100 Subject: [PATCH 11/12] fix f2 issue --- qmctorch/utils/algebra_utils.py | 15 +++++++++- .../wavefunction/orbitals/norm_orbital.py | 28 +++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/qmctorch/utils/algebra_utils.py b/qmctorch/utils/algebra_utils.py index 50f5d5bf..726c5e53 100644 --- a/qmctorch/utils/algebra_utils.py +++ b/qmctorch/utils/algebra_utils.py @@ -1,5 +1,5 @@ import torch - +from scipy.special import factorial2 as f2 def btrace(M): """Computes the trace of batched matrices @@ -43,6 +43,19 @@ def bdet2(M): return M[..., 0, 0] * M[..., 1, 1] - M[..., 0, 1] * M[..., 1, 0] +def double_factorial(input): + """Computes the double factorial of an array of int + + Args: + input (List): input numbers + + Returns: + List: values of the double factorial + """ + output = f2(input) + return [1 if o==0 else o for o in output] + + class BatchDeterminant(torch.autograd.Function): @staticmethod diff --git a/qmctorch/wavefunction/orbitals/norm_orbital.py b/qmctorch/wavefunction/orbitals/norm_orbital.py index 77ee6990..6f3be4ff 100644 --- a/qmctorch/wavefunction/orbitals/norm_orbital.py +++ b/qmctorch/wavefunction/orbitals/norm_orbital.py @@ -1,6 +1,6 @@ import torch import numpy as np - +from ...utils.algebra_utils import double_factorial def atomic_orbital_norm(basis): """Computes the norm of the atomic orbitals @@ -77,16 +77,13 @@ def norm_gaussian_spherical(bas_n, bas_exp): Returns: torch.tensor: normalization factor """ - - from scipy.special import factorial2 as f2 - bas_n = torch.tensor(bas_n) bas_n = bas_n + 1. exp1 = 0.25 * (2. * bas_n + 1.) A = torch.tensor(bas_exp)**exp1 B = 2**(2. * bas_n + 3. / 2) - C = torch.as_tensor(f2(2 * bas_n.int() - 1) * np.pi ** + C = torch.as_tensor(double_factorial(2 * bas_n.int() - 1) * np.pi ** 0.5).type(torch.get_default_dtype()) return torch.sqrt(B / C) * A @@ -106,8 +103,6 @@ def norm_slater_cartesian(a, b, c, n, exp): Returns: torch.tensor: normalization factor """ - from scipy.special import factorial2 as f2 - lvals = a + b + c + n + 1. lfact = torch.as_tensor([np.math.factorial(int(2 * i)) @@ -115,13 +110,13 @@ def norm_slater_cartesian(a, b, c, n, exp): prefact = 4 * np.pi * lfact / ((2 * exp)**(2 * lvals + 1)) - num = torch.as_tensor(f2(2 * a.astype('int') - 1) * - f2(2 * b.astype('int') - 1) * - f2(2 * c.astype('int') - 1) + num = torch.as_tensor(double_factorial(2 * a.astype('int') - 1) * + double_factorial(2 * b.astype('int') - 1) * + double_factorial(2 * c.astype('int') - 1) ).type(torch.get_default_dtype()) denom = torch.as_tensor( - f2((2 * a + 2 * b + 2 * c + 1).astype('int') + double_factorial((2 * a + 2 * b + 2 * c + 1).astype('int') )).type(torch.get_default_dtype()) return torch.sqrt(1. / (prefact * num / denom)) @@ -135,22 +130,19 @@ def norm_gaussian_cartesian(a, b, c, exp): a (torch.tensor): exponent of x b (torch.tensor): exponent of y c (torch.tensor): exponent of z - exp (torch.tensor): Sater exponent + exp (torch.tensor): Slater exponent Returns: torch.tensor: normalization factor """ - - from scipy.special import factorial2 as f2 - pref = torch.as_tensor((2 * exp / np.pi)**(0.75)) am1 = (2 * a - 1).astype('int') - x = (4 * exp)**(a / 2) / torch.sqrt(torch.as_tensor(f2(am1))) + x = (4 * exp)**(a / 2) / torch.sqrt(torch.as_tensor(double_factorial(am1))) bm1 = (2 * b - 1).astype('int') - y = (4 * exp)**(b / 2) / torch.sqrt(torch.as_tensor(f2(bm1))) + y = (4 * exp)**(b / 2) / torch.sqrt(torch.as_tensor(double_factorial(bm1))) cm1 = (2 * c - 1).astype('int') - z = (4 * exp)**(c / 2) / torch.sqrt(torch.as_tensor(f2(cm1))) + z = (4 * exp)**(c / 2) / torch.sqrt(torch.as_tensor(double_factorial(cm1))) return (pref * x * y * z).type(torch.get_default_dtype()) From 91cfde457c3af0ed297dfd6518027cedd3c29c2f Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 5 Dec 2024 18:20:47 +0100 Subject: [PATCH 12/12] make f2 output an array --- .github/workflows/build_osx.yml | 66 --------------------------------- qmctorch/utils/algebra_utils.py | 3 +- 2 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/build_osx.yml diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml deleted file mode 100644 index fa66a2d7..00000000 --- a/.github/workflows/build_osx.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: build_OSX - -on: [push] - -jobs: - build: - name: build and test on mac os - runs-on: macos-latest - - strategy: - fail-fast: false - matrix: - version: ['3.8', '3.10'] - include: - - os: macos-latest - CONDA_OS: osx-64 - - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.12.0 - with: - access_token: ${{ github.token }} - - uses: actions/checkout@v4 - - name: Setup conda - uses: conda-incubator/setup-miniconda@v3 - with: - miniconda-version: "latest" - auto-update-conda: true - python-version: ${{ matrix.version }} - conda-channels: anaconda - - - name: Install conda packages - run: | - conda install h5py -c conda-forge - conda install pytorch::pytorch -c pytorch - - - name: Install the package - run: python -m pip install .[test] - - - - name: Test with single thread - env: - CONDA_PREFIX: /usr/share/miniconda - run: coverage run -m pytest tests - - - name: Combine all coverage results - run: coverage combine - - - run: coverage report - - - name: Coveralls Parallel - run: coveralls --service=github - env: - GITHUB_TOKEN: ${{ secrets.github_token }} - COVERALLS_FLAG_NAME: python-${{ matrix.version }} - COVERALLS_PARALLEL: true - - finish: - needs: build - runs-on: ubuntu-latest - steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true diff --git a/qmctorch/utils/algebra_utils.py b/qmctorch/utils/algebra_utils.py index 726c5e53..914d14c4 100644 --- a/qmctorch/utils/algebra_utils.py +++ b/qmctorch/utils/algebra_utils.py @@ -1,4 +1,5 @@ import torch +import numpy as np from scipy.special import factorial2 as f2 def btrace(M): @@ -53,7 +54,7 @@ def double_factorial(input): List: values of the double factorial """ output = f2(input) - return [1 if o==0 else o for o in output] + return np.array([1 if o==0 else o for o in output]) class BatchDeterminant(torch.autograd.Function):