# Introduction to QimPy


## Set up

QimPy is already set-up within the BEAST python environment loaded in the tutorial,
but requires one additional step to use from Jupyter notebooks on NERSC.
This is based on the NERSC's [Jupyter environment setup instructions](https://docs.nersc.gov/services/jupyter/how-to-guides/#how-to-customize-a-kernel-with-a-helper-shell-script)

Save the following to `~/.local/share/jupyter/kernels/beast_pyenv/kernel-helper.sh`:

    #!/bin/bash
    module use /global/cfs/cdirs/m4025/Software/Perlmutter/modules
    module load beast-tutorial
    exec "$@"

and make it executable using `chmod +x ~/.local/share/jupyter/kernels/beast_pyenv/kernel-helper.sh`.
Then edit `~/.local/share/jupyter/kernels/beast_pyenv/kernel.json` so that it looks like:

    {
     "argv": [
      "{resource_dir}/kernel-helper.sh",     
      "python",
      "-m",
      "ipykernel_launcher",
      "-f",
      "{connection_file}"
     ],
     "display_name": "BEAST Python",
     "language": "python",
     "metadata": {
      "debugger": true
     }
    }

The only changes are in lines 3-4: this uses a wrapper script to load the module before creating the kernel within Jupyter.

## QimPy tutorials

See [the Qimpy website](https://qimpy.org/en/latest/tutorials) for tutorials that closely mimic the first few JDFTx tutorials, covering the basic DFT features already implemented in QimPy. To run them here, make a few modifications:

+ Use srun within an interactive session instead of mpirun to run the multi-process calculations. You can also just skip the mpirun altogether for a single-process run. Alternately, adapt the `gpu-*.job` files in this directory to run on as many GPUs as desired.

+ For visualization, instead of creating XSFs and visualizing offline using VESTA, adapt the `Visualize.ipynb` in this directory to load data from the checkpoint and visualize in x3d on the browser as shown yesterday.

## Larger calculations and scaling

See the `Pt-furfural` directory for a larger calculation that resembles a typical catalysis calculation in size.
This has inputs for both JDFTx and QimPy.
Set-up jobs based on yesterday's experience for JDFTx, and use the `gpu-*.job` provided alongside to run QimPy.
Check how the run time changes for JDFTx with increasing GPU counts, and compare this to QimPy.
