From 8d80f251d43aae81d480a1cbeec7ce01a8d21d05 Mon Sep 17 00:00:00 2001 From: Nicolas Vogt <45093608+nfwvogt@users.noreply.github.com> Date: Thu, 18 Nov 2021 16:18:00 +0100 Subject: [PATCH] Topology_links_interface (#132) * update dependencies * updated dependencies * WIP: two_qubit_edges * Added two_qubit_edges to Device trait --- CHANGELOG.md | 1 + roqoqo/src/devices.rs | 14 ++++++++++++++ roqoqo/tests/integration/devices.rs | 25 +++++++++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6edbe3cc..0d43a470 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/roqoqo/src/devices.rs b/roqoqo/src/devices.rs index 746717e8..ad480100 100644 --- a/roqoqo/src/devices.rs +++ b/roqoqo/src/devices.rs @@ -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. diff --git a/roqoqo/tests/integration/devices.rs b/roqoqo/tests/integration/devices.rs index 590e819b..7912d967 100644 --- a/roqoqo/tests/integration/devices.rs +++ b/roqoqo/tests/integration/devices.rs @@ -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 { match self.single_qubit_gates.get(&hqslang.to_string()) { Some(x) => x.get(&qubit).map(|x| *x), @@ -67,6 +63,20 @@ impl Device for TestDevice { fn qubit_decoherence_rates(&self, qubit: &usize) -> Option> { 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 @@ -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