Skip to main content

Python Version PyPI License codecov Documentation Status Tests

⚽ sphere-n

Generator of Low discrepancy Sequence on S_n

Generate uniformly distributed points on n-dimensional spheres using low-discrepancy sequences. Perfect for Monte Carlo simulations, numerical integration, and computational geometry.

Quick Start

Installation

pip install sphere-n

Basic Usage

from sphere_n import Sphere3, SphereN, CylindN

# Generate points on 3-sphere
sgen = Sphere3([2, 3, 5])
sgen.reseed(42)
point = sgen.pop()
print(point)  # [0.291, 0.897, -0.333, 6.12e-17]

# Generate points on n-sphere (4D)
nsgen = SphereN([2, 3, 5, 7])
nsgen.reseed(42)
point = nsgen.pop()
print(point)  # 5-dimensional vector

# Batch generation (more efficient)
points = sgen.pop_batch(100)  # Generate 100 points at once

Use Cases

# Monte Carlo integration
import numpy as np
from sphere_n import SphereN

sgen = SphereN([2, 3, 5, 7])
points = np.array(sgen.pop_batch(10000))
values = [f(p) for p in points]
integral = np.mean(values)

# Compare with random sampling
random_points = np.random.randn(10000, 5)
random_points /= np.linalg.norm(random_points, axis=1)[:, None]
random_integral = np.mean([f(p) for p in random_points])

# LDS typically converges 2-3x faster

This library implements a generator for the generation of low-discrepancy sequences on n-dimensional spheres. Low-discrepancy sequences are utilized for the generation of points that are distributed uniformly across a given space. This technique is of significant value in a number of fields, including computer graphics, numerical integration, and Monte Carlo simulations.

The principal objective of this library is to facilitate the generation of points on the surface of spheres of varying dimensions, including three-dimensional and higher-dimensional spheres. The input required is the dimension of the sphere (n) and a set of base numbers to be used for the underlying sequence generation. The output is a series of vectors, with each vector representing a point on the surface of the n-dimensional sphere.

The library achieves this through a combination of mathematical calculations and recursive structures. The library utilizes a number of fundamental components, including:

  1. The VdCorput sequence generator produces a sequence of numbers that are evenly distributed between 0 and 1.
  2. Subsequently, the aforementioned numerical data is mapped onto the surface of a sphere through the use of interpolation functions.
  3. The SphereGen module represents an abstract base class that defines the common interface for all sphere generators.
  4. The recursive structures, namely Sphere3 and NSphere, facilitate the construction of higher-dimensional spheres from their lower-dimensional counterparts.

The primary logic flow begins with the construction of a SphereN object, which utilizes either a Sphere3 (for 3D) or a recursive process to generate lower-dimensional spheres for higher dimensions. In the generation of points, the VdCorput sequence is employed to obtain a base number, which is then subjected to a series of transformations involving sine, cosine, and interpolation in order to map it onto the surface of the sphere.

A noteworthy aspect of the library is its incorporation of caching (through the @cache decorator) to optimize performance by storing and reusing calculated values. Moreover, the library provides traits and structures that facilitate the adaptable deployment of the sphere generators. The SphereGen abstract base class serves to define a common interface for a variety of sphere generators, whereas the NSphere and SphereN structures are responsible for implementing the actual generation logic.

In conclusion, this library provides a sophisticated yet flexible method for generating evenly distributed points on high-dimensional spheres, which can be advantageous in numerous scientific and computational applications.

Dependencies

👀 See also

👉 Note

This project has been set up using PyScaffold 3.2.1. For details and usage information on PyScaffold see https://pyscaffold.org/.

Metadata

Release files for sphere-n 0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphere-n 0.8
File Size Uploaded Provenance Actions
sphere_n-0.8.tar.gz 7.9 MB With provenance Details for sphere_n-0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sphere-n 0.8
File Interpreter ABI Platform Actions
sphere_n-0.8-py3-none-any.whl Python 3 none any Details for sphere_n-0.8-py3-none-any.whl

Total release size: 7.9 MB

Release files / sphere_n-0.8.tar.gz

Download URL sphere_n-0.8.tar.gz
Size 7.9 MB
Tags Source
SHA-256 checksum
How to use checksums
9ac7c86a72cec50d261e2e4c0134a000d7d6a32958ed737ac09f5f4289f02a43
BLAKE2b-256 checksum
How to use checksums
5cccd261ed880fcb5f7d92a6da49f897dcb1c6b38ee10a6cd503936bc46180c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / sphere_n-0.8-py3-none-any.whl

Download URL sphere_n-0.8-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eaf7e86ed0e02b11f4915e980c7c9f7d830f8351bd22d07925cee650de14ecf4
BLAKE2b-256 checksum
How to use checksums
460e3af2ef59d54c90ae3ab34bcb21f1be99fb01d079c02ba8697bccbc997bf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for sphere-n 0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sphere_n-0.8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page