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

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ path = "src/lib.rs"
[dependencies]
bitvec = "1.0.1"
itertools = "0.13.0"
petgraph = { git = "https://github.com/daehiff/petgraph", branch = "add-mst-prim" }
petgraph = { version = "0.8.0", features = ["stable_graph"]}
typenum = "1.17.0"

[dev-dependencies]
criterion = "0.5.1"
rand = "0.9.0"

[[bench]]
name = "clifford_tableau"
Expand Down
5 changes: 4 additions & 1 deletion benches/clifford_tableau.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::connectivity::connectivity_benchmark;
use bitvec::bitvec;
use bitvec::prelude::Lsb0;
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
Expand All @@ -8,6 +9,8 @@ use syn::ir::clifford_tableau::CallbackCliffordSynthesizer;
use syn::ir::CliffordGates;
use syn::ir::Synthesizer;

mod connectivity;

#[derive(Debug, Default)]
pub struct MockCircuit {
commands: Vec<MockCommand>,
Expand Down Expand Up @@ -162,4 +165,4 @@ pub fn ct_bench(c: &mut Criterion) {
}

criterion_group!(benches, ct_bench);
criterion_main!(benches);
criterion_main!(benches, connectivity_benchmark);
57 changes: 57 additions & 0 deletions benches/connectivity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use criterion::{black_box, criterion_group, Criterion};
use petgraph::visit::Walker;
use rand::prelude::IndexedRandom;
use rand::seq::SliceRandom;
use rand::Rng;
use syn::architecture::connectivity::Connectivity;
use syn::architecture::Architecture;

fn random_connected_connectivity(
Comment thread
daehiff marked this conversation as resolved.
num_nodes: usize,
extra_edges: usize,
subset_length: usize,
) -> (Connectivity, Vec<usize>, usize) {
let mut rng = rand::thread_rng();
let mut edges = Vec::new();

let mut nodes: Vec<usize> = (0..num_nodes).collect();
nodes.shuffle(&mut rng);
for i in 1..num_nodes {
edges.push((nodes[i - 1], nodes[i]));
}

// Add extra random edges:
while edges.len() < (num_nodes - 1) + extra_edges {
let a = rng.gen_range(0..num_nodes);
let b = rng.gen_range(0..num_nodes);
if a != b && !edges.contains(&(a, b)) && !edges.contains(&(b, a)) {
edges.push((a, b));
}
}

let mut subset_nodes = nodes.clone();
subset_nodes.shuffle(&mut rng);
let subset: Vec<usize> = subset_nodes.into_iter().take(subset_length).collect();

let random_element = *subset.choose(&mut rng).expect("Subset cannot be empty");

(Connectivity::from_edges(&edges), subset, random_element)
}

fn get_cx_ladder_connectivity((connectivity, nodes, root): &(Connectivity, Vec<usize>, usize)) {
let _ = connectivity.get_cx_ladder(&nodes, &root);
}

pub fn connectivity_bench(c: &mut Criterion) {
let input = random_connected_connectivity(30, 15, 10);
Comment thread
daehiff marked this conversation as resolved.
c.bench_function("get_cx_ladder_connectivity: 30, 15, 10", |b| {
b.iter(|| get_cx_ladder_connectivity(black_box(&input)))
});

let input = random_connected_connectivity(100, 50, 50);
c.bench_function("get_cx_ladder_connectivity: 100, 15, 10", |b| {
b.iter(|| get_cx_ladder_connectivity(black_box(&input)))
});
}

criterion_group!(connectivity_benchmark, connectivity_bench);
12 changes: 10 additions & 2 deletions src/architecture.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
pub mod complete;
pub mod connectivity;
pub mod line;

type GraphIndex = usize;
type EdgeWeight = usize;
type NodeWeight = ();

#[derive(Debug, PartialEq)]
pub enum LadderError {
RootNotFound,
}

pub trait Architecture {
fn best_path(&self, i: GraphIndex, j: GraphIndex) -> Vec<GraphIndex>;
fn distance(&self, i: GraphIndex, j: GraphIndex) -> GraphIndex;
fn neighbors(&self, i: GraphIndex) -> Vec<GraphIndex>;
fn non_cutting(&mut self) -> &Vec<GraphIndex>;
fn get_cx_ladder(
&self,
nodes: &[GraphIndex],
root: &GraphIndex,
) -> Result<Vec<(usize, usize)>, LadderError>;
Comment thread
daehiff marked this conversation as resolved.
}
Loading
Loading