Skip to content

Commit

Permalink
Fix: Retrieve NodeIndex + EdgeData in edge related functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Jul 21, 2024
1 parent a960aaf commit 17deb75
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use qiskit_circuit::{
};
use rustworkx_core::petgraph::{
graph::NodeIndex,
stable_graph::{EdgeReference, StableDiGraph, StableGraph},
stable_graph::{StableDiGraph, StableGraph},
visit::{Control, EdgeRef},
};

Expand Down Expand Up @@ -82,9 +82,7 @@ impl<'a> BasisSearchVisitor<'a> {
Control::Continue
}

pub fn examine_edge(&mut self, edge: EdgeReference<'a, Option<EdgeData>>) -> Control<()> {
let (target, edata) = (edge.target(), edge.weight());

pub fn examine_edge(&mut self, target: NodeIndex, edata: Option<&'a EdgeData>) -> Control<()> {
if edata.is_none() {
return Control::Continue;
}
Expand All @@ -101,10 +99,11 @@ impl<'a> BasisSearchVisitor<'a> {
Control::Continue
}

pub fn edge_relaxed(&mut self, edge: EdgeReference<'a, EdgeData>) -> Control<()> {
let (target, edata) = (edge.target(), edge.weight());
let gate = &self.graph[target].key;
self.predecessors.insert(gate, &edata.rule);
pub fn edge_relaxed(&mut self, target: NodeIndex, edata: Option<&'a EdgeData>) -> Control<()> {
if let Some(edata) = edata {
let gate = &self.graph[target].key;
self.predecessors.insert(gate, &edata.rule);
}
Control::Continue
}
/// Returns the cost of an edge.
Expand All @@ -113,8 +112,7 @@ impl<'a> BasisSearchVisitor<'a> {
/// the costs of all gates in the rule equivalence circuit. In the
/// end, we need to subtract the cost of the source since `dijkstra`
/// will later add it.
pub fn edge_cost(&self, edge_data: &'a Option<EdgeData>) -> u32 {
// TODO: Handle None case
pub fn edge_cost(&self, edge_data: Option<&'a EdgeData>) -> u32 {
if edge_data.is_none() {
return 1;
}
Expand Down

0 comments on commit 17deb75

Please sign in to comment.