Skip to main content

Python interface for DualPerspective.jl - A Julia package for obtaining maximum-entropy solutions to underdetermined linear systems.

Project description

DualPerspective Python Package

Python interface for DualPerspective.jl, a Julia package for solving large-scale KL divergence problems.

Installation

pip install DualPerspective

The package automatically:

  1. Installs Julia if not already installed (via juliacall)
  2. Installs the DualPerspective.jl Julia package from the official registry

TODO:

  • Precompiles dependencies for fast performance from the first run

Basic Usage

import numpy as np
from DualPerspective import DPModel, solve, regularize

# Generate sample data
np.random.seed(42)
n = 200  # dimension of solution
m = 100  # number of measurements
x0 = np.pi * (tmp := np.random.rand(n)) / np.sum(tmp)
A = np.random.rand(m, n)
b = A @ x0  # measurements

# Create and solve the problem
model = DPModel(A, b)
regularize(model, 1e-4)  # Optional: set regularization parameter
solution = solve(model)

print(f"Sum of solution: {np.sum(solution):.6f} (should be ≈ {np.pi:.6f})")
print(f"Optimal solution shape: {solution.shape}")

Features

  • Python interface for DualPerspective.jl
  • Automatic installation of Julia dependencies
  • Integration with NumPy arrays

Performance Considerations

This package uses Julia's precompilation to ensure good performance. The first import may take slightly longer as it sets up the Julia environment, but subsequent operations should be fast.

Advanced Usage

Updating DualPerspective.jl

To reinstall or update the Julia package:

uv pip install --force-reinstall DualPerspective

Local Development

By default, the Python interface uses the version of DualPerspective.jl from the Julia registry. For local development, use the environment variable DUALPERSPECTIVE_USE_LOCAL:

export DUALPERSPECTIVE_USE_LOCAL=true

Or, to set it temporarily for a single command:

DUALPERSPECTIVE_USE_LOCAL=true python [command]

Building and Publishing

Prerequisites

Install the necessary tools:

uv pip install --upgrade build twine

Building the Package

Build both wheel and source distributions:

python -m build

This creates distribution files in the dist/ directory.

Testing Locally

Before publishing, test the package locally:

# Install in development mode
source venv/bin/activate
uv pip install -e .

# Or install the built wheel
uv pip install dist/DualPerspective-0.1.1-py3-none-any.whl

Publishing to TestPyPI (Optional)

To test the publishing process:

twine upload --repository-url https://test.pypi.org/legacy/ dist/*

# Install from TestPyPI
uv pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ DualPerspective

Publishing to PyPI

Once tested and ready:

twine upload dist/*

Updating for New Releases

  1. Update the version number in pyproject.toml
  2. Make code changes
  3. Rebuild: python -m build
  4. Upload: twine upload dist/*

Requirements

  • Python 3.7+
  • NumPy
  • juliacall

License

This project is licensed under the MIT License.

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

dualperspective-0.1.4.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

dualperspective-0.1.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file dualperspective-0.1.4.tar.gz.

File metadata

  • Download URL: dualperspective-0.1.4.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for dualperspective-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b6cd989c5b40c43cf6df60c199a1278188c6ea2fcc0fffa2110cba8b9bc50af7
MD5 cc73f0b15c1ec5b9519734d1962921f0
BLAKE2b-256 e4fbbdad43891f9749a7bca4d76ab4f884d84f0051e044ad391eff571cd83a76

See more details on using hashes here.

File details

Details for the file dualperspective-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for dualperspective-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3071e992575db417476452cd060949a3e4daad873aa58d6c3a0e8af074edfa77
MD5 0309c79e3f93fd88994b5e4c2562d2c8
BLAKE2b-256 b580d8eeed904d8b2fdefc90af77e6a1788ee2232c774179cd15b9d896ef8d00

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