# VIPR Reflectometry Examples

Inference and compare examples covering X-ray and neutron reflectometry datasets for VIPR CLI and web app workflows.

## Available Example Configurations

- `PTCDI-C3_Reflectorch.yaml` - deterministic Reflectorch workflow for PTCDI-C3 X-ray reflectivity
- `Fe_Pt_DN_Reflectorch_narrow_bounds.yaml` - Fe/Pt spin-down with narrow first-layer thickness prior
- `Fe_Pt_DN_Reflectorch_broad_bounds.yaml` - Fe/Pt spin-down with broad first-layer thickness prior
- `Fe_Pt_DN_Reflectorch_Anaklasis.yaml` - Fe/Pt spin-down benchmark-aligned prior bounds
- `Fe_Pt_UP_Reflectorch.yaml` - Fe/Pt spin-up deterministic Reflectorch workflow
- `Fe_Ni_Au_DN_Reflectorch.yaml` - Fe/Ni/Au spin-down deterministic Reflectorch workflow
- `Fe_Ni_Au_UP_Reflectorch.yaml` - Fe/Ni/Au spin-up deterministic Reflectorch workflow
- `Fe_Pt_DN_NSF.yaml` - normalizing-flow workflow (NSF + clustering)
- `Fe_Pt_DN_compare.yaml` - compare workflow for precomputed Fe/Pt results

## VIPR CLI

### Requirements

- Python 3.10 or higher

### Installation

```bash
pip install git+https://codebase.helmholtz.cloud/vipr/vipr-core.git
pip install git+https://codebase.helmholtz.cloud/vipr/vipr-reflectometry-plugin.git
```

### Usage

Run an inference config:

```bash
vipr --config ./Fe_Pt_DN_Reflectorch_narrow_bounds.yaml inference run
```

Additional examples:

```bash
vipr --config ./PTCDI-C3_Reflectorch.yaml inference run
vipr --config ./Fe_Pt_DN_Reflectorch_broad_bounds.yaml inference run
vipr --config ./Fe_Pt_DN_NSF.yaml inference run
```

### Compare Example

The compare config expects these result IDs to exist:

- `Fe_Pt_DN_Reflectorch_narrow_bounds`
- `Fe_Pt_DN_Reflectorch_broad_bounds`
- `Fe_Pt_DN_NSF`

Generate them with:

```bash
vipr --config ./Fe_Pt_DN_Reflectorch_narrow_bounds.yaml inference run
vipr --config ./Fe_Pt_DN_Reflectorch_broad_bounds.yaml inference run
vipr --config ./Fe_Pt_DN_NSF.yaml inference run
```

Then run:

```bash
vipr --config ./Fe_Pt_DN_compare.yaml compare run
```

Result ID behavior:

- CLI example configs use fixed `vipr.result_id` values for deterministic output paths and compare compatibility.
- Re-running the same config via CLI overwrites the same result folder. Use a different `vipr.result_id` for each run if you want to keep multiple runs.
- In web app runs, `result_id` is assigned automatically from the task UUID, so this overwrite behavior does not apply there.

## Custom NSF Model Setup

`Fe_Pt_DN_NSF.yaml` expects the custom flow model `fxc34ran`.

1. Save the model files in:
   - config: `storage/reflectometry/flow_models/configs/fxc34ran.yaml`
   - weights: `storage/reflectometry/flow_models/saved_models/fxc34ran.pt`
2. Keep `load_model.parameters.config_name: fxc34ran` in the config.

Reference links:
- model config: <https://codebase.helmholtz.cloud/vipr/models/reflectometry-nsf-nr-maria/-/blob/main/models/fxc34ran/config.yaml?ref_type=heads>
- model weights: <https://codebase.helmholtz.cloud/vipr/models/reflectometry-nsf-nr-maria/-/blob/main/models/fxc34ran/model.pt?ref_type=heads>

## VIPR Web App

### Prerequisites

- Docker

### Start

```bash
git clone https://codebase.helmholtz.cloud/vipr/vipr-framework.git
cd vipr-framework
cp docker-compose.override.yml.example docker-compose.override.yml
mkdir -p storage
docker compose up --wait
```

Frontend: <http://localhost:5000>

### Running the Examples in the UI

1. Open <http://localhost:5000>
2. Click **Load Examples**
3. Select one of the YAML examples from this directory
4. Click **Run Inference**

`Fe_Pt_DN_compare.yaml` is for the CLI compare workflow (`compare run`), not for the standard inference run action.

If you add the custom NSF model files, restart containers:

```bash
docker compose restart
```
