Skip to main content

Python client for the Inductiva API

Project description

Python package

linkedin_header

Large scale simulations made simple

Inductiva API provides open-source physical simulation from your laptop. With no configuration headaches, users can easily scale simulations to the next level with one line of code.

Whether you want to simulate pre-build scenarios to solve scientific/engineering problems or you are a power user of a specific open-source simulator, Inductiva API is here for you.

Scenarios

Inductiva API contains pre-built scenarios that define physical systems of interest ready to simulate. Users can choose some parameters and configure the system according to their needs, run the simulation using the most adequate resources and visualize the results.

Let's go through the currently available scenarios in Inductiva API.

Protein solvation

The protein solvation scenario models the dynamics of a protein whose structure is described by a PDB file. The protein is placed in a cubic box filled with water. If the protein has a non-zero electric charge, charged ions are added to the solution to neutralize the system. First, the system undergoes an energy minimization process to eliminate any steric clashes or structural issues within the protein-water system. After this, the position of the atoms in this system is updated according to Newton's equation in discrete time steps. The force that acts upon the particles is computed using standard molecular force fields.

Example

Initialize the scenario:

from inductiva import molecules

scenario = molecules.scenarios.ProteinSolvation("protein.pdb", temperature=300)

The user must provide the path for the PDB file corresponding to the protein to be simulated. Additionally, the temperature (in Kelvin) can be specified, which defaults to 300 K.

Run the simulation:

task = scenario.simulate(simulation_time_ns=10, n_steps_min=5000)

output = task.get_output()

Users can set the simulation duration (in ns) and the number of steps for the energy minimization.

Visualize the results:

view = ouptut.render_interactive(representation="ball+stick", add_backbone=True)

This yields an interactive visualization of the protein's trajectory that can be visualized and manipulated in a standard jupyter notebook. The user can specify the representation used for the protein and choose to add the backbone to the visualization.

Protein solvation simulation.

Wind tunnel

This scenario models the aerodynamics of an object inside a virtual wind tunnel for a given air flow velocity. Air is injected on a side wall of the wind tunnel, the flow changes according to the structure of the object and leaves through an outlet on the other side. The system is modelled with the steady-state equations for incompressible flow and the $k-\epsilon$ turbulence models.

Example

Initialize the scenario:

from inductiva import fluids

scenario = fluids.scenarios.WindTunnel(
    flow_velocity=[30, 0, 0],
    domain_geometry={"x": [-6, 12], "y": [-5, 5], "z": [0, 10]})

The user can specify the flow velocity vector (in m/s) and the domain geometry (in m).

Run the simulation:

task = scenario.simulate(object_path="vehicle.obj",
                         simulation_time=100,
                         output_time_step=50,
                         resolution="medium")

output = task.get_output()

The user must provide the path for the object to be inserted in the wind tunnel. Additionally, users can choose the total simulation time, the time step interval to output data and the resolution of the simulation.

After the simulation has finished, the user can obtain several metrics and visuals. An example here is given for a slice of the flow:

flow_slice = output.get_flow_slice(simulation_time=100,
                                   plane="xz")
flow_slice.render("velocity")

F1 car in WindTunnel

Fluid tank

This scenario simulates the motion of a fluid in a cubic or cylindrical tank. Fluid is injected into the tank via an inlet located at the top of the tank and flows out of the tank via an outlet located at the bottom of the tank. The motion of the fluid is controlled by gravity. The simulation is performed using the Smoothed Particle Hydrodynamics method.

Example

Initialize the scenario:

from inductiva import fluids
scenario = fluids.scenarios.FluidTank(shape=fluids.shapes.Cylinder(),
                                      fluid=fluids.WATER,
                                      fluid_level=0.5)

The user can specify the fluid (e.g. water, honey or oil), the fluid level (in meters), as well as the tank shape and its inlet and outlet properties.

Run the simulation:

task = scenario.simulate(simulation_time=5,
                           output_time_step=0.1,
                           resolution="medium")

output = task.get_output()

The user can specify the total simulation time and the time step between outputs (all in seconds). The user can also specify the resolution of the simulation (low, medium or high).

Visualize the results:

output.render()

Fluid tank simulation.

Simulators

Inductiva API has available several open-source simulators ready to use. Users familiar with the simulators can easily start running simulations with their previously prepared simulation configuration files. In this way, they can take advantage of performant hardware to speed up their simulation and exploration.

The simulators we provide are all open-source and have their own dedicated documentation.

Currently, we have available the following simulators:

If you would like other simulators to be added, contact us at simulations@inductiva.ai.

Example

Example of how to use the simulators:

from inductiva import fluids

simulator = fluids.simulators.DualSPHysics()

output_dir = simulator.run(input_dir="FlowCylinder",
                           sim_config_filename="CaseFlowCylinder_Re200_Def.xml",
                           output_dir="Flow",
                           device="gpu")

The user must specify the input directory, the simulation configuration file, the output directory and the device to run the simulation on.

Find more examples of simulations in the tutorials section.

Async API

Up until now, all examples have run synchronously, which allows users to get feedback while the simulation is running. However, this is not always the best option. For example, if the user wants to run a large number of simulations, it is better to run them asynchronously. This way, the user can launch all the simulations and then check the results when they are ready.

Let's look at an example using the wind tunnel scenario:

from inductiva import fluids

# Initialize scenario with defaults
scenario = fluids.scenarios.WindTunnel()

# Path to a set of objects
object_path = "path/to/vehicle.obj"

# Run simulation
task = scenario.simulate(object_path=object_path,
                         run_async=True)

# Blocking call to obtain the results
output = task.get_output()

In this way, the simulation is launched asynchronously and the user can continue with other tasks. When the user wants to retrieve the results, they can do so by calling the get_output() method. This method will block until the results are ready.

Running simulations asynchronously allows users to launch multiple simulations in parallel. Let's look at an example:

from inductiva import fluids

# Initialize scenario with defaults
scenario = fluids.scenarios.WindTunnel()

# Path to a set of vehicles
vehicle_path_list = ["vehicle_1.obj", "vehicle_2.obj", ..., "vehicle_1000.obj"]

tasks_list = []

for vehicle in vehicle_path_list:
    task = scenario.simulate(object_path=vehicle,
                             run_async=True)
    tasks_list.append(task)

All of the simulations will be launched in one go. The user can check the status of the simulations and retrieve the results when they are ready. Check the FAQ section for more information on how to do this.

Manage Resources

Inductiva API provides a simple way to manage the hardware resources used to run the simulations. Users can launch virtual machines, list the available machines and terminate them. This is a feature available only to admins. In this way, users do not need to wait for their simulations in a queue and can have full control of the hardware used.

Start your machines and run your simulations:

import inductiva

machines = inductiva.admin.launch_machines(name="test_machine",
                                           machine_type="c2-standard-16")

# Example with ProteinSolvation scenario
scenario = molecules.scenarios.ProteinSolvation(pdb_file, temperature=300)

output = scenario.simulate(simulation_time=10,
                           nsteps_minim = 5000,
                           resources=machine)

To launch resources users must select a name for the resources group, the type of machine to be launched and the number of machines, with the available options being the machines available in the Google Cloud Platform.

But do not forget to kill your machines:

machine.kill()

Installation

It is super simple to start using the API if you are already familiar with Python package management.

One just needs to do

pip install inductiva

and you are good to go! You are ready to start exploring our tutorial notebooks.

API access tokens

To use Inductiva API you will need an API token. Please request your demo API token via the following Google Form (we will reply to you by email):

Request API token

Before running simulations you just need to add the following line and you are good to go:

import inductiva

inductiva.api_key = "YOUR_API_KEY"

FAQ:

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

inductiva-0.2.3.tar.gz (5.1 MB view hashes)

Uploaded Source

Built Distribution

inductiva-0.2.3-py3-none-any.whl (5.4 MB view hashes)

Uploaded Python 3

Supported by

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