Skip to content

Commit

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

* updated dependencies

* fixing bug in MultiQubitZZ gate

* Update multi_qubit_gate_operations.rs

Co-authored-by: kbarkhqs <[email protected]>
  • Loading branch information
nfwvogt and kbarkhqs authored Nov 18, 2021
1 parent 4db72be commit 9ac49a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 11 additions & 1 deletion roqoqo/src/operations/multi_qubit_gate_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// express or implied. See the License for the specific language governing permissions and
// limitations under the License.

use std::panic;

use crate::operations;
use crate::prelude::*;
use crate::Circuit;
Expand Down Expand Up @@ -127,7 +129,15 @@ impl OperateGate for MultiQubitZZ {
let cos: Complex64 = Complex64::new((self.theta.float()? / 2.0).cos(), 0.0);
let sin: Complex64 = Complex64::new(0.0, -(self.theta.float()? / 2.0).sin());
for i in 0..dim {
array[(i, i)] = cos + sin;
// Fix the signs of the imaginary part due to the ZZZ..ZZ product
let prefactor: f64 = (0..self.qubits.len())
.map(|q| match i.div_euclid(2usize.pow(q as u32)) % 2 {
0 => 1.0,
1 => -1.0,
_ => panic!("Internal division error MuliQubitZZ"),
})
.product();
array[(i, i)] = cos + prefactor * sin;
}
Ok(array)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,14 @@ fn test_matrix_output_multi_qubit_zz(qubits: Vec<usize>) {
],
[
Complex64::new(0.0, 0.0),
Complex64::new(f, (-1.0) * f),
Complex64::new(f, f),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0)
],
[
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(f, (-1.0) * f),
Complex64::new(f, f),
Complex64::new(0.0, 0.0)
],
[
Expand Down Expand Up @@ -376,7 +376,7 @@ fn test_matrix_output_three_multi_qubit_zz(qubits: Vec<usize>) {
],
[
Complex64::new(0.0, 0.0),
Complex64::new(f, (-1.0) * f),
Complex64::new(f, f),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Expand All @@ -387,7 +387,7 @@ fn test_matrix_output_three_multi_qubit_zz(qubits: Vec<usize>) {
[
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(f, (-1.0) * f),
Complex64::new(f, f),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Expand All @@ -409,7 +409,7 @@ fn test_matrix_output_three_multi_qubit_zz(qubits: Vec<usize>) {
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(f, (-1.0) * f),
Complex64::new(f, f),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0)
Expand Down Expand Up @@ -442,7 +442,7 @@ fn test_matrix_output_three_multi_qubit_zz(qubits: Vec<usize>) {
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(f, (-1.0) * f)
Complex64::new(f, f)
],
];
let unit = gate.unitary_matrix().unwrap();
Expand Down

0 comments on commit 9ac49a3

Please sign in to comment.