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.4-cp313-cp313-win_amd64.whl (16.0 MB view details)

Uploaded CPython 3.13Windows x86-64

pynari-1.2.4-cp313-cp313-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

pynari-1.2.4-cp313-cp313-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynari-1.2.4-cp312-cp312-win_amd64.whl (16.0 MB view details)

Uploaded CPython 3.12Windows x86-64

pynari-1.2.4-cp312-cp312-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pynari-1.2.4-cp311-cp311-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pynari-1.2.4-cp310-cp310-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pynari-1.2.4-cp39-cp39-win_amd64.whl (16.0 MB view details)

Uploaded CPython 3.9Windows x86-64

pynari-1.2.4-cp39-cp39-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pynari-1.2.4-cp38-cp38-manylinux_2_34_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

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

File metadata

  • Download URL: pynari-1.2.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 16.0 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0a56a62ce6f6da22ba40fdf8a5b12aa598003550aefb19190350a983a1efa11f
MD5 923b5979573219c19ff94eddd35c7823
BLAKE2b-256 e0d58cc3a434255d59a534c04a5567b075646d55a505cd3a671171c0acfaee78

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 98e14b393111fe75bb52a28368c5037189ba3d4c347d257d9985dc515842e43a
MD5 85fb5ae3c05e6117010ccc04a9e3423d
BLAKE2b-256 307375e765a07b3a86e3199948e4c9218769bbc3415a9af5b07d0f9c31f7e473

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34ef5c134668e92660ed27e3305f68c3dd93d448a977d50bf08611b164491650
MD5 4cafc278eb81c2b5a3f6915d748042e9
BLAKE2b-256 2a41a08bfee1f11d8cdef010dda4a96497b3a4bc37e486af5a75bfe0f6d28e42

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pynari-1.2.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 16.0 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 016d8588a8c065e3fb864e84af7af92bbb021ef09ed9a288531a897dcc9f0390
MD5 c4b8ffd8d6c7b47fad50080ab9dc5c75
BLAKE2b-256 61b6f5e4388c9501fa2962dc495965e4c131fc7b363fec52c2186db9084561ba

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9a6cc5e54650a244cddbc6924256738c04061a24b7aa37c715fe3aabc86769c1
MD5 5ff7633967edf89a9d7a4b1e8117a629
BLAKE2b-256 e266b7e3855a5044ad6ff0026e97e3524c38781ea800d59de2f06c218230bf7e

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f75df7d0d65407097883971d853f54a13d19cd747cd546a25644a7518caffe07
MD5 7cd50e9d7e531fdf87237053e957e54a
BLAKE2b-256 bde75d38387aae588bfdfc0b77aba99234d26e0cc48a53b8e3a2a0d556b1b9d4

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 346a258a6637e5626d697726f49e772ad586884305abd3470bd5ea19a72b6080
MD5 34f53d317ebca86e1426e21015db5147
BLAKE2b-256 7ab30f9cf5aca64538a48e4121033996edfaa3211e57962eaac4f79e087547ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pynari-1.2.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 16.0 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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 21a6ff76da9f4890ee457c797c73dff18e178ebc22d85b833acaf764f8973820
MD5 51f6a045f3e4fe5992ddbd9a38b35856
BLAKE2b-256 ad20ff5234600c2e40dc84ccd7d71fb25923da6c831fe748bf667c99e1b4f0fc

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 90fd2bb8f41028886f3663fb253f2bc8c8aeb70a1f7c1225235ae656503d6bb0
MD5 f7854c04b5c0486f9f53c2209840959e
BLAKE2b-256 48bfbdad15734fa1c7c43ba48e243977c39a02aee37f51957c8dd6ef2ecb82c6

See more details on using hashes here.

File details

Details for the file pynari-1.2.4-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pynari-1.2.4-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 eb6345994203af6718e2579f92d94d752177aca0fc952dbdfb85f7f97220efee
MD5 d669f26c978c5d10fbf710f61dd9bc09
BLAKE2b-256 ed243d0c3aff1d5be7b3fb5bf76d2626f02a5b972eb3519aad5936ce6146c6c7

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