Skip to content

Commit 67368f7

Browse files
authored
Feat/pecos num (#201)
* Add Rust general numerical methods
1 parent 480a058 commit 67368f7

File tree

22 files changed

+2876
-54
lines changed

22 files changed

+2876
-54
lines changed

Cargo.lock

Lines changed: 373 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ tket = "0.16"
8585
tket-qsystem = { version = "0.22", default-features = false }
8686
ndarray = "0.16"
8787
anyhow = "1"
88+
89+
# Numerical computing dependencies (for pecos-num)
90+
peroxide = "0.40"
91+
roots = "0.0.8"
92+
levenberg-marquardt = "0.15"
93+
nalgebra = "0.34"
8894
cxx = "1.0.187"
8995
cxx-build = "1.0.187"
9096
reqwest = { version = "0.12", default-features = false, features = ["blocking", "rustls-tls"] }
@@ -126,6 +132,7 @@ pecos-rslib = { version = "0.1.1", path = "python/pecos-rslib/rust" }
126132
pecos-wasm = { version = "0.1.1", path = "crates/pecos-wasm" }
127133
pecos-build-utils = { version = "0.1.1", path = "crates/pecos-build-utils" }
128134
pecos-llvm-utils = { version = "0.1.1", path = "crates/pecos-llvm-utils" }
135+
pecos-num = { version = "0.1.1", path = "crates/pecos-num" }
129136

130137
# Decoder crates
131138
pecos-decoder-core = { version = "0.1.1", path = "crates/pecos-decoder-core" }

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ decoder-cache-clean: ## Clean decoder download cache
327327
.PHONY: pytest
328328
pytest: ## Run tests on the Python package (not including optional dependencies). ASSUMES: previous build command
329329
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/quantum-pecos/tests/ --doctest-modules -m "not optional_dependency"
330-
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/pecos-rslib/tests/
330+
@$(ADD_LLVM_TO_PATH) uv run --with scipy --with numpy pytest ./python/pecos-rslib/tests/
331331
@$(ADD_LLVM_TO_PATH) uv run pytest ./python/slr-tests/ -m "not optional_dependency"
332332

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

342342
# .PHONY: pytest-doc
343343
# pydoctest: ## Run doctests with pytest. ASSUMES: A build command was ran previously. ASSUMES: previous build command

crates/pecos-num/Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "pecos-num"
3+
version.workspace = true
4+
edition.workspace = true
5+
authors.workspace = true
6+
homepage.workspace = true
7+
repository.workspace = true
8+
license.workspace = true
9+
keywords.workspace = true
10+
categories.workspace = true
11+
readme.workspace = true
12+
description = "Numerical computing support for PECOS quantum error correction simulations"
13+
14+
[dependencies]
15+
# Comprehensive numerical computing library (for Newton, polynomial fitting)
16+
peroxide.workspace = true
17+
18+
# Root finding (for Brent's method only - Peroxide doesn't have it)
19+
roots.workspace = true
20+
21+
# Curve fitting (scipy-compatible API, better match than Peroxide's AD-based optimizer)
22+
levenberg-marquardt.workspace = true
23+
nalgebra.workspace = true # Required by levenberg-marquardt
24+
25+
# Array interface (for API compatibility and return types)
26+
ndarray.workspace = true
27+
28+
# Logging
29+
log.workspace = true
30+
31+
[lints]
32+
workspace = true

crates/pecos-num/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# pecos-num
2+
3+
`pecos-num` provides numerical computing support for PECOS quantum error correction simulations.
4+
5+
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.
6+
7+
## Features
8+
9+
- Root finding algorithms (Brent's method, Newton-Raphson)
10+
- Non-linear curve fitting (Levenberg-Marquardt)
11+
- Polynomial fitting and evaluation
12+
- Built on robust Rust numerical libraries (Peroxide, levenberg-marquardt, nalgebra)
13+
14+
## Usage
15+
16+
This is an **internal crate** used by:
17+
- `pecos` - The main PECOS metacrate (via prelude)
18+
- `pecos-rslib` - Python bindings exposing numerical functions
19+
20+
For direct usage in Rust:
21+
22+
```rust
23+
use pecos_num::prelude::*;
24+
25+
// Root finding with Brent's method
26+
let root = brentq(|x| x * x - 2.0, 0.0, 2.0, None).unwrap();
27+
28+
// Curve fitting
29+
let result = curve_fit(
30+
|x, params| params[0] * x + params[1],
31+
xdata.view(),
32+
ydata.view(),
33+
p0.view(),
34+
None
35+
).unwrap();
36+
```

0 commit comments

Comments
 (0)