Skip to content

Commit

Permalink
Adding Clippy to workflow + lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranra committed Sep 25, 2024
1 parent 8428d26 commit 4ddc85d
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 112 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PECOS Rust test / linting
name: Rust test / linting

on:
push:
Expand Down Expand Up @@ -35,8 +35,8 @@ jobs:
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
# - name: Run clippy
# run: cargo clippy --workspace --all-targets -- -D warnings
- name: Run clippy
run: cargo clippy --workspace --all-targets -- -D warnings

pre-commit:
runs-on: ubuntu-latest
Expand Down
39 changes: 27 additions & 12 deletions crates/benchmarks/benches/modules/helpers/rot_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ use pecos_qsims::CliffordSimulator;
use pecos_sets::IndexableElement;
use std::collections::HashMap;

type Layout = HashMap<usize, (usize, usize)>;

// TODO: Create a simplified function that generates the list of gates and qubits in the right
// space and time ordering.


#[allow(dead_code)]
struct RotSurface {
distance: usize,
width: usize,
Expand All @@ -15,11 +19,13 @@ struct RotSurface {
pos2qid: HashMap<(usize, usize), usize>,
}

#[allow(dead_code)]
enum CheckType {
XCheck,
ZCheck,
}

#[allow(dead_code)]
struct Check {
check_type: CheckType,
locations: Vec<usize>,
Expand All @@ -30,7 +36,8 @@ struct Check {
meas_tick: usize,
}

fn get_pos2qid(layout: &HashMap<usize, (usize, usize)>) -> HashMap<(usize, usize), usize> {
#[allow(dead_code)]
fn get_pos2qid(layout: &Layout) -> HashMap<(usize, usize), usize> {
let mut rev_map = HashMap::<(usize, usize), usize>::new();

for (&q, &pos) in layout {
Expand All @@ -41,6 +48,8 @@ fn get_pos2qid(layout: &HashMap<usize, (usize, usize)>) -> HashMap<(usize, usize
}

impl RotSurface {

#[allow(dead_code)]
pub fn new(distance: usize) -> Self {
let width = distance;
let height = distance;
Expand All @@ -59,8 +68,9 @@ impl RotSurface {
}
}

#[allow(dead_code)]
fn new_node(
layout: &mut HashMap<usize, (usize, usize)>,
layout: &mut Layout,
id: &usize,
id_vec: &mut Vec<usize>,
coord: (usize, usize),
Expand All @@ -70,10 +80,11 @@ impl RotSurface {
id + 1
}

#[allow(dead_code)]
fn generate_layout(
height: usize,
width: usize,
) -> (HashMap<usize, (usize, usize)>, Vec<usize>, Vec<usize>) {
) -> (Layout, Vec<usize>, Vec<usize>) {
let lattice_height = 2 * height;
let lattice_width = 2 * width;
let mut layout = HashMap::<usize, (usize, usize)>::new();
Expand Down Expand Up @@ -111,14 +122,9 @@ impl RotSurface {
// ancilla qubit
nid = Self::new_node(&mut layout, &nid, &mut anc_ids, (x, y));
}
} else if x == lattice_width && width % 2 == 1 {
if y != 0 && y & 4 == 0 {
// ancilla qubit
nid = Self::new_node(&mut layout, &nid, &mut anc_ids, (x, y));
} else if (y - 2) % 4 == 0 {
// ancilla qubit
nid = Self::new_node(&mut layout, &nid, &mut anc_ids, (x, y));
}
} else if x == lattice_width && width % 2 == 1 && ((y != 0 && y & 4 == 0) || ((y - 2) % 4 == 0)) {
// ancilla qubit
nid = Self::new_node(&mut layout, &nid, &mut anc_ids, (x, y));
}
}
}
Expand All @@ -127,6 +133,7 @@ impl RotSurface {
(layout, data_ids, anc_ids)
}

#[allow(dead_code)]
fn mz<E: IndexableElement>(&self, state: &mut impl CliffordSimulator<E>) -> Vec<bool> {
let mut meas = Vec::new();
for &q in &self.data_qubit_ids {
Expand All @@ -136,6 +143,7 @@ impl RotSurface {
meas
}

#[allow(dead_code)]
/// Get a vector of `Checks` to be converted into actual circuits.
fn get_syn_extract_checks(&self) -> Vec<Check> {
let mut checks = Vec::new();
Expand Down Expand Up @@ -176,11 +184,13 @@ impl RotSurface {
checks
}

#[allow(dead_code)]
/// TODO: Using the timing and qubit locations, convert to list of representations of gates...
fn checks2timed_ops(checks: Vec<Check>) {
fn checks2timed_ops(_checks: Vec<Check>) {
todo!()
}

#[allow(dead_code)]
fn create_x_check(
&self,
ancilla: usize,
Expand All @@ -198,6 +208,7 @@ impl RotSurface {
(locations, datas, my_data_ticks)
}

#[allow(dead_code)]
fn create_z_check(
&self,
ancilla: usize,
Expand All @@ -215,6 +226,7 @@ impl RotSurface {
(locations, datas, my_data_ticks)
}

#[allow(dead_code)]
fn find_data(
pos_to_qid: &HashMap<(usize, usize), usize>,
positions: [(usize, usize); 4],
Expand All @@ -234,6 +246,7 @@ impl RotSurface {
(data_list, tick_list)
}

#[allow(dead_code)]
fn data_pos_x_check(x: usize, y: usize) -> [(usize, usize); 4] {
[
(x - 1, y + 1),
Expand All @@ -243,6 +256,7 @@ impl RotSurface {
]
}

#[allow(dead_code)]
fn data_pos_z_check(x: usize, y: usize) -> [(usize, usize); 4] {
[
(x - 1, y + 1),
Expand All @@ -252,6 +266,7 @@ impl RotSurface {
]
}

#[allow(dead_code)]
fn pz<E: IndexableElement>(&self, state: &mut impl CliffordSimulator<E>) {
// data qubits start in zeros.
for &q in &self.data_qubit_ids {
Expand Down
36 changes: 20 additions & 16 deletions crates/pecos-qsims/src/gens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ where
T: for<'a> Set<'a, Element = E>,
E: IndexableElement,
{
pub(crate) num_qubits: usize,
pub(crate) col_x: Vec<T>,
pub(crate) col_z: Vec<T>,
pub(crate) row_x: Vec<T>,
pub(crate) row_z: Vec<T>,
pub(crate) sign: T,
pub(crate) signs_minus: T,
pub(crate) signs_i: T,
num_qubits: usize,
pub col_x: Vec<T>,
pub col_z: Vec<T>,
pub row_x: Vec<T>,
pub row_z: Vec<T>,
pub sign: T,
pub signs_minus: T,
pub signs_i: T,
_marker: PhantomData<E>,
}

Expand All @@ -52,6 +52,10 @@ where
}
}

pub fn get_num_qubits(&self) -> usize {
self.num_qubits
}

#[inline]
pub fn clear(&mut self) {
self.col_x.clear();
Expand All @@ -67,20 +71,20 @@ where
pub fn init_all_z(&mut self) {
self.clear();
// TODO: Change these to not create a new Vec... instead populate them...
self.col_x = vec![T::new(); self.num_qubits];
self.col_z = new_index_set::<T, E>(self.num_qubits);
self.row_x = vec![T::new(); self.num_qubits];
self.row_z = new_index_set::<T, E>(self.num_qubits);
self.col_x = vec![T::new(); self.get_num_qubits()];
self.col_z = new_index_set::<T, E>(self.get_num_qubits());
self.row_x = vec![T::new(); self.get_num_qubits()];
self.row_z = new_index_set::<T, E>(self.get_num_qubits());
}

#[inline]
pub fn init_all_x(&mut self) {
// TODO: Change these to not create a new Vec... instead populate them...
self.clear();
self.col_x = new_index_set::<T, E>(self.num_qubits);
self.col_z = vec![T::new(); self.num_qubits];
self.row_x = new_index_set::<T, E>(self.num_qubits);
self.row_z = vec![T::new(); self.num_qubits];
self.col_x = new_index_set::<T, E>(self.get_num_qubits());
self.col_z = vec![T::new(); self.get_num_qubits()];
self.row_x = new_index_set::<T, E>(self.get_num_qubits());
self.row_z = vec![T::new(); self.get_num_qubits()];
}
}

Expand Down
18 changes: 9 additions & 9 deletions crates/pecos-qsims/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![deny(clippy::all)]
#![warn(clippy::cargo)]
#![warn(clippy::complexity)]
#![warn(clippy::correctness)]
// #![deny(clippy::all)]
// #![warn(clippy::cargo)]
// #![warn(clippy::complexity)]
// #![warn(clippy::correctness)]
// #![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
#![warn(clippy::perf)]
#![warn(clippy::restriction)]
#![warn(clippy::style)]
#![warn(clippy::suspicious)]
// #![warn(clippy::pedantic)]
// #![warn(clippy::perf)]
// #![warn(clippy::restriction)]
// #![warn(clippy::style)]
// #![warn(clippy::suspicious)]
// Try to minimize these:
#![allow(
clippy::arithmetic_side_effects,
Expand Down
2 changes: 0 additions & 2 deletions crates/pecos-qsims/src/paulis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use core::ops::BitAnd;
use pecos_sets::{IndexableElement, Set};
use std::collections::HashSet;

#[expect(dead_code)]
#[derive(Clone, Debug)]
pub struct Paulis<T, E>
where
Expand All @@ -29,7 +28,6 @@ where
_marker: PhantomData<E>,
}

#[expect(dead_code)]
impl<T, E> Paulis<T, E>
where
T: for<'a> Set<'a, Element = E>,
Expand Down
Loading

0 comments on commit 4ddc85d

Please sign in to comment.