Skip to content

Commit

Permalink
Update Rust version, notices, and licence (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
swernli authored Feb 15, 2023
1 parent 36e6c6a commit 1c2ed04
Show file tree
Hide file tree
Showing 14 changed files with 3,724 additions and 675 deletions.
211 changes: 112 additions & 99 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2022 Microsoft Corporation.
Copyright (c) 2022 QIR Alliance
Copyright (c) 2023 Microsoft Corporation.
Copyright (c) 2023 QIR Alliance

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 7 additions & 7 deletions backend/src/exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl QuantumSim {
*self
.id_map
.get(c)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", c))
.unwrap_or_else(|| panic!("Unable to find qubit with id {c}"))
as u64
})
.collect();
Expand All @@ -186,7 +186,7 @@ impl QuantumSim {
*self
.id_map
.get(c)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", c))
.unwrap_or_else(|| panic!("Unable to find qubit with id {c}"))
as u64
})
.collect();
Expand All @@ -208,7 +208,7 @@ impl QuantumSim {
)
})
{
panic!("Duplicate qubit id '{}' found in application.", duplicate);
panic!("Duplicate qubit id '{duplicate}' found in application.");
}

let id_coeff = Complex64::new(theta.cos(), 0.0);
Expand Down Expand Up @@ -239,7 +239,7 @@ impl QuantumSim {
self.state.drain().into_iter().fold(
SparseState::default(),
|mut accum, (index, value)| {
if ctls.iter().all(|c| index.bit(*c as u64))
if ctls.iter().all(|c| index.bit(*c))
&& (&index & &yz_mask).count_ones() & 1 != 0
{
accum.insert(index, value * id_coeff);
Expand All @@ -252,7 +252,7 @@ impl QuantumSim {
self.state.drain().into_iter().fold(
SparseState::default(),
|mut accum, (index, value)| {
if ctls.iter().all(|c| index.bit(*c as u64))
if ctls.iter().all(|c| index.bit(*c))
&& (&index & &yz_mask).count_ones() & 1 != 0
{
accum.insert(index, value * pauli_coeff);
Expand All @@ -265,7 +265,7 @@ impl QuantumSim {
self.state.drain().into_iter().fold(
SparseState::default(),
|mut accum, (index, val)| {
if ctls.iter().all(|c| index.bit(*c as u64)) {
if ctls.iter().all(|c| index.bit(*c)) {
accum.insert(
index.clone(),
val * if (index & &yz_mask).count_ones() & 1 == 0 {
Expand Down Expand Up @@ -298,7 +298,7 @@ impl QuantumSim {

let mut new_state = SparseState::default();
for (index, value) in &self.state {
if ctls.iter().all(|c| index.bit(*c as u64)) {
if ctls.iter().all(|c| index.bit(*c)) {
let alt_index = index ^ &xy_mask;
if !self.state.contains_key(&alt_index) {
new_state.insert(index.clone(), value * id_coeff);
Expand Down
8 changes: 4 additions & 4 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ unsafe fn map_paulis(
.filter_map(|index| {
let p =
*__quantum__rt__array_get_element_ptr_1d(paulis, index).cast::<Pauli>() as Pauli;
let q = *__quantum__rt__array_get_element_ptr_1d(qubits, index as u64)
.cast::<*mut c_void>() as usize;
let q = *__quantum__rt__array_get_element_ptr_1d(qubits, index).cast::<*mut c_void>()
as usize;
if let Pauli::I = p {
None
} else {
Expand Down Expand Up @@ -680,7 +680,7 @@ pub unsafe extern "C" fn __quantum__qis__assertmeasurementprobability__body(
actual_prob = 1.0 - actual_prob;
}

if (actual_prob - (prob as f64)).abs() > tol as f64 {
if (actual_prob - prob).abs() > tol {
__quantum__rt__fail(msg);
}

Expand Down Expand Up @@ -767,7 +767,7 @@ pub extern "C" fn __quantum__rt__result_record_output(result: *mut c_void, tag:
.expect("Result with given id missing after expansion.")
};

let val: i64 = if b { 1 } else { 0 };
let val: i64 = i64::from(b);
output("RESULT", &val, tag, &mut std::io::stdout()).expect("Failed to write result output");
});
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/matrix_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl QuantumSim {
let loc = *self
.id_map
.get(target)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", target));
.unwrap_or_else(|| panic!("Unable to find qubit with id {target}"));
let swap_id = *self
.id_map
.iter()
Expand Down
23 changes: 11 additions & 12 deletions backend/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl QuantumSim {
let loc = self
.id_map
.remove(&id)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}.", id));
.unwrap_or_else(|| panic!("Unable to find qubit with id {id}."));

// Measure and collapse the state for this qubit.
let res = self.measure_impl(loc);
Expand Down Expand Up @@ -191,7 +191,7 @@ impl QuantumSim {
*self
.id_map
.get(id)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", id))
.unwrap_or_else(|| panic!("Unable to find qubit with id {id}"))
})
.collect();

Expand All @@ -210,7 +210,7 @@ impl QuantumSim {
*self
.id_map
.get(&id)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", id)),
.unwrap_or_else(|| panic!("Unable to find qubit with id {id}")),
)
}

Expand Down Expand Up @@ -240,7 +240,7 @@ impl QuantumSim {
*self
.id_map
.get(id)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", id))
.unwrap_or_else(|| panic!("Unable to find qubit with id {id}"))
})
.collect();

Expand Down Expand Up @@ -327,11 +327,11 @@ impl QuantumSim {
let qubit1_mapped = *self
.id_map
.get(&qubit1)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", qubit1));
.unwrap_or_else(|| panic!("Unable to find qubit with id {qubit1}"));
let qubit2_mapped = *self
.id_map
.get(&qubit2)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", qubit2));
.unwrap_or_else(|| panic!("Unable to find qubit with id {qubit2}"));
*self.id_map.get_mut(&qubit1).unwrap() = qubit2_mapped;
*self.id_map.get_mut(&qubit2).unwrap() = qubit1_mapped;
}
Expand Down Expand Up @@ -368,8 +368,7 @@ impl QuantumSim {
for id in ids.iter() {
assert!(
unique.insert(id),
"Duplicate qubit id '{}' found in application.",
id
"Duplicate qubit id '{id}' found in application."
);
}
}
Expand All @@ -384,7 +383,7 @@ impl QuantumSim {
let target = *self
.id_map
.get(&target)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", target))
.unwrap_or_else(|| panic!("Unable to find qubit with id {target}"))
as u64;

let ctls: Vec<u64> = ctls
Expand All @@ -393,7 +392,7 @@ impl QuantumSim {
*self
.id_map
.get(c)
.unwrap_or_else(|| panic!("Unable to find qubit with id {}", c))
.unwrap_or_else(|| panic!("Unable to find qubit with id {c}"))
as u64
})
.collect();
Expand Down Expand Up @@ -446,8 +445,8 @@ impl QuantumSim {
self.state = self.state.drain().into_iter().fold(
SparseState::default(),
|mut accum, (index, value)| {
let (k, v) = if ctls.iter().all(|c| index.bit(*c as u64)) {
op((index, value), target as u64)
let (k, v) = if ctls.iter().all(|c| index.bit(*c)) {
op((index, value), target)
} else {
(index, value)
};
Expand Down
Loading

0 comments on commit 1c2ed04

Please sign in to comment.