Skip to main content

Python bindings for ANARI

Project description

pynari - Python Bindings for ANARI

This project provides a python interface for the Khronos ANARI rendering API. This implementation currently requires a CUDA capable GPU (support for other backends will be added at a later time).

Usage - Quickstart

Assuming you already know how the ANARI API works (and that you have pip-installed this package) you can use ANARI in python as follows: First, import this package

import pynari as anari

(for all the steps below we assume you imported pynari as anari; this is not required, but please take this in mind for the examples below).

Once the package has been imported you can then create a ANARI "device" using

device = anari.newDevice('default')

(where desired, the string passed to 'newDevice' allows for selecting a specific ANARI device, see below; 'default' in this case will currently select a 'barney' backend, see https://github.com/ingowald/barney).

You can then create various ANARI actor objects through creator-methods on that device, such as, for example

world = device.newWorld()
mesh  = device.newGeometry('triangle')
array = device.newArray(anari.FLOAT32_VEC3,vertex)

etc.

Large arrays (such as vertex or index arrays for a triangle mesh) are expected to be populated using numpy, and wrapped in the ANARI 'array' type:

import numpy as np
...
vertex = np.array(...,dtype=np.float32)
mesh.setParameter('vertex.position',anari.ARRAY,
                  device.newArray(anari.FLOAT32_VEC3,vertex));
index  = np.array(...,dtype=np.uint32)
mesh.setParameter('primitive.index',anari.ARRAY,
                  device.newArray(anari.UINT32_VEC3,index));

The ANARI API, and how it is exposed in pynari

For a full description of what ANARI Objects are, what kind of objects exist, and how they work, please refer to the ANARI API Spec at https://registry.khronos.org/ANARI/specs/1.0/ANARI-1.0.html .

Since the official ANARI API is a plain C API we could not implement this literally, but had to make certain changes to make ti more "pythonic". Basically, these rules were applied (we will assume that the pynari module was imported under the alias as anari):

  • If there is a C constant/enum of name ANARI_XYZ, it is exposed as anari.XYZ. Example: the C enum of ANARI_FLOAT32 is anari.FLOAT32 in pynari.

  • If there is a C API function of anariFunctionXyz(ANARIDevice device, ...) it will be exposed as device.functionXyz(...). Note that in order to remain as close to the C-style API as possible we use CAML-case for function names, not python-casing. I.e., pynari uses device.functionXyz(...), not device.function_xyz(...).

Examples

For a list of several samples, please visit the pynari github repo https://github.com/ingowald/pynari

Supported and Built-in Devices

In ANARI, the 'device' abstraction aims at allowing for what is essentially the concept of a "driver"--i.e., a specific implementation of the hardware for a specific set of underlying hardware, or features. On the OS level, this is realized through installing of different ANARI implementations (e.g., barney or visrtx for CUDA GPUs, or ospray for Intel CPUs and GPUs), and then at runtime selecting one of then by passing a proper 'device name' identifier.

In pynari, we currently expose the device concept as follows:

  • If installed through pip, pynari comes with two "baked" devices that are pre-supplied with the pynari pip package, even if no ANARI devices are installed on the OS level: barney_cuda, and barney_cpu (see below).

  • the barney_cuda device (shipped with pynari's pip install) is a CUDA- and OptiX accelerated path tracer (see https://github.com/ingowald/barney). barney_cuda requires a OptiX-capable NVIDIA GPU with driver 535 or newer. Specifying device as 'barney_cuda' (or 'gpu' for short) will try to load this device, and throw an exception if this is not possible (eg, if no GPU can be found).

  • the barney_cpu device (also shipped with pynari's pip install) is a (much!) slower CPU-only fallback (based on embree) that should produce similar images. barney_cpu does not require an NVIDIA GPU, but will be significantly slower. Specifying barney_cpu (or cpu, for short) will try to load this device, and throw an exception if this did not succeed.

  • Specifying device as 'default' first try to load barney_cuda, and use that if possible; if not it will try to load barney_cpu.

  • For any device name other than default, barney_cuda, 'gpu', barney_cpu, or 'cpu', pynari will look for a system-installed ANARI implementation, and ask this to create a device of that name.

Issues

For any issues, bugs, or feature requests, please use the github pynari issue tracker.

Version History

v1.1.3

  • support for macOS

  • support for CPU-fallback when no GPU is present (in part on mac)

  • anari.newDevice(<devName>) will accept device names 'cuda' and 'cpu'. 'default' will try to load 'cuda', and if that fails, fall back to 'cpu'.

  • supports pass-through to system-installed anari device. Device names other than 'cuda', 'cpu', or 'default' will read the env-var ANARI_LIBRARY, and use system-installed anari library specified therein.

v1.1.4

  • updated to latest barney, with various fixes to lighting code and fixed structured volume data.

  • baked backends built for 'all-major' CUDA architectures.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pynari-1.2.2-cp313-cp313-win_amd64.whl (15.4 MB view details)

Uploaded CPython 3.13Windows x86-64

pynari-1.2.2-cp312-cp312-win_amd64.whl (15.4 MB view details)

Uploaded CPython 3.12Windows x86-64

pynari-1.2.2-cp39-cp39-win_amd64.whl (15.3 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file pynari-1.2.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pynari-1.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 15.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pynari-1.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7047ea23870bbbe062f98dd86881edcbafd24ad45eb66ac5b01de6f8ebe68457
MD5 b011f9b1fe3c8bd5d75148bb9e243310
BLAKE2b-256 25a06869ee3898f60702b9a1385f6afb777c94672b080b0f83e05dff6d2b3b88

See more details on using hashes here.

File details

Details for the file pynari-1.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pynari-1.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 15.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pynari-1.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 66a5302fd34d3190c1eb61d1a4c29381a9e18d132a47ffdd6c1127c41aa23977
MD5 ad92efed3ceac5127c72deeba73af5b5
BLAKE2b-256 0cbbf0c659239927c37081f492fd58382dd06435ecb77cd57e6572a997e03f3a

See more details on using hashes here.

File details

Details for the file pynari-1.2.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pynari-1.2.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 15.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pynari-1.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6484235f21e1cd73b9acfe711c753fe06b24ac70fb587896bfec82a9692345bc
MD5 c2299bdbe2d14eb9d68b05a3a4b71389
BLAKE2b-256 a1fe4120cf3db503d8a08e625983fd17036989b2d62aad7a4add8c3b46f975c1

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