Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit a7ccec5

Browse files
committed
Added more docs, ported feature docs to document-features.
1 parent 4e2e386 commit a7ccec5

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/Simulation/qdk_sim_rs/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ crate-type = ["rlib", "staticlib", "cdylib"]
3232
# Optional build-time features: we use this to create Python and WASM bindings.
3333
[features]
3434
default = []
35+
36+
## Ensures that the crate is compatible with usage from WebAssembly.
3537
wasm = ["web-sys"]
38+
3639
# When Python bindings are enabled, we also need the pyo3 dependency.
40+
## Enables Python bindings for this crate.
3741
python = ["pyo3", "numpy"]
3842

3943
# Enable LaTeX on docs.rs.
4044
# See https://stackoverflow.com/a/54573800/267841 and
4145
# https://github.com/rust-num/num/pull/226/files for why this works.
4246
[package.metadata.docs.rs]
4347
rustdoc-args = [ "--html-in-header", "docs-includes/header.html", "--html-after-content", "docs-includes/after.html" ]
48+
features = ["document-features"]
4449

4550

4651
[profile.release]
@@ -82,6 +87,10 @@ thiserror = "1.0.30"
8287
miette = "4.3.0"
8388
anyhow = "1.0.56"
8489

90+
# We use document-features to automatically generate feature documentation from
91+
# Cargo.toml, following the example at
92+
document-features = { version = "0.2", optional = true }
93+
8594
[build-dependencies]
8695
built = "0.5.0"
8796

src/Simulation/qdk_sim_rs/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
To generate and view the documentation for this crate locally, please
55
run:
66
7-
$ cargo +nightly doc --features python --open
7+
$ cargo doc --features python,document-features --open
88
-->
99

1010
# Quantum Development Kit Preview Simulators
@@ -28,11 +28,6 @@ The [`c_api`] module allows for using the simulation functionality in this crate
2828

2929
Similarly, the [`python`] module allows exposing data structures in this crate to Python programs.
3030

31-
## Cargo Features
32-
33-
- **`python`**: Enables Python bindings for this crate.
34-
- **`wasm`**: Ensures that the crate is compatible with usage from WebAssembly.
35-
3631
## Representing quantum systems
3732

3833
This crate provides several different data structures for representing quantum systems in a variety of different conventions:
@@ -148,3 +143,5 @@ TODO
148143
- Stabilizer simulation not yet exposed via C API.
149144
- Test and microbenchmark coverage still incomplete.
150145
- Too many APIs `panic!` or `unwrap`, and need replaced with `Result` returns instead.
146+
147+
# Crate features

src/Simulation/qdk_sim_rs/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the MIT License.
33

44
#![cfg_attr(all(), doc = include_str!("../README.md"))]
5+
#![cfg_attr(
6+
feature = "document-features",
7+
cfg_attr(doc, doc = ::document_features::document_features!())
8+
)]
59
// Set linting rules for documentation. We will stop the build on missing docs,
610
// or docs with known broken links. We only enable this when all relevant
711
// features are enabled, otherwise the docs build will fail on links to

src/Simulation/qdk_sim_rs/src/linalg/decompositions/lu.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait LUDecomposable {
3636
type Output: LUDecomposition<Self::Elem, Self::OwnedRepr>;
3737

3838
/// The type used to represent errors in the decomposition.
39-
type Error;
39+
type Error: std::error::Error;
4040

4141
/// Performs an LU decomposition on the given type.
4242
fn lu(&self) -> Result<Self::Output, Self::Error>;
@@ -108,19 +108,41 @@ where
108108
}
109109
}
110110

111+
/// Represents the result of decomposing a square matrix $A$ into lower- and
112+
/// upper-triangular components $L$ and $U$, respectively.
111113
pub trait LUDecomposition<A, S>
112114
where
113115
S: Data<Elem = A>,
114116
A: Scalar,
115117
{
118+
/// The type used to represent errors in using this decomposition to solve
119+
/// matrix equations.
116120
type Error: std::error::Error;
121+
122+
/// The type resulting from using this decomposition to solve problems
123+
/// of the form $A\vec{x} = \vec{y}$.
117124
type VectorSolution;
125+
126+
/// The type resulting from using this decomposition to solve problems
127+
/// of the form $AX = Y$.
118128
type MatrixSolution;
119129

130+
/// The size $n$ of the matrix whose decomposition is represented. In
131+
/// particular, $L\Pi U$ is taken to be an $n \times n$ matrix, where $L$
132+
/// and $U$ are the lower- and upper-triangular factors, and where $\Pi$
133+
/// is a permutation matrix.
120134
fn order(&self) -> usize;
121135

122136
// TODO: Change signature to be in-place.
137+
/// Uses this decomposition to solve an equation of the form
138+
/// $A\vec{x} = \vec{y}$ for $\vec{x}$ given $\vec{y}$, where $A$ is
139+
/// implicitly represented by this decomposition.
123140
fn solve_vector(&self, rhs: &ArrayBase<S, Ix1>) -> Result<Self::VectorSolution, Self::Error>;
141+
142+
// TODO: Change signature to be in-place.
143+
/// Uses this decomposition to solve an equation of the form
144+
/// $AX = Y$ for $X$ given $Y$, where $A$ is
145+
/// implicitly represented by this decomposition.
124146
fn solve_matrix(&self, rhs: &ArrayBase<S, Ix2>) -> Result<Self::MatrixSolution, Self::Error>;
125147
}
126148

0 commit comments

Comments
 (0)