Skip to main content

Add your description here

Project description

Neural emulator for interstellar chemistry

This repository contains the code for using a conditional neural field as an emulator for instellar chemistry.

Installation

It should be enough to do:

pip install neural_chemistry

and all requirements should be installed.

Dependencies

In case it fails, note that this repository makes use of PyTorch and other Python packages. You can have them installed in your system, but we recommend to follow these instructions to have a working environment with everything needed for running the code.

Install Miniconda in your system. Go to https://docs.conda.io/projects/miniconda/en/latest/ and download the executable file for your system. For instance, for a typical Linux system, you should do:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

or

curl -lO https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Install Miniconda

chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

and follow the instructions for selecting the directory.

Create an environment and install the packages:

conda create -n chemistry python=3.10
conda activate chemistry
conda install -c conda-forge numpy tqdm 

Now install PyTorch. Go to https://pytorch.org/ and select from the properties of your system from the matrix (Linux/Mac/Windows, CPU/GPU, conda/pip). If you have an NVIDIA GPU card in your system, you can take advantage of the acceleration that it provides (around a factor 10 faster). For instance, in a system with an NVIDIA GPU card with CUDA drivers on version 12.1, you can install PyTorch using:

conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

or

pip3 install torch torchvision torchaudio

if using pip for the installation of packages.

In a CPU-only system:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

or

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

if using pip for the installation of packages.

To make then a local installation, simply clone the repository and type

pip install -e .

New version

An example of how to run the code is shown in example2.py, that we reproduce here:

# Define the number of random models 

n_models = 32
batch_size = 32

mols = [0, 1, 2, 3, 4, 5]

nh = 10.0**np.random.uniform(np.log10(1e4), np.log10(1e7), size=n_models)
T = np.random.uniform(10.0, 80.0, size=n_models)
crir = 10.0**np.random.uniform(np.log10(1e-17), np.log10(1e-15), size=n_models)
sulfur = 10.0**np.random.uniform(np.log10(7.5e-8), np.log10(1.5e-5), size=n_models)
uv_flux = 10.0**np.random.uniform(np.log10(0.1), np.log10(1e4), size=n_models)
Av = np.random.uniform(0.0, 18.0, size=n_models)

t = np.logspace(0, 7, 120)

net = neural_chemistry.ChemistryEmulator2(gpu=0, verbose=True)
abundance = net.evaluate(t, T, nh, crir, sulfur, uv_flux, Av, batch_size=batch_size, species=None)

abundance_subset = net.evaluate(t, T, nh, crir, sulfur, uv_flux, Av, batch_size=batch_size, species=[0,1,2,3,4,5])

We choose 64 models with random properties inside the range of validity. Select the output times and call the emulator. The batch_size defines the number of models that will be computed in parallel. This depends on the amount of memory you have but it can be a large number. The keyword species indicates a list of the indices of which species you want to compute, from the list of 250 species that can be found in list_molecules:20ene24.txt. If abstent or set to None, all species are computed.

Old version

An example of how to run the old code is shown in example.py, that we reproduce here:

# Define the number of random models 
n_models = 64
batch_size = 32

nh = 10.0**np.random.uniform(np.log10(1e4), np.log10(1e7), size=n_models)
T = np.random.uniform(10.0, 80.0, size=n_models)
crir = 10.0**np.random.uniform(np.log10(1e-17), np.log10(1e-15), size=n_models)
sulfur = 10.0**np.random.uniform(np.log10(1.5e-5), np.log10(7.5e-8), size=n_models)
uv_flux = 10.0**np.random.uniform(np.log10(0.1), np.log10(1e4), size=n_models)

t = np.logspace(0, 7, 64)

net = emulator.ChemistryEmulator(gpu=0, batch_size=32)
abundance = net.evaluate(t, T, nh, crir, sulfur, uv_flux, batch_size=32, species=None)

Weights

The weights are downloadad automatically the first time any of the emulators is used.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neural_chemistry-1.0.2.tar.gz (231.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neural_chemistry-1.0.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file neural_chemistry-1.0.2.tar.gz.

File metadata

  • Download URL: neural_chemistry-1.0.2.tar.gz
  • Upload date:
  • Size: 231.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for neural_chemistry-1.0.2.tar.gz
Algorithm Hash digest
SHA256 989242bb14fda0ab303e6b14fcb85fada00dd122b7e88b56c4716477234b6e4f
MD5 74cb25b1f95632264777d71bafefff0f
BLAKE2b-256 c660ba189a96f77f6a0d9918f6732029fb98f80c69d9b75b59f9a35874142a15

See more details on using hashes here.

File details

Details for the file neural_chemistry-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for neural_chemistry-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 12b06987cfb9932b0fba47fbf28c5563d30d34331a8cdd411959e49cc6ced0ff
MD5 601e57e91b0e4de1c4a53c4d8083e5d2
BLAKE2b-256 06bdec7ff3f162dae50674f7282b1c85d61355a8cc946f3250aa32d2957bf47f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page