Skip to main content

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

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 will automatically:

  1. Install Julia if not already installed (via juliacall)
  2. Install the DualPerspective.jl Julia package
  3. Perform precompilation to ensure fast performance from the first run

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.random.rand(n)
x0 = np.pi * x0 / np.sum(x0)  # Rescale to sum to pi
A = np.random.rand(m, n)
b = A @ x0

# 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}")

Reinstalling the DualPerspective.jl package

To reinstall or update the DualPerspective.jl package, you can use the following command:

pip install --force-reinstall DualPerspective

Performance Considerations

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

Features

  • Easy-to-use Python interface for DualPerspective.jl
  • Automatic installation of Julia dependencies
  • Support for large-scale KL divergence problems
  • Integration with NumPy arrays
  • Precompilation for consistent performance

Requirements

  • Python 3.7+
  • NumPy
  • juliacall

License

This project is licensed under the MIT License.

Advanced Usage

Reinstalling the Julia Package

If you need to update the underlying Julia package to the latest version from the repository, you can use the following command:

from DualPerspective.core import _reinstall_dualperspective
_reinstall_dualperspective()

This will pull the latest version of DualPerspective.jl from the GitHub repository and reinstall it in your Julia environment. This can be useful for:

  • Getting the latest bugfixes
  • Testing new features before they're included in an official Python package release
  • Troubleshooting version compatibility issues

Note: While this function has a leading underscore (indicating it's "private"), it's documented here for users who need this functionality.

Development

Building and Publishing the Package

Follow these steps to build and publish new versions of the package to PyPI:

Prerequisites

Make sure you have the necessary tools:

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
pip install -e .

# Or install the built wheel
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
pip install --index-url https://test.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/*

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.2.tar.gz (5.5 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.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dualperspective-0.1.2.tar.gz
  • Upload date:
  • Size: 5.5 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.2.tar.gz
Algorithm Hash digest
SHA256 255395e5e188567a1c1dbe9fa7ab9ef645635512f4dec0bb11ee9b007f7d0d8d
MD5 9c2a7243de986be905f0dcaa2a9f8689
BLAKE2b-256 66fb23f90afd80cf16cd4dd64db47cf598af21632cdcb8c072e3990efdd13a70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dualperspective-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 04fc4584e673ebe98e89eabe2e2586f2e95f6487b44afd9847058e7f96eeb49c
MD5 74dfc967a3a57052fca933f72ef5d346
BLAKE2b-256 985cf330d878616118ae4fe3b792e3a33b2c6e2bdd47edbf468387331467add9

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