Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
418 changes: 373 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ tket = "0.16"
tket-qsystem = { version = "0.22", default-features = false }
ndarray = "0.16"
anyhow = "1"

# Numerical computing dependencies (for pecos-num)
peroxide = "0.40"
roots = "0.0.8"
levenberg-marquardt = "0.15"
nalgebra = "0.34"
cxx = "1.0.187"
cxx-build = "1.0.187"
reqwest = { version = "0.12", default-features = false, features = ["blocking", "rustls-tls"] }
Expand Down Expand Up @@ -126,6 +132,7 @@ pecos-rslib = { version = "0.1.1", path = "python/pecos-rslib/rust" }
pecos-wasm = { version = "0.1.1", path = "crates/pecos-wasm" }
pecos-build-utils = { version = "0.1.1", path = "crates/pecos-build-utils" }
pecos-llvm-utils = { version = "0.1.1", path = "crates/pecos-llvm-utils" }
pecos-num = { version = "0.1.1", path = "crates/pecos-num" }

# Decoder crates
pecos-decoder-core = { version = "0.1.1", path = "crates/pecos-decoder-core" }
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ decoder-cache-clean: ## Clean decoder download cache
.PHONY: pytest
pytest: ## Run tests on the Python package (not including optional dependencies). ASSUMES: previous build command
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/quantum-pecos/tests/ --doctest-modules -m "not optional_dependency"
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/pecos-rslib/tests/
@$(ADD_LLVM_TO_PATH) uv run --with scipy --with numpy pytest ./python/pecos-rslib/tests/
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/slr-tests/ -m "not optional_dependency"

.PHONY: pytest-dep
Expand All @@ -337,7 +337,7 @@ pytest-dep: ## Run tests on the Python package only for optional dependencies. A
.PHONY: pytest-all
pytest-all: ## Run all tests on the Python package ASSUMES: previous build command
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/quantum-pecos/tests/ -m ""
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/pecos-rslib/tests/
@$(ADD_LLVM_TO_PATH) uv run --with scipy --with numpy pytest ./python/pecos-rslib/tests/

# .PHONY: pytest-doc
# pydoctest: ## Run doctests with pytest. ASSUMES: A build command was ran previously. ASSUMES: previous build command
Expand Down
32 changes: 32 additions & 0 deletions crates/pecos-num/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "pecos-num"
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true
readme.workspace = true
description = "Numerical computing support for PECOS quantum error correction simulations"

[dependencies]
# Comprehensive numerical computing library (for Newton, polynomial fitting)
peroxide.workspace = true

# Root finding (for Brent's method only - Peroxide doesn't have it)
roots.workspace = true

# Curve fitting (scipy-compatible API, better match than Peroxide's AD-based optimizer)
levenberg-marquardt.workspace = true
nalgebra.workspace = true # Required by levenberg-marquardt

# Array interface (for API compatibility and return types)
ndarray.workspace = true

# Logging
log.workspace = true

[lints]
workspace = true
36 changes: 36 additions & 0 deletions crates/pecos-num/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# pecos-num

`pecos-num` provides numerical computing support for PECOS quantum error correction simulations.

This crate brings together numerical computing dependencies and implements functionality needed for QEC analysis in PECOS, including threshold fitting, data analysis, and optimization. It provides APIs with similar functionality to scipy and numpy for numerical operations.

## Features

- Root finding algorithms (Brent's method, Newton-Raphson)
- Non-linear curve fitting (Levenberg-Marquardt)
- Polynomial fitting and evaluation
- Built on robust Rust numerical libraries (Peroxide, levenberg-marquardt, nalgebra)

## Usage

This is an **internal crate** used by:
- `pecos` - The main PECOS metacrate (via prelude)
- `pecos-rslib` - Python bindings exposing numerical functions

For direct usage in Rust:

```rust
use pecos_num::prelude::*;

// Root finding with Brent's method
let root = brentq(|x| x * x - 2.0, 0.0, 2.0, None).unwrap();

// Curve fitting
let result = curve_fit(
|x, params| params[0] * x + params[1],
xdata.view(),
ydata.view(),
p0.view(),
None
).unwrap();
```
Loading
Loading