Skip to content

Commit c2270b2

Browse files
committed
Add gpu4pyscf support
* Adds support for using gpu4pyscf instead of pyscf for running SCF (cherry picked from commit 7c1ce3bce4b84bf05d6b5765c914f71f4ced98d5)
1 parent 18cf836 commit c2270b2

25 files changed

+1840
-180
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Setup micromamba
2525
uses: mamba-org/setup-micromamba@v1
2626
with:
27-
environment-file: environment.yml
27+
environment-file: environment-cpu.yml
2828
environment-name: skala
2929
cache-environment: true
3030
cache-downloads: true

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup micromamba
2424
uses: mamba-org/setup-micromamba@v1
2525
with:
26-
environment-file: environment.yml
26+
environment-file: environment-cpu.yml
2727
environment-name: skala
2828
cache-environment: true
2929
cache-downloads: true

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,31 @@ mol = gto.M(
4343
ks = SkalaKS(mol, xc="skala")
4444
ks.kernel()
4545
```
46-
4746
Go to [microsoft.github.io/skala](https://microsoft.github.io/skala) for a more detailed installation guide and further examples of how to use Skala functional with PySCF and ASE and in [Azure Foundry](https://ai.azure.com/catalog/models/Skala).
4847

48+
## Getting started (GPU support)
49+
50+
Install using Pip:
51+
```bash
52+
cu_version=128 #or 126 or 130 depending on your CUDA version
53+
pip install torch cupy --extra-index-url "https://download.pytorch.org/whl/cu${cu_version}"
54+
pip install --no-deps "gpu4pyscf-cuda${cu_version:0:2}x>=1.0,<2" "gpu4pyscf-libxc-cuda${cu_version:0:2}x>=0.4,<1"
55+
pip install microsoft-skala
56+
```
57+
Run an SCF calculation with Skala for a hydrogen molecule on GPU:
58+
59+
```python
60+
from pyscf import gto
61+
from skala.gpu4pyscf import SkalaKS
62+
63+
mol = gto.M(
64+
atom="""H 0 0 0; H 0 0 1.4""",
65+
basis="def2-tzvp",
66+
)
67+
ks = SkalaKS(mol, xc="skala")
68+
ks.kernel()
69+
```
70+
4971
## Project information
5072

5173
See the following files for more information about contributing, reporting issues, and the code of conduct:

docs/installation.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ If you prefer to install Skala from the source code, you can clone the repositor
3333
3434
git clone https://github.com/microsoft/skala
3535
cd skala
36-
mamba env create -n skala -f environment.yml
36+
mamba env create -n skala -f environment-cpu.yml
3737
mamba activate skala
3838
pip install -e .
3939
40+
where `environment-cpu.yml` can be replaced for `environment-gpu.yml` for gpu support (CUDA 12) with gpu4pyscf, in which case gpu4pyscf needs to be separately installed *after creating the environment* via
41+
42+
.. code-block:: bash
43+
44+
pip install --no-deps 'gpu4pyscf-cuda12x>=1.0,<2' 'gpu4pyscf-libxc-cuda12x>=0.4,<1'
45+
4046
To install the development dependencies, you can run:
4147

4248
.. code-block:: bash

docs/pyscf/scf_settings.ipynb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 1,
14+
"execution_count": null,
1515
"id": "dd93a68a",
1616
"metadata": {},
17-
"outputs": [
18-
{
19-
"name": "stderr",
20-
"output_type": "stream",
21-
"text": [
22-
"/home/giulialuise/miniconda3/envs/skala/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
23-
" from .autonotebook import tqdm as notebook_tqdm\n"
24-
]
25-
}
26-
],
17+
"outputs": [],
2718
"source": [
2819
"from pyscf import gto\n",
2920
"\n",

docs/pyscf/singlepoint.ipynb

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,42 @@
104104
"\n",
105105
"print(ks.dump_scf_summary())"
106106
]
107+
},
108+
{
109+
"cell_type": "markdown",
110+
"id": "fd56964d",
111+
"metadata": {},
112+
"source": [
113+
"# Using the Skala functional in GPU4PySCF\n",
114+
"\n",
115+
"The Skala functional can also be used in GPU4PySCF with an appropriate PyTorch CUDA version by creating a new Kohn-Sham calculator based on the `SkalaKS` constructor from the `skala.gpu4pyscf`."
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"id": "cec1b5f9",
122+
"metadata": {},
123+
"outputs": [],
124+
"source": [
125+
"from pyscf import gto\n",
126+
"\n",
127+
"from skala.gpu4pyscf import SkalaKS\n",
128+
"\n",
129+
"mol = gto.M(\n",
130+
" atom=\"\"\"H 0 0 0; H 0 0 1.4\"\"\",\n",
131+
" basis=\"def2-tzvp\",\n",
132+
")\n",
133+
"ks = SkalaKS(mol, xc=\"skala\")\n",
134+
"ks.kernel()\n",
135+
"\n",
136+
"print(ks.dump_scf_summary())"
137+
]
107138
}
108139
],
109140
"metadata": {
110141
"kernelspec": {
111-
"display_name": "skala",
142+
"display_name": "skala_test",
112143
"language": "python",
113144
"name": "python3"
114145
},
@@ -122,7 +153,7 @@
122153
"name": "python",
123154
"nbconvert_exporter": "python",
124155
"pygments_lexer": "ipython3",
125-
"version": "3.13.5"
156+
"version": "3.14.2"
126157
}
127158
},
128159
"nbformat": 4,

environment-cpu.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: skala-cpu
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- ase
6+
- azure-core
7+
- azure-identity
8+
- dftd3-python
9+
- e3nn
10+
- numpy
11+
- opt_einsum_fx
12+
- pyscf<2.10.0
13+
- python
14+
- pytorch * cpu_*
15+
- qcelemental
16+
# Testing and development
17+
- pre-commit
18+
- pytest
19+
- pytest-cov
20+
- pip:
21+
- huggingface_hub

environment-gpu.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: skala-gpu
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- ase
6+
- azure-core
7+
- azure-identity
8+
- dftd3-python
9+
- e3nn
10+
- numpy
11+
- opt_einsum_fx
12+
- pyscf<2.10.0
13+
- python
14+
- pytorch-gpu
15+
- qcelemental
16+
- cuda-toolkit
17+
- cupy
18+
- cutensor
19+
- cuda-version ==12.*
20+
# Testing and development
21+
- pre-commit
22+
- pytest
23+
- pytest-cov
24+
- pip:
25+
- huggingface_hub

environment.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/cpp/cpp_integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Set up the conda environment using the provided environment file:
88

99
```bash
1010
cd examples/cpp/cpp_integration
11-
conda env create -n skala_cpp_integration -f environment.yml
11+
conda env create -n skala_cpp_integration -f environment-cpu.yml
1212
conda activate skala_cpp_integration
1313
```
1414

0 commit comments

Comments
 (0)