Skip to content

Conversation

Copy link

Copilot AI commented Jan 16, 2026

Implements optional high-performance Zig core for tensor operations with Python FFI bindings. Library remains pure Python/JAX by default; Zig provides native performance when available.

Core Implementation

  • Zig library (src/zig/core.zig): Matrix operations (multiply, transpose, trace), metric tensors (Minkowski, spherical polar), C ABI exports
  • Python FFI (src/autograv/zig_ffi.py): ctypes bindings with NumPy integration, automatic library detection, graceful JAX fallback
  • Build system (build.zig): Cross-platform compilation, optimization levels, test suite

Infrastructure

  • Build scripts: Shell/PowerShell for Linux/macOS/Windows
  • CI/CD (.github/workflows/zig.yml): Multi-platform testing (Ubuntu, macOS, Windows), Zig 0.11.0/0.12.0, cross-compilation validation
  • Documentation: API reference, integration guide, development workflow, implementation details

Usage

import numpy as np
from autograv.zig_ffi import spherical_polar_metric_zig, is_zig_available

if is_zig_available():
    coords = np.array([5.0, np.pi/3, np.pi/2])
    metric = spherical_polar_metric_zig(coords)  # Native Zig performance
else:
    # Automatic fallback to existing JAX implementation
    from autograv import spherical_polar_metric
    metric = spherical_polar_metric(coords)

Architecture

Hybrid design: JAX for autodiff/GPU, optional Zig for performance-critical operations. Zig library usable standalone without Python. Foundation for future JAX/XLA custom operations.

Note: Building JAX/XLA with Zig as primary build system is impractical (complex C++ codebase with Bazel). Implementation focuses on Zig-based operations callable from Python, with documented path to XLA custom calls.

Security: CodeQL scan clean (0 alerts), workflow permissions scoped to contents: read.

Files: 15 modified, +2,879 lines (265 Zig, 489 Python, 1,609 docs, 417 build/CI, 99 config).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)
  • ziglang.org
    • Triggering command: /usr/bin/curl curl -L REDACTED -o /tmp/zig.tar.xz (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>rust/zig core pending</issue_title>
<issue_description>- maybe zig bindings for jax/xla?

  • FFI to python & publish to pypi
  • document new library, unique capabilities, git add, git commit, lint, prose lint, format, test (unit and integration), update docs, update CI, update usage instructions
  • the idea is to provide a zig core which can be used directly with zig (obviously) and through python via python-zig bindings

we need to figure out how to use Zig as a build system to successfully build jax and/or xla</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits January 16, 2026 02:46
Co-authored-by: bkataru <14833123+bkataru@users.noreply.github.com>
Co-authored-by: bkataru <14833123+bkataru@users.noreply.github.com>
Co-authored-by: bkataru <14833123+bkataru@users.noreply.github.com>
Co-authored-by: bkataru <14833123+bkataru@users.noreply.github.com>
Co-authored-by: bkataru <14833123+bkataru@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Zig bindings for JAX/XLA and Python integration Add Zig core with Python FFI for high-performance tensor operations Jan 16, 2026
Copilot AI requested a review from bkataru January 16, 2026 02:59
@bkataru bkataru added enhancement New feature or request help wanted Extra attention is needed labels Jan 16, 2026
@bkataru bkataru closed this Feb 3, 2026
@bkataru bkataru deleted the copilot/add-zig-bindings-for-jax-xla branch February 3, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust/zig core pending

2 participants