Skip to content

Commit

Permalink
Topology_links_interface (#132)
Browse files Browse the repository at this point in the history
* update dependencies

* updated dependencies

* WIP: two_qubit_edges

* Added two_qubit_edges to Device trait
  • Loading branch information
nfwvogt authored Nov 18, 2021
1 parent 0041be3 commit 8d80f25
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This changelog track changes to the qoqo project starting at version 0.5.0
### Added not released

* MultiQubitZZ gate. Rotation under a multi-qubit product of Pauli Z operators.
* `two_qubit_edges` function in Device trait. Used to create a simple graph-library-agnostic representation of the connectivity graph of a device.

## 0.8.1

Expand Down
14 changes: 14 additions & 0 deletions roqoqo/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ pub trait Device {
/// Returns the number of qubits the device supports.
fn number_qubits(&self) -> usize;

/// Returns the list of pairs of qubits linked with a native two-qubit-gate in the device.
///
/// A pair of qubits is considered linked by a native two-qubit-gate if the device
/// can implement a two-qubit-gate btween the two qubits without decomposing it
/// into a sequence of gates that involves a third qubit of the device.
/// The two-qubit-gate also has to form a universal set together with the available
/// single qubit gates.
///
/// The returned vectors is a simple, graph-library independent, representation of
/// the undirected connectivity graph of the device.
/// It can be used to construct the connectivity graph in a graph library of the users
/// choice from a list of edges and can be used for applications like routing in quantum algorithms.
fn two_qubit_edges(&self) -> Vec<(usize, usize)>;

/// Changes the device topology based on a Pragma operation.
///
/// Specific devices and backends can allow changes to the device topology.
Expand Down
25 changes: 21 additions & 4 deletions roqoqo/tests/integration/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ impl TestDevice {
}

impl Device for TestDevice {
fn number_qubits(&self) -> usize {
self.number_qubits
}

fn single_qubit_gate_time(&self, hqslang: &str, qubit: &usize) -> Option<f64> {
match self.single_qubit_gates.get(&hqslang.to_string()) {
Some(x) => x.get(&qubit).map(|x| *x),
Expand All @@ -67,6 +63,20 @@ impl Device for TestDevice {
fn qubit_decoherence_rates(&self, qubit: &usize) -> Option<Array2<f64>> {
self.rates.get(&qubit).map(|x| x.to_owned())
}

fn number_qubits(&self) -> usize {
self.number_qubits
}

fn two_qubit_edges(&self) -> Vec<(usize, usize)> {
let mut edges: Vec<(usize, usize)> = Vec::new();
for row in 0..self.number_qubits {
for column in row + 1..self.number_qubits {
edges.push((row, column));
}
}
edges
}
}

/// Basic functional test
Expand Down Expand Up @@ -128,6 +138,13 @@ fn it_works() {
Some(0.8f64)
);
assert_eq!(device.multi_qubit_gate_time("Other", &[0, 1, 2]), None);

let test_edges = vec![(0, 1), (0, 2), (1, 2)];
let edges = device.two_qubit_edges();
assert_eq!(test_edges.len(), edges.len());
for edge in edges {
assert!(test_edges.contains(&edge));
}
}

/// Basic functional test
Expand Down

0 comments on commit 8d80f25

Please sign in to comment.