Skip to content

Commit

Permalink
Add: Use rust coupling map to extemd error map.
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Jun 3, 2024
1 parent 115cd54 commit 188b570
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crates/accelerate/src/target_transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ impl BaseTarget {
if self.average_error_map.is_some() {
return self.average_error_map.as_ref();
} else {
let num_qubits = self.num_qubits.unwrap_or_default();
let mut built = false;
let qargs = self.get_qargs().unwrap_or(IndexSet::new());
let mut avg_map = ErrorMap {
Expand Down Expand Up @@ -1147,6 +1148,46 @@ impl BaseTarget {
}
}
}
let mut coupling_graph = None;
if !built {
if self.coupling_graph.is_none() {
coupling_graph = match self.build_coupling_map(None, false) {
Ok(graph) => graph,
Err(_) => None,
};
}
if let Some(coupling_graph) = coupling_graph {
let node_indices = coupling_graph.node_indices().collect_vec();
for (qubit, node_index) in node_indices.iter().enumerate() {
let neighbors_count = coupling_graph
.neighbors_undirected(*node_index)
.collect_vec();
avg_map.error_map.insert(
[
PhysicalQubit::new(qubit as u32),
PhysicalQubit::new(qubit as u32),
],
(neighbors_count.len() as f64) / (num_qubits as f64),
);
}
for edge in coupling_graph.edge_indices() {
let get_edge = coupling_graph.edge_endpoints(edge);
if let Some(get_edge) = get_edge {
let get_edge: [PhysicalQubit; 2] = [
PhysicalQubit::new(get_edge.0.index() as u32),
PhysicalQubit::new(get_edge.1.index() as u32),
];
avg_map.error_map.insert(
get_edge,
(avg_map.error_map[&[get_edge[0], get_edge[0]]]
+ avg_map.error_map[&[get_edge[1], get_edge[1]]])
/ 2_f64,
);
built = true;
}
}
}
}
if built {
self.average_error_map = Some(avg_map);
self.average_error_map.as_ref()
Expand Down

0 comments on commit 188b570

Please sign in to comment.