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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions source/pip/qsharp/magnets/geometry/hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Hyperedge:
vertices: Sorted list of vertex indices connected by this hyperedge.

Example:

.. code-block:: python
>>> edge = Hyperedge([2, 0, 1])
>>> edge.vertices
Expand Down Expand Up @@ -60,7 +60,7 @@ class Hypergraph:
_edge_list: Set of hyperedges for efficient membership testing.

Example:

.. code-block:: python
>>> edges = [Hyperedge([0, 1]), Hyperedge([1, 2]), Hyperedge([0, 2])]
>>> graph = Hypergraph(edges)
Expand Down Expand Up @@ -113,7 +113,7 @@ def edges(self, part: int = 0) -> Iterator[Hyperedge]:
return iter(self._edge_list)

def __str__(self) -> str:
return f"Hypergraph with {self.nvertices()} vertices and {self.nedges()} edges."
return f"Hypergraph with {self.nvertices} vertices and {self.nedges} edges."

def __repr__(self) -> str:
return f"Hypergraph({list(self._edges)})"
24 changes: 12 additions & 12 deletions source/pip/tests/magnets/test_hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,36 @@ def test_hypergraph_init_basic():
"""Test basic Hypergraph initialization."""
edges = [Hyperedge([0, 1]), Hyperedge([1, 2])]
graph = Hypergraph(edges)
assert graph.nedges() == 2
assert graph.nvertices() == 3
assert graph.nedges == 2
assert graph.nvertices == 3


def test_hypergraph_empty_graph():
"""Test hypergraph with no edges."""
graph = Hypergraph([])
assert graph.nedges() == 0
assert graph.nvertices() == 0
assert graph.nedges == 0
assert graph.nvertices == 0


def test_hypergraph_nedges():
"""Test edge count."""
edges = [Hyperedge([0, 1]), Hyperedge([1, 2]), Hyperedge([2, 3])]
graph = Hypergraph(edges)
assert graph.nedges() == 3
assert graph.nedges == 3


def test_hypergraph_nvertices():
"""Test vertex count with unique vertices."""
edges = [Hyperedge([0, 1]), Hyperedge([2, 3])]
graph = Hypergraph(edges)
assert graph.nvertices() == 4
assert graph.nvertices == 4


def test_hypergraph_nvertices_with_shared_vertices():
"""Test vertex count when edges share vertices."""
edges = [Hyperedge([0, 1]), Hyperedge([1, 2]), Hyperedge([0, 2])]
graph = Hypergraph(edges)
assert graph.nvertices() == 3
assert graph.nvertices == 3


def test_hypergraph_vertices_iterator():
Expand Down Expand Up @@ -135,8 +135,8 @@ def test_hypergraph_single_vertex_edges():
"""Test hypergraph with self-loop edges."""
edges = [Hyperedge([0]), Hyperedge([1]), Hyperedge([2])]
graph = Hypergraph(edges)
assert graph.nedges() == 3
assert graph.nvertices() == 3
assert graph.nedges == 3
assert graph.nvertices == 3


def test_hypergraph_mixed_edge_sizes():
Expand All @@ -147,14 +147,14 @@ def test_hypergraph_mixed_edge_sizes():
Hyperedge([3, 4, 5]), # 3 vertices (triple)
]
graph = Hypergraph(edges)
assert graph.nedges() == 3
assert graph.nvertices() == 6
assert graph.nedges == 3
assert graph.nvertices == 6


def test_hypergraph_non_contiguous_vertices():
"""Test hypergraph with non-contiguous vertex indices."""
edges = [Hyperedge([0, 10]), Hyperedge([5, 20])]
graph = Hypergraph(edges)
assert graph.nvertices() == 4
assert graph.nvertices == 4
vertices = list(graph.vertices())
assert vertices == [0, 5, 10, 20]
5 changes: 4 additions & 1 deletion source/qre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ edition.workspace = true
license.workspace = true

[dependencies]
rustc-hash = { workspace = true }
num-traits = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }


[dev-dependencies]

Expand Down
10 changes: 6 additions & 4 deletions source/qre/src/isa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{

use num_traits::FromPrimitive;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -158,7 +159,7 @@ impl FromIterator<InstructionConstraint> for ISARequirements {
}
}

#[derive(Clone)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Instruction {
id: u64,
encoding: Encoding,
Expand Down Expand Up @@ -328,13 +329,14 @@ impl InstructionConstraint {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Encoding {
#[default]
Physical,
Logical,
}

#[derive(Clone)]
#[derive(Clone, Serialize, Deserialize)]
pub enum Metrics {
FixedArity {
arity: u64,
Expand All @@ -351,7 +353,7 @@ pub enum Metrics {
},
}

#[derive(Clone)]
#[derive(Clone, Serialize, Deserialize)]
pub enum VariableArityFunction<T> {
Constant { value: T },
Linear { slope: T },
Expand Down
43 changes: 43 additions & 0 deletions source/qre/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use thiserror::Error;

mod isa;
mod pareto;
pub use pareto::{
ParetoFrontier as ParetoFrontier2D, ParetoFrontier3D, ParetoItem2D, ParetoItem3D,
};
mod result;
pub use result::{EstimationCollection, EstimationResult, FactoryResult};
mod trace;
pub use isa::{
ConstraintBound, Encoding, ISA, ISARequirements, Instruction, InstructionConstraint,
VariableArityFunction,
};
pub use trace::instruction_ids;
pub use trace::{Block, LatticeSurgery, PSSPC, Property, Trace, TraceTransform, estimate_parallel};

/// A resourc estimation error.
#[derive(Clone, Debug, Error, PartialEq)]
pub enum Error {
/// The resource estimation exceeded the maximum allowed error.
#[error("resource estimation exceeded the maximum allowed error: {actual_error} > {max_error}")]
MaximumErrorExceeded { actual_error: f64, max_error: f64 },
/// Missing instruction in the ISA.
#[error("requested instruction {0} not present in ISA")]
InstructionNotFound(u64),
/// Cannot extract space from instruction.
#[error("cannot extract space from instruction {0} for fixed arity")]
CannotExtractSpace(u64),
/// Cannot extract time from instruction.
#[error("cannot extract time from instruction {0} for fixed arity")]
CannotExtractTime(u64),
/// Cannot extract error rate from instruction.
#[error("cannot extract error rate from instruction {0} for fixed arity")]
CannotExtractErrorRate(u64),
/// Factory time exceeds algorithm runtime
#[error(
"factory instruction {id} time {factory_time} exceeds algorithm runtime {algorithm_runtime}"
)]
FactoryTimeExceedsAlgorithmRuntime {
id: u64,
factory_time: u64,
algorithm_runtime: u64,
},
/// Unsupported instruction in trace transformation
#[error("unsupported instruction {id} in trace transformation '{name}'")]
UnsupportedInstruction { id: u64, name: &'static str },
}
Loading