Skip to content

Commit

Permalink
Fixed unittest for devices and updated changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarkhqs committed Sep 3, 2021
1 parent 8aac948 commit f8cbdb0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 51 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ This changelog track changes to the qoqo project starting at version 0.5.0

## Not released

### Changed

* Rarely used qubit mapping is now the last argument in PragmaRepeatedMeasurement
* PragmaGeneralNoise uses sigma^+ sigma^- and sigma^z as a basis to for Lindblad decoherence rates to avoid using complex rates. Rate and operators parameters of PragmaGeneralNoise have been combined in single parameter rates.
## 0.6.0

### Added

* Device trait: A minimal trait for quantum computing devices used with roqoqo
* `RoqoqoBackendError` now has a variant `GenericError` for additional backend error types
### Added

* Rarely used qubit mapping is now the last argument in PragmaRepeatedMeasurement
* PragmaGeneralNoise uses sigma^+ sigma^- and sigma^z as a basis to for Lindblad decoherence rates to avoid using complex rates. Rate and operators parameters of PragmaGeneralNoise have been combined in single parameter rates.

## 0.5.1

Expand Down
2 changes: 1 addition & 1 deletion roqoqo-derive/src/operate_unitary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub fn dispatch_struct_enum_operate_noise_proba_pragma(input: DeriveInput) -> To

fn operate_noise_proba_pragma_enum(de: DataEnum, ident: Ident) -> TokenStream {
let variants_with_type = extract_variants_with_types(de).into_iter();
let match_proba_quotes = variants_with_type.clone().map(|(vident, _, _)| {
let match_proba_quotes = variants_with_type.map(|(vident, _, _)| {
quote! {
&#ident::#vident(ref inner) => inner.probability(),
}
Expand Down
2 changes: 1 addition & 1 deletion roqoqo/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub trait Device: Sized {
///
/// * `Some<&Array2<f64>>` - The decoherence rates.
/// * `None` - The qubit is not part of the device.
fn qubit_decoherence_rates(&self, qubits: &[usize]) -> Option<Array2<f64>>; // ask
fn qubit_decoherence_rates(&self, qubit: usize) -> Option<&Array2<f64>>;

/// Returns the number of qubits the device supports.
fn number_qubits(&self) -> usize;
Expand Down
73 changes: 28 additions & 45 deletions roqoqo/tests/integration/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,24 @@ struct TestDevice {
number_qubits: usize,
single_qubit_gates: HashMap<String, HashMap<usize, f64>>,
two_qubit_gates: HashMap<String, HashMap<(usize, usize), f64>>,
multi_qubit_gates: HashMap<String, HashMap<(usize, usize, usize), f64>>,
dephasing_rates: HashMap<usize, f64>,
depolarising_rates: HashMap<usize, f64>,
damping_rates: HashMap<usize, f64>,
multi_qubit_gates: HashMap<String, f64>,
rates: HashMap<usize, Array2<f64>>,
}

impl TestDevice {
pub fn new(
number_qubits: usize,
single_qubit_gates: HashMap<String, HashMap<usize, f64>>,
two_qubit_gates: HashMap<String, HashMap<(usize, usize), f64>>,
multi_qubit_gates: HashMap<String, HashMap<(usize, usize, usize), f64>>,
dephasing_rates: HashMap<usize, f64>,
depolarising_rates: HashMap<usize, f64>,
damping_rates: HashMap<usize, f64>,
multi_qubit_gates: HashMap<String, f64>,
rates: HashMap<usize, Array2<f64>>,
) -> Self {
TestDevice {
number_qubits,
single_qubit_gates,
two_qubit_gates,
multi_qubit_gates,
dephasing_rates,
depolarising_rates,
damping_rates,
rates,
}
}
}
Expand All @@ -66,16 +60,12 @@ impl Device for TestDevice {
}
}

fn multi_qubit_gate_time(&self, hqslang: &str, qubits: &[usize]) -> Option<&f64> {
match self.multi_qubit_gates.get(&hqslang.to_string()) {
Some(x) => x.get(&(qubits[0], qubits[1], qubits[2])), // ask,
None => None,
}
fn multi_qubit_gate_time(&self, hqslang: &str, _qubits: &[usize]) -> Option<&f64> {
self.multi_qubit_gates.get(&hqslang.to_string())
}

fn qubit_decoherence_rates(&self, qubits: &[usize]) -> Option<Array2<f64>> {
let default: Array2<f64> = array![[qubits[0] as f64]];
Some(default)
fn qubit_decoherence_rates(&self, qubit: usize) -> Option<&Array2<f64>> {
self.rates.get(&qubit)
}
}

Expand All @@ -96,37 +86,34 @@ fn it_works() {
let mut two_qubit_gates: HashMap<String, HashMap<(usize, usize), f64>> = HashMap::new();
two_qubit_gates.insert("CNOT".to_string(), cnot_map);

let mut multi_ms_map: HashMap<(usize, usize, usize), f64> = HashMap::new();
multi_ms_map.insert((0, 1, 2), 0.8);
let mut multi_qubit_gates: HashMap<String, HashMap<(usize, usize, usize), f64>> =
HashMap::new();
multi_qubit_gates.insert("MultiQubitMS".to_string(), multi_ms_map);

let mut deph_map: HashMap<usize, f64> = HashMap::new();
deph_map.insert(0, 0.003);
deph_map.insert(1, 0.002);
deph_map.insert(2, 0.001);
let mut depol_map: HashMap<usize, f64> = HashMap::new();
depol_map.insert(0, 0.009);
depol_map.insert(1, 0.008);
depol_map.insert(2, 0.007);
let mut damp_map: HashMap<usize, f64> = HashMap::new();
damp_map.insert(0, 0.006);
damp_map.insert(1, 0.005);
damp_map.insert(2, 0.004);
let mut multi_qubit_gates: HashMap<String, f64> = HashMap::new();
multi_qubit_gates.insert("MultiQubitMS".to_string(), 0.8);

let mut rates: HashMap<usize, Array2<f64>> = HashMap::new();
rates.insert(
0,
array![[0.003, 0.0, 0.0], [0.0, 0.0, 00.0], [0.0, 0.0, 0.0]],
);
rates.insert(
1,
array![[0.0, 0.0, 0.0], [0.0, 0.002, 0.0], [0.0, 0.0, 0.0]],
);
rates.insert(
2,
array![[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.001, 0.0]],
);

let device = TestDevice::new(
3,
single_qubit_gates,
two_qubit_gates,
multi_qubit_gates,
deph_map,
depol_map,
damp_map,
rates,
);

let array: Array2<f64> = array![[0.003, 0.0, 0.0], [0.0, 0.0, 00.0], [0.0, 0.0, 0.0]];
assert_eq!(device.number_qubits(), 3usize);
assert_eq!(device.qubit_decoherence_rates(&[0]), Some(array![[0.0]]));
assert_eq!(device.qubit_decoherence_rates(0), Some(&array));

assert_eq!(device.single_qubit_gate_time("RotateX", 0), Some(&0.1f64));
assert_eq!(device.single_qubit_gate_time("RotateX", 3), None);
Expand All @@ -140,9 +127,5 @@ fn it_works() {
device.multi_qubit_gate_time("MultiQubitMS", &[0, 1, 2]),
Some(&0.8f64)
);
assert_eq!(
device.multi_qubit_gate_time("MultiQubitMS", &[0, 1, 3]),
None
);
assert_eq!(device.multi_qubit_gate_time("Other", &[0, 1, 2]), None);
}

0 comments on commit f8cbdb0

Please sign in to comment.