Skip to content

Commit

Permalink
Fix Rust lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Sep 14, 2023
1 parent 77210a2 commit cd2bdc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 9 additions & 11 deletions crates/accelerate/src/quantum_circuit/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ impl CircuitData {
py,
(
op,
extract_args(&self.qubits.as_ref(py), qargs)?,
extract_args(&self.clbits.as_ref(py), cargs)?,
extract_args(self.qubits.as_ref(py), qargs)?,
extract_args(self.clbits.as_ref(py), cargs)?,
),
)
} else {
Expand All @@ -133,7 +133,7 @@ impl CircuitData {
}
Int(index) => {
let index = self.convert_py_index(index, IndexFor::Lookup)?;
if let Some(_) = self.data.get(index) {
if self.data.get(index).is_some() {
let cached_entry = self.data.remove(index);
self.drop_from_cache(py, cached_entry)
} else {
Expand Down Expand Up @@ -207,10 +207,10 @@ impl CircuitData {
}

pub fn pop(&mut self, py: Python<'_>, index: Option<isize>) -> PyResult<PyObject> {
let index = index.unwrap_or(max(0, self.data.len() as isize - 1));
let index = index.unwrap_or_else(|| max(0, self.data.len() as isize - 1));
let item = self.__getitem__(py, Int(index))?;
self.__delitem__(py, Int(index))?;
return Ok(item);
Ok(item)
}

pub fn append(&mut self, py: Python<'_>, value: ElementType) -> PyResult<()> {
Expand Down Expand Up @@ -316,10 +316,8 @@ impl CircuitData {
fn equals(slf: &PyAny, other: &PyAny) -> PyResult<bool> {
let slf_len = slf.len()?;
let other_len = other.len();
if other_len.is_ok() {
if slf_len != other_len.unwrap() {
return Ok(false);
}
if other_len.is_ok() && slf_len != other_len.unwrap() {
return Ok(false);
}
let mut ours_itr = slf.iter()?;
let mut theirs_itr = match other.iter() {
Expand Down Expand Up @@ -375,8 +373,8 @@ impl CircuitData {

Ok(InternedInstruction(
Some(elem.operation),
cache_args(&self.qubit_indices.as_ref(py), elem.qubits)?,
cache_args(&self.clbit_indices.as_ref(py), elem.clbits)?,
cache_args(self.qubit_indices.as_ref(py), elem.qubits)?,
cache_args(self.clbit_indices.as_ref(py), elem.clbits)?,
))
}
}
Expand Down
11 changes: 8 additions & 3 deletions crates/accelerate/src/quantum_circuit/intern_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ impl InternContext {

let slot_idx = self.slot_lookup.entry(args.clone()).or_insert_with(|| {
if !self.free_slots.is_empty() {
let slot = self.free_slots.pop_front().unwrap();
println!("{:?}| Reusing empty slot {slot}", self.id);
slot
self.free_slots.pop_front().unwrap()
} else {
let slot = self.slots.len();
println!("{:?}| Using new empty slot {slot}", self.id);
Expand Down Expand Up @@ -100,7 +99,7 @@ impl InternContext {
operands
}

pub fn drop_use(&mut self, slot_idx: IndexType) -> () {
pub fn drop_use(&mut self, slot_idx: IndexType) {
let mut shared = take(&mut self.slots[slot_idx as usize]).unwrap();
if let SharedOperandList {
operands,
Expand Down Expand Up @@ -135,3 +134,9 @@ impl InternContext {
}
}
}

impl Default for InternContext {
fn default() -> Self {
Self::new()
}
}

0 comments on commit cd2bdc1

Please sign in to comment.