Skip to content

Commit 35c1358

Browse files
authored
Merge pull request #44 from alchem0x2A/master
Update doc and schemes for socket mode
2 parents 7b1d467 + 5654f82 commit 35c1358

13 files changed

+4435
-22
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,5 @@ examples/ex1-ase/
782782
/*.psp8
783783
/test-1/
784784
/test-2/
785+
*.pt
786+
/README.html

README.md

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@
44
[![Unit tests](https://github.com/SPARC-X/SPARC-X-API/actions/workflows/installation_test.yml/badge.svg)](https://github.com/SPARC-X/SPARC-X-API/actions/workflows/installation_test.yml)
55
[![JSON-API](https://raw.githubusercontent.com/SPARC-X/SPARC-X-API/badges/badges/api_version.svg)](https://raw.githubusercontent.com/SPARC-X/SPARC-X-API/badges/badges/api_version.svg)
66

7+
# Table of Contents
8+
- [Installation](#installation)
9+
- [Setting Up Environment](#setting-up-the-environment)
10+
- [Basic Usage](#basic-usage-of-the-python-api)
11+
- [Advanced Usage: Socket Interface](#advanced-usage-sparc-x-api-as-a-socket-interface)
12+
- [Troubleshooting](#troubleshooting)
13+
- [Advanced Topics](#advanced-topics)
14+
- [Support and Contribution](#how-to-contribute)
15+
716
`SPARC-X-API` is an [ASE](https://wiki.fysik.dtu.dk/ase/)-compatible Python API for the density functional theory (DFT) code [SPARC](https://github.com/SPARC-X/SPARC). It offers:
817

918
1. ASE-compatible I/O format for SPARC files
10-
2. A JSON API interfacing with SPARC's C-code for parameter validation and conversion
11-
3. A comprehensive calculator interface for SPARC.
19+
2. A JSON Schema interfacing with SPARC's C-code for parameter validation and conversion
20+
3. A comprehensive calculator interface for SPARC with socket-communication support.
21+
22+
23+
[Fig. 1](#fig-1-schematic-drawing-for-the-architecture-of-the-sparc-x-api-package) provides an overlook of the components of `SPARC-X-API` and its relation with the SPARC C-code.
24+
25+
#### Fig. 1 Schematic drawing for the architecture of the `SPARC-X-API` package
26+
![scheme-sparc-api-outlook](doc/img/scheme_api_architecture.png)
27+
1228

1329

1430
## Installation:
@@ -53,7 +69,7 @@ To utilize the API for drive SPARC calculations, please
5369
following the [SPARC manual](https://github.com/SPARC-X/SPARC) for
5470
compilation and installation of the SPARC DFT code itself.
5571

56-
## Post-installation check
72+
### Post-installation check
5773

5874
We recommend the users to run a simple test after installation and setup:
5975

@@ -206,9 +222,9 @@ To learn more about the JSON schema design, please refer to [Advanced
206222
Topics](doc/advanced_topics.md).
207223

208224

209-
### 3. Calculator interface
225+
### 3. Calculator interface (File-IO mode)
210226

211-
`SPARC-X-API` offers a calculator interface that aligns with many
227+
`SPARC-X-API` offers a calculator interface based on file I/O that aligns with many
212228
other ASE calculators. If you've worked with ASE modules like `Vasp`,
213229
`QuantumEspresso`, or `GPAW`, you'll find this package intuitive,
214230
as shown in the following examples:
@@ -277,7 +293,7 @@ opt.run(fmax=0.02)
277293

278294
### 4. Command-line tools
279295

280-
`SPARC-X-API` provides a simple command wrapper `sparc-ase` to add
296+
A simple command wrapper `sparc-ase` is provided to add
281297
support of SPARC file formats to the `ase` cli tools. Simple
282298
replace `ase [subcommand] [args]` with `sparc-ase [subcommand] [args]`
283299
to access your SPARC bundle files as you would use for other file
@@ -286,9 +302,10 @@ for the visualization of atomistic structures. Depending on the
286302
bundle's contents, this could display individual atoms or multiple
287303
images.
288304

289-
Below is a screenshot showing the usage of `sparc-ase gui` to visualize a
305+
[Fig. 2](#fig-2-a-screenshot-of-the-sparc-ase-program) is a screenshot showing the usage of `sparc-ase gui` to visualize a
290306
short [MD trajectory](tests/outputs/NH3_sort_lbfgs_opt.sparc).
291307

308+
#### Fig 2. A screenshot of the `sparc-ase` program
292309
<img width="1200" alt="image" src="https://github.com/alchem0x2A/SPARC-X-API/assets/6829706/e72329ff-7194-4819-94f8-486ef2218844">
293310

294311
### 5. Parameters and units used in `SPARC-X-API`
@@ -362,15 +379,22 @@ calc = SPARC(xc="PBE", kpts=(9, 9, 9), h=0.25, directory="sparc-calc.sparc", con
362379
*Disclaimer: The socket communication feature in SPARC and SPARC-X-API are experimental and subject to changes until the release of v2.0 SPARC-X-API.*
363380

364381
### Overview
365-
Experienced users can now harness the power of SPARC and SPARC-X-API's
382+
Experienced users can harness the power of SPARC and SPARC-X-API's
366383
socket communication layer to build efficient and flexible
367384
computational workflows. By integrating a socket communication
368385
interface directly into SPARC, users can significantly reduce the
369386
overhead typically associated with file I/O during calculation
370387
restarts. This feature is particularly beneficial for tasks involving
371388
repetitive operations like structural optimization and saddle point
372389
searches, where traditional file-based communication can become a
373-
bottleneck.
390+
bottleneck. The underlying software architecture is shown in [Fig. 3](#fig-3-sparc-electronic-calculations-with-socket-communication-across-hybrid-computing-platforms):
391+
392+
#### Fig. 3. SPARC electronic calculations with socket communication across hybrid computing platforms
393+
394+
![scheme-sparc-socket](doc/img/scheme_socket_hetero.png)
395+
396+
397+
374398

375399
**Requirements**: the SPARC binary must be manually compiled from the source
376400
code with [socket
@@ -389,15 +413,18 @@ adheres to the [i-PI protocol](https://github.com/i-pi/i-pi)
389413
standard. Specifically, we implement the original i-PI protocol within
390414
the SPARC C-source code, while the python SPARC-X-API uses a
391415
backward-compatible protocol based on i-PI. The dual-mode design is aimed for both low-level and
392-
high-level interfacing of the DFT codes, providing the following features:
416+
high-level interfacing of the DFT codes, providing the following features as shown in [Fig. 4](#fig-4-overview-of-the-sparc-protocol-as-an-extension-to-the-standard-i-pi-protocol):
417+
418+
#### Fig. 4. Overview of the SPARC protocol as an extension to the standard i-PI protocol.
419+
![scheme-sparc-protocol](doc/img/scheme_sparc_protocol.png)
420+
421+
Based on the scenarios, the socket communication layer can be accessed via the following approaches as shown in [Fig. 5](#fig-5-different-ways-of-using-sparcs-socket-mode):
393422

394-
1. **Unified Interface**: A consistent interface for both client and server codes, simplifying user interaction across different modes.
395-
2. **Versatile Operation Modes:** Supports various modes (Local-only, Client, Server) to cater to diverse computational needs.
396-
3. **Seamless Calculation Restart:** Automates the restarting process on the client side, enhancing user convenience.
423+
#### Fig. 5. Different ways of using SPARC's socket mode.
424+
![scheme-sparc-modes](doc/img/scheme-SPARC-socket-modes.png)
397425

398-
Based on the user scenarios, the socket communication layer can be accessed via the following approaches:
399426

400-
1. **SPARC binary only**
427+
1. **SPARC binary only** ([Fig. 5](#fig-5-different-ways-of-using-sparcs-socket-mode) **a**)
401428

402429
SPARC binary with socket support can be readily coupled with any i-PI compatible socker server, such as
403430
`ase.calculators.socketio.SocketIOCalculator`, for example
@@ -419,7 +446,7 @@ Based on the user scenarios, the socket communication layer can be accessed via
419446
to be run on a single computer system.
420447

421448

422-
2. **Local-only Mode**
449+
2. **Local-only Mode** ([Fig. 5](#fig-5-different-ways-of-using-sparcs-socket-mode) **b**)
423450

424451
Ideal for standalone calculations, this mode simulates a conventional calculator while benefiting from socket-based efficiency.
425452

@@ -429,7 +456,7 @@ Based on the user scenarios, the socket communication layer can be accessed via
429456
```
430457
For most users we recommend using this mode when performing a calculation on a single HPC node.
431458

432-
3. **Client (Relay) Mode**
459+
3. **Client (Relay) Mode** ([Fig. 5](#fig-5-different-ways-of-using-sparcs-socket-mode) **c**)
433460

434461
In this mode, the `sparc.SPARC` calculator servers as a passive
435462
client which listens to a remote i-PI-compatible server. When
@@ -457,7 +484,7 @@ Based on the user scenarios, the socket communication layer can be accessed via
457484
automatically determine if it is necessary to restart the SPARC
458485
subprocess.
459486

460-
4. **Server Mode**
487+
4. **Server Mode** ([Fig. 5](#fig-5-different-ways-of-using-sparcs-socket-mode) **d**)
461488

462489
Paired with the client mode in (3), SPARC-X-API can be run as a
463490
socket server, isolated from the node that performs the
@@ -482,7 +509,8 @@ Based on the user scenarios, the socket communication layer can be accessed via
482509

483510
### (In-progress) Controlling SPARC routines from socket interface
484511

485-
Our SPARC socket protocol designs allows bidirectional control of
512+
As shown in [Fig. 4](#fig-4-overview-of-the-sparc-protocol-as-an-extension-to-the-standard-i-pi-protocol),
513+
the SPARC socket protocol designs allows bidirectional control of
486514
internal SPARC routines. Local- or server-mode `sparc.SPARC`
487515
calculators can communicate with the SPARC binary via functions like
488516
`set_params`. This can be useful for applications like on-the-fly

0 commit comments

Comments
 (0)