From f086caf9a70872240eef686bc094ed9aad0c1404 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 22 Jan 2025 11:33:10 -0800 Subject: [PATCH] Fix global phase for controlled-T, R1 (#2112) The decomposition for controlled-`T` in the stdlib uses `Rz` gates that are correct up to a global phase, which is fine for hardware but distracting in simulation. Correcting for that global phase in `T` fixes the global phase in `S`, which in turn allows removing a patch that made `R1` use a global phase consistent with `S`. Fixes #2106 --- library/src/tests/diagnostics.rs | 49 ++ library/src/tests/intrinsic.rs | 848 ++++++++++++------------- library/std/src/Std/InternalHelpers.qs | 10 +- 3 files changed, 476 insertions(+), 431 deletions(-) diff --git a/library/src/tests/diagnostics.rs b/library/src/tests/diagnostics.rs index 53f649bc22..3893c81024 100644 --- a/library/src/tests/diagnostics.rs +++ b/library/src/tests/diagnostics.rs @@ -425,6 +425,55 @@ fn check_dumpoperation_with_extra_qubits_relative_phase_not_reflected_in_matrix( .assert_eq(&output); } +#[test] +fn check_dump_operation_for_r1_of_pi() { + let output = test_expression( + "Microsoft.Quantum.Diagnostics.DumpOperation(1, qs => R1(Std.Math.PI(), qs[0]))", + &Value::unit(), + ); + expect![[r#" + MATRIX: + 1.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 −1.0000+0.0000𝑖 + "#]] + .assert_eq(&output); +} + +#[test] +fn check_dump_operation_for_r1_of_pi_with_one_control() { + let output = test_expression( + "Microsoft.Quantum.Diagnostics.DumpOperation(2, qs => Controlled R1(qs[...0], (Std.Math.PI(), qs[1])))", + &Value::unit(), + ); + expect![[r#" + MATRIX: + 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 −1.0000+0.0000𝑖 + "#]] + .assert_eq(&output); +} + +#[test] +fn check_dump_operation_for_r1_of_pi_with_two_controls() { + let output = test_expression( + "Microsoft.Quantum.Diagnostics.DumpOperation(3, qs => Controlled R1(qs[...1], (Std.Math.PI(), qs[2])))", + &Value::unit(), + ); + expect![[r#" + MATRIX: + 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 1.0000+0.0000𝑖 0.0000+0.0000𝑖 + 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 0.0000+0.0000𝑖 −1.0000+0.0000𝑖 + "#]].assert_eq(&output); +} + #[test] fn check_bit_flip_noise_values() { test_expression( diff --git a/library/src/tests/intrinsic.rs b/library/src/tests/intrinsic.rs index df9224cbf9..b8abc2f93e 100644 --- a/library/src/tests/intrinsic.rs +++ b/library/src/tests/intrinsic.rs @@ -694,14 +694,14 @@ fn test_mcs_2_control() { ); expect![[r#" STATE: - |000000⟩: 0.3468−0.0690𝑖 - |001001⟩: 0.3468−0.0690𝑖 - |010010⟩: 0.3468−0.0690𝑖 - |011011⟩: 0.3468−0.0690𝑖 - |100100⟩: 0.3468−0.0690𝑖 - |101101⟩: 0.3468−0.0690𝑖 - |110110⟩: 0.3468−0.0690𝑖 - |111111⟩: 0.0690+0.3468𝑖 + |000000⟩: 0.3536+0.0000𝑖 + |001001⟩: 0.3536+0.0000𝑖 + |010010⟩: 0.3536+0.0000𝑖 + |011011⟩: 0.3536+0.0000𝑖 + |100100⟩: 0.3536+0.0000𝑖 + |101101⟩: 0.3536+0.0000𝑖 + |110110⟩: 0.3536+0.0000𝑖 + |111111⟩: 0.0000+0.3536𝑖 "#]] .assert_eq(&dump); @@ -735,22 +735,22 @@ fn test_unrestricted_mcs_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452−0.0488𝑖 - |00010001⟩: 0.2452−0.0488𝑖 - |00100010⟩: 0.2452−0.0488𝑖 - |00110011⟩: 0.2452−0.0488𝑖 - |01000100⟩: 0.2452−0.0488𝑖 - |01010101⟩: 0.2452−0.0488𝑖 - |01100110⟩: 0.2452−0.0488𝑖 - |01110111⟩: 0.2452−0.0488𝑖 - |10001000⟩: 0.2452−0.0488𝑖 - |10011001⟩: 0.2452−0.0488𝑖 - |10101010⟩: 0.2452−0.0488𝑖 - |10111011⟩: 0.2452−0.0488𝑖 - |11001100⟩: 0.2452−0.0488𝑖 - |11011101⟩: 0.2452−0.0488𝑖 - |11101110⟩: 0.2452−0.0488𝑖 - |11111111⟩: 0.0488+0.2452𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.0000+0.2500𝑖 "#]] .assert_eq(&dump); @@ -786,22 +786,22 @@ fn test_base_mcs_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452−0.0488𝑖 - |00010001⟩: 0.2452−0.0488𝑖 - |00100010⟩: 0.2452−0.0488𝑖 - |00110011⟩: 0.2452−0.0488𝑖 - |01000100⟩: 0.2452−0.0488𝑖 - |01010101⟩: 0.2452−0.0488𝑖 - |01100110⟩: 0.2452−0.0488𝑖 - |01110111⟩: 0.2452−0.0488𝑖 - |10001000⟩: 0.2452−0.0488𝑖 - |10011001⟩: 0.2452−0.0488𝑖 - |10101010⟩: 0.2452−0.0488𝑖 - |10111011⟩: 0.2452−0.0488𝑖 - |11001100⟩: 0.2452−0.0488𝑖 - |11011101⟩: 0.2452−0.0488𝑖 - |11101110⟩: 0.2452−0.0488𝑖 - |11111111⟩: 0.0488+0.2452𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.0000+0.2500𝑖 "#]] .assert_eq(&dump); @@ -835,38 +835,38 @@ fn test_unrestricted_mcs_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734−0.0345𝑖 - |0000100001⟩: 0.1734−0.0345𝑖 - |0001000010⟩: 0.1734−0.0345𝑖 - |0001100011⟩: 0.1734−0.0345𝑖 - |0010000100⟩: 0.1734−0.0345𝑖 - |0010100101⟩: 0.1734−0.0345𝑖 - |0011000110⟩: 0.1734−0.0345𝑖 - |0011100111⟩: 0.1734−0.0345𝑖 - |0100001000⟩: 0.1734−0.0345𝑖 - |0100101001⟩: 0.1734−0.0345𝑖 - |0101001010⟩: 0.1734−0.0345𝑖 - |0101101011⟩: 0.1734−0.0345𝑖 - |0110001100⟩: 0.1734−0.0345𝑖 - |0110101101⟩: 0.1734−0.0345𝑖 - |0111001110⟩: 0.1734−0.0345𝑖 - |0111101111⟩: 0.1734−0.0345𝑖 - |1000010000⟩: 0.1734−0.0345𝑖 - |1000110001⟩: 0.1734−0.0345𝑖 - |1001010010⟩: 0.1734−0.0345𝑖 - |1001110011⟩: 0.1734−0.0345𝑖 - |1010010100⟩: 0.1734−0.0345𝑖 - |1010110101⟩: 0.1734−0.0345𝑖 - |1011010110⟩: 0.1734−0.0345𝑖 - |1011110111⟩: 0.1734−0.0345𝑖 - |1100011000⟩: 0.1734−0.0345𝑖 - |1100111001⟩: 0.1734−0.0345𝑖 - |1101011010⟩: 0.1734−0.0345𝑖 - |1101111011⟩: 0.1734−0.0345𝑖 - |1110011100⟩: 0.1734−0.0345𝑖 - |1110111101⟩: 0.1734−0.0345𝑖 - |1111011110⟩: 0.1734−0.0345𝑖 - |1111111111⟩: 0.0345+0.1734𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.0000+0.1768𝑖 "#]] .assert_eq(&dump); @@ -902,38 +902,38 @@ fn test_base_mcs_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734−0.0345𝑖 - |0000100001⟩: 0.1734−0.0345𝑖 - |0001000010⟩: 0.1734−0.0345𝑖 - |0001100011⟩: 0.1734−0.0345𝑖 - |0010000100⟩: 0.1734−0.0345𝑖 - |0010100101⟩: 0.1734−0.0345𝑖 - |0011000110⟩: 0.1734−0.0345𝑖 - |0011100111⟩: 0.1734−0.0345𝑖 - |0100001000⟩: 0.1734−0.0345𝑖 - |0100101001⟩: 0.1734−0.0345𝑖 - |0101001010⟩: 0.1734−0.0345𝑖 - |0101101011⟩: 0.1734−0.0345𝑖 - |0110001100⟩: 0.1734−0.0345𝑖 - |0110101101⟩: 0.1734−0.0345𝑖 - |0111001110⟩: 0.1734−0.0345𝑖 - |0111101111⟩: 0.1734−0.0345𝑖 - |1000010000⟩: 0.1734−0.0345𝑖 - |1000110001⟩: 0.1734−0.0345𝑖 - |1001010010⟩: 0.1734−0.0345𝑖 - |1001110011⟩: 0.1734−0.0345𝑖 - |1010010100⟩: 0.1734−0.0345𝑖 - |1010110101⟩: 0.1734−0.0345𝑖 - |1011010110⟩: 0.1734−0.0345𝑖 - |1011110111⟩: 0.1734−0.0345𝑖 - |1100011000⟩: 0.1734−0.0345𝑖 - |1100111001⟩: 0.1734−0.0345𝑖 - |1101011010⟩: 0.1734−0.0345𝑖 - |1101111011⟩: 0.1734−0.0345𝑖 - |1110011100⟩: 0.1734−0.0345𝑖 - |1110111101⟩: 0.1734−0.0345𝑖 - |1111011110⟩: 0.1734−0.0345𝑖 - |1111111111⟩: 0.0345+0.1734𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.0000+0.1768𝑖 "#]] .assert_eq(&dump); @@ -1004,14 +1004,14 @@ fn test_mcsadj_2_control() { ); expect![[r#" STATE: - |000000⟩: 0.3468+0.0690𝑖 - |001001⟩: 0.3468+0.0690𝑖 - |010010⟩: 0.3468+0.0690𝑖 - |011011⟩: 0.3468+0.0690𝑖 - |100100⟩: 0.3468+0.0690𝑖 - |101101⟩: 0.3468+0.0690𝑖 - |110110⟩: 0.3468+0.0690𝑖 - |111111⟩: 0.0690−0.3468𝑖 + |000000⟩: 0.3536+0.0000𝑖 + |001001⟩: 0.3536+0.0000𝑖 + |010010⟩: 0.3536+0.0000𝑖 + |011011⟩: 0.3536+0.0000𝑖 + |100100⟩: 0.3536+0.0000𝑖 + |101101⟩: 0.3536+0.0000𝑖 + |110110⟩: 0.3536+0.0000𝑖 + |111111⟩: 0.0000−0.3536𝑖 "#]] .assert_eq(&dump); @@ -1045,22 +1045,22 @@ fn test_unrestricted_mcsadj_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452+0.0488𝑖 - |00010001⟩: 0.2452+0.0488𝑖 - |00100010⟩: 0.2452+0.0488𝑖 - |00110011⟩: 0.2452+0.0488𝑖 - |01000100⟩: 0.2452+0.0488𝑖 - |01010101⟩: 0.2452+0.0488𝑖 - |01100110⟩: 0.2452+0.0488𝑖 - |01110111⟩: 0.2452+0.0488𝑖 - |10001000⟩: 0.2452+0.0488𝑖 - |10011001⟩: 0.2452+0.0488𝑖 - |10101010⟩: 0.2452+0.0488𝑖 - |10111011⟩: 0.2452+0.0488𝑖 - |11001100⟩: 0.2452+0.0488𝑖 - |11011101⟩: 0.2452+0.0488𝑖 - |11101110⟩: 0.2452+0.0488𝑖 - |11111111⟩: 0.0488−0.2452𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.0000−0.2500𝑖 "#]] .assert_eq(&dump); @@ -1096,22 +1096,22 @@ fn test_base_mcsadj_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452+0.0488𝑖 - |00010001⟩: 0.2452+0.0488𝑖 - |00100010⟩: 0.2452+0.0488𝑖 - |00110011⟩: 0.2452+0.0488𝑖 - |01000100⟩: 0.2452+0.0488𝑖 - |01010101⟩: 0.2452+0.0488𝑖 - |01100110⟩: 0.2452+0.0488𝑖 - |01110111⟩: 0.2452+0.0488𝑖 - |10001000⟩: 0.2452+0.0488𝑖 - |10011001⟩: 0.2452+0.0488𝑖 - |10101010⟩: 0.2452+0.0488𝑖 - |10111011⟩: 0.2452+0.0488𝑖 - |11001100⟩: 0.2452+0.0488𝑖 - |11011101⟩: 0.2452+0.0488𝑖 - |11101110⟩: 0.2452+0.0488𝑖 - |11111111⟩: 0.0488−0.2452𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.0000−0.2500𝑖 "#]] .assert_eq(&dump); @@ -1145,38 +1145,38 @@ fn test_unrestricted_mcsadj_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734+0.0345𝑖 - |0000100001⟩: 0.1734+0.0345𝑖 - |0001000010⟩: 0.1734+0.0345𝑖 - |0001100011⟩: 0.1734+0.0345𝑖 - |0010000100⟩: 0.1734+0.0345𝑖 - |0010100101⟩: 0.1734+0.0345𝑖 - |0011000110⟩: 0.1734+0.0345𝑖 - |0011100111⟩: 0.1734+0.0345𝑖 - |0100001000⟩: 0.1734+0.0345𝑖 - |0100101001⟩: 0.1734+0.0345𝑖 - |0101001010⟩: 0.1734+0.0345𝑖 - |0101101011⟩: 0.1734+0.0345𝑖 - |0110001100⟩: 0.1734+0.0345𝑖 - |0110101101⟩: 0.1734+0.0345𝑖 - |0111001110⟩: 0.1734+0.0345𝑖 - |0111101111⟩: 0.1734+0.0345𝑖 - |1000010000⟩: 0.1734+0.0345𝑖 - |1000110001⟩: 0.1734+0.0345𝑖 - |1001010010⟩: 0.1734+0.0345𝑖 - |1001110011⟩: 0.1734+0.0345𝑖 - |1010010100⟩: 0.1734+0.0345𝑖 - |1010110101⟩: 0.1734+0.0345𝑖 - |1011010110⟩: 0.1734+0.0345𝑖 - |1011110111⟩: 0.1734+0.0345𝑖 - |1100011000⟩: 0.1734+0.0345𝑖 - |1100111001⟩: 0.1734+0.0345𝑖 - |1101011010⟩: 0.1734+0.0345𝑖 - |1101111011⟩: 0.1734+0.0345𝑖 - |1110011100⟩: 0.1734+0.0345𝑖 - |1110111101⟩: 0.1734+0.0345𝑖 - |1111011110⟩: 0.1734+0.0345𝑖 - |1111111111⟩: 0.0345−0.1734𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.0000−0.1768𝑖 "#]] .assert_eq(&dump); @@ -1212,38 +1212,38 @@ fn test_base_mcsadj_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734+0.0345𝑖 - |0000100001⟩: 0.1734+0.0345𝑖 - |0001000010⟩: 0.1734+0.0345𝑖 - |0001100011⟩: 0.1734+0.0345𝑖 - |0010000100⟩: 0.1734+0.0345𝑖 - |0010100101⟩: 0.1734+0.0345𝑖 - |0011000110⟩: 0.1734+0.0345𝑖 - |0011100111⟩: 0.1734+0.0345𝑖 - |0100001000⟩: 0.1734+0.0345𝑖 - |0100101001⟩: 0.1734+0.0345𝑖 - |0101001010⟩: 0.1734+0.0345𝑖 - |0101101011⟩: 0.1734+0.0345𝑖 - |0110001100⟩: 0.1734+0.0345𝑖 - |0110101101⟩: 0.1734+0.0345𝑖 - |0111001110⟩: 0.1734+0.0345𝑖 - |0111101111⟩: 0.1734+0.0345𝑖 - |1000010000⟩: 0.1734+0.0345𝑖 - |1000110001⟩: 0.1734+0.0345𝑖 - |1001010010⟩: 0.1734+0.0345𝑖 - |1001110011⟩: 0.1734+0.0345𝑖 - |1010010100⟩: 0.1734+0.0345𝑖 - |1010110101⟩: 0.1734+0.0345𝑖 - |1011010110⟩: 0.1734+0.0345𝑖 - |1011110111⟩: 0.1734+0.0345𝑖 - |1100011000⟩: 0.1734+0.0345𝑖 - |1100111001⟩: 0.1734+0.0345𝑖 - |1101011010⟩: 0.1734+0.0345𝑖 - |1101111011⟩: 0.1734+0.0345𝑖 - |1110011100⟩: 0.1734+0.0345𝑖 - |1110111101⟩: 0.1734+0.0345𝑖 - |1111011110⟩: 0.1734+0.0345𝑖 - |1111111111⟩: 0.0345−0.1734𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.0000−0.1768𝑖 "#]] .assert_eq(&dump); @@ -1277,10 +1277,10 @@ fn test_mct_1_control() { ); expect![[r#" STATE: - |0000⟩: 0.4904−0.0975𝑖 - |0101⟩: 0.4904−0.0975𝑖 - |1010⟩: 0.4904−0.0975𝑖 - |1111⟩: 0.4157+0.2778𝑖 + |0000⟩: 0.5000+0.0000𝑖 + |0101⟩: 0.5000+0.0000𝑖 + |1010⟩: 0.5000+0.0000𝑖 + |1111⟩: 0.3536+0.3536𝑖 "#]] .assert_eq(&dump); @@ -1314,14 +1314,14 @@ fn test_mct_2_control() { ); expect![[r#" STATE: - |000000⟩: 0.3468−0.0690𝑖 - |001001⟩: 0.3468−0.0690𝑖 - |010010⟩: 0.3468−0.0690𝑖 - |011011⟩: 0.3468−0.0690𝑖 - |100100⟩: 0.3468−0.0690𝑖 - |101101⟩: 0.3468−0.0690𝑖 - |110110⟩: 0.3468−0.0690𝑖 - |111111⟩: 0.2940+0.1964𝑖 + |000000⟩: 0.3536+0.0000𝑖 + |001001⟩: 0.3536+0.0000𝑖 + |010010⟩: 0.3536+0.0000𝑖 + |011011⟩: 0.3536+0.0000𝑖 + |100100⟩: 0.3536+0.0000𝑖 + |101101⟩: 0.3536+0.0000𝑖 + |110110⟩: 0.3536+0.0000𝑖 + |111111⟩: 0.2500+0.2500𝑖 "#]] .assert_eq(&dump); @@ -1355,22 +1355,22 @@ fn test_unrestricted_mct_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452−0.0488𝑖 - |00010001⟩: 0.2452−0.0488𝑖 - |00100010⟩: 0.2452−0.0488𝑖 - |00110011⟩: 0.2452−0.0488𝑖 - |01000100⟩: 0.2452−0.0488𝑖 - |01010101⟩: 0.2452−0.0488𝑖 - |01100110⟩: 0.2452−0.0488𝑖 - |01110111⟩: 0.2452−0.0488𝑖 - |10001000⟩: 0.2452−0.0488𝑖 - |10011001⟩: 0.2452−0.0488𝑖 - |10101010⟩: 0.2452−0.0488𝑖 - |10111011⟩: 0.2452−0.0488𝑖 - |11001100⟩: 0.2452−0.0488𝑖 - |11011101⟩: 0.2452−0.0488𝑖 - |11101110⟩: 0.2452−0.0488𝑖 - |11111111⟩: 0.2079+0.1389𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.1768+0.1768𝑖 "#]] .assert_eq(&dump); @@ -1406,22 +1406,22 @@ fn test_base_mct_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452−0.0488𝑖 - |00010001⟩: 0.2452−0.0488𝑖 - |00100010⟩: 0.2452−0.0488𝑖 - |00110011⟩: 0.2452−0.0488𝑖 - |01000100⟩: 0.2452−0.0488𝑖 - |01010101⟩: 0.2452−0.0488𝑖 - |01100110⟩: 0.2452−0.0488𝑖 - |01110111⟩: 0.2452−0.0488𝑖 - |10001000⟩: 0.2452−0.0488𝑖 - |10011001⟩: 0.2452−0.0488𝑖 - |10101010⟩: 0.2452−0.0488𝑖 - |10111011⟩: 0.2452−0.0488𝑖 - |11001100⟩: 0.2452−0.0488𝑖 - |11011101⟩: 0.2452−0.0488𝑖 - |11101110⟩: 0.2452−0.0488𝑖 - |11111111⟩: 0.2079+0.1389𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.1768+0.1768𝑖 "#]] .assert_eq(&dump); @@ -1455,38 +1455,38 @@ fn test_unrestricted_mct_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734−0.0345𝑖 - |0000100001⟩: 0.1734−0.0345𝑖 - |0001000010⟩: 0.1734−0.0345𝑖 - |0001100011⟩: 0.1734−0.0345𝑖 - |0010000100⟩: 0.1734−0.0345𝑖 - |0010100101⟩: 0.1734−0.0345𝑖 - |0011000110⟩: 0.1734−0.0345𝑖 - |0011100111⟩: 0.1734−0.0345𝑖 - |0100001000⟩: 0.1734−0.0345𝑖 - |0100101001⟩: 0.1734−0.0345𝑖 - |0101001010⟩: 0.1734−0.0345𝑖 - |0101101011⟩: 0.1734−0.0345𝑖 - |0110001100⟩: 0.1734−0.0345𝑖 - |0110101101⟩: 0.1734−0.0345𝑖 - |0111001110⟩: 0.1734−0.0345𝑖 - |0111101111⟩: 0.1734−0.0345𝑖 - |1000010000⟩: 0.1734−0.0345𝑖 - |1000110001⟩: 0.1734−0.0345𝑖 - |1001010010⟩: 0.1734−0.0345𝑖 - |1001110011⟩: 0.1734−0.0345𝑖 - |1010010100⟩: 0.1734−0.0345𝑖 - |1010110101⟩: 0.1734−0.0345𝑖 - |1011010110⟩: 0.1734−0.0345𝑖 - |1011110111⟩: 0.1734−0.0345𝑖 - |1100011000⟩: 0.1734−0.0345𝑖 - |1100111001⟩: 0.1734−0.0345𝑖 - |1101011010⟩: 0.1734−0.0345𝑖 - |1101111011⟩: 0.1734−0.0345𝑖 - |1110011100⟩: 0.1734−0.0345𝑖 - |1110111101⟩: 0.1734−0.0345𝑖 - |1111011110⟩: 0.1734−0.0345𝑖 - |1111111111⟩: 0.1470+0.0982𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.1250+0.1250𝑖 "#]] .assert_eq(&dump); @@ -1522,38 +1522,38 @@ fn test_base_mct_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734−0.0345𝑖 - |0000100001⟩: 0.1734−0.0345𝑖 - |0001000010⟩: 0.1734−0.0345𝑖 - |0001100011⟩: 0.1734−0.0345𝑖 - |0010000100⟩: 0.1734−0.0345𝑖 - |0010100101⟩: 0.1734−0.0345𝑖 - |0011000110⟩: 0.1734−0.0345𝑖 - |0011100111⟩: 0.1734−0.0345𝑖 - |0100001000⟩: 0.1734−0.0345𝑖 - |0100101001⟩: 0.1734−0.0345𝑖 - |0101001010⟩: 0.1734−0.0345𝑖 - |0101101011⟩: 0.1734−0.0345𝑖 - |0110001100⟩: 0.1734−0.0345𝑖 - |0110101101⟩: 0.1734−0.0345𝑖 - |0111001110⟩: 0.1734−0.0345𝑖 - |0111101111⟩: 0.1734−0.0345𝑖 - |1000010000⟩: 0.1734−0.0345𝑖 - |1000110001⟩: 0.1734−0.0345𝑖 - |1001010010⟩: 0.1734−0.0345𝑖 - |1001110011⟩: 0.1734−0.0345𝑖 - |1010010100⟩: 0.1734−0.0345𝑖 - |1010110101⟩: 0.1734−0.0345𝑖 - |1011010110⟩: 0.1734−0.0345𝑖 - |1011110111⟩: 0.1734−0.0345𝑖 - |1100011000⟩: 0.1734−0.0345𝑖 - |1100111001⟩: 0.1734−0.0345𝑖 - |1101011010⟩: 0.1734−0.0345𝑖 - |1101111011⟩: 0.1734−0.0345𝑖 - |1110011100⟩: 0.1734−0.0345𝑖 - |1110111101⟩: 0.1734−0.0345𝑖 - |1111011110⟩: 0.1734−0.0345𝑖 - |1111111111⟩: 0.1470+0.0982𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.1250+0.1250𝑖 "#]] .assert_eq(&dump); @@ -1587,10 +1587,10 @@ fn test_mctadj_1_control() { ); expect![[r#" STATE: - |0000⟩: 0.4904+0.0975𝑖 - |0101⟩: 0.4904+0.0975𝑖 - |1010⟩: 0.4904+0.0975𝑖 - |1111⟩: 0.4157−0.2778𝑖 + |0000⟩: 0.5000+0.0000𝑖 + |0101⟩: 0.5000+0.0000𝑖 + |1010⟩: 0.5000+0.0000𝑖 + |1111⟩: 0.3536−0.3536𝑖 "#]] .assert_eq(&dump); @@ -1624,14 +1624,14 @@ fn test_mctadj_2_control() { ); expect![[r#" STATE: - |000000⟩: 0.3468+0.0690𝑖 - |001001⟩: 0.3468+0.0690𝑖 - |010010⟩: 0.3468+0.0690𝑖 - |011011⟩: 0.3468+0.0690𝑖 - |100100⟩: 0.3468+0.0690𝑖 - |101101⟩: 0.3468+0.0690𝑖 - |110110⟩: 0.3468+0.0690𝑖 - |111111⟩: 0.2940−0.1964𝑖 + |000000⟩: 0.3536+0.0000𝑖 + |001001⟩: 0.3536+0.0000𝑖 + |010010⟩: 0.3536+0.0000𝑖 + |011011⟩: 0.3536+0.0000𝑖 + |100100⟩: 0.3536+0.0000𝑖 + |101101⟩: 0.3536+0.0000𝑖 + |110110⟩: 0.3536+0.0000𝑖 + |111111⟩: 0.2500−0.2500𝑖 "#]] .assert_eq(&dump); @@ -1665,22 +1665,22 @@ fn test_unrestricted_mctadj_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452+0.0488𝑖 - |00010001⟩: 0.2452+0.0488𝑖 - |00100010⟩: 0.2452+0.0488𝑖 - |00110011⟩: 0.2452+0.0488𝑖 - |01000100⟩: 0.2452+0.0488𝑖 - |01010101⟩: 0.2452+0.0488𝑖 - |01100110⟩: 0.2452+0.0488𝑖 - |01110111⟩: 0.2452+0.0488𝑖 - |10001000⟩: 0.2452+0.0488𝑖 - |10011001⟩: 0.2452+0.0488𝑖 - |10101010⟩: 0.2452+0.0488𝑖 - |10111011⟩: 0.2452+0.0488𝑖 - |11001100⟩: 0.2452+0.0488𝑖 - |11011101⟩: 0.2452+0.0488𝑖 - |11101110⟩: 0.2452+0.0488𝑖 - |11111111⟩: 0.2079−0.1389𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.1768−0.1768𝑖 "#]] .assert_eq(&dump); @@ -1716,22 +1716,22 @@ fn test_base_mctadj_3_control() { ); expect![[r#" STATE: - |00000000⟩: 0.2452+0.0488𝑖 - |00010001⟩: 0.2452+0.0488𝑖 - |00100010⟩: 0.2452+0.0488𝑖 - |00110011⟩: 0.2452+0.0488𝑖 - |01000100⟩: 0.2452+0.0488𝑖 - |01010101⟩: 0.2452+0.0488𝑖 - |01100110⟩: 0.2452+0.0488𝑖 - |01110111⟩: 0.2452+0.0488𝑖 - |10001000⟩: 0.2452+0.0488𝑖 - |10011001⟩: 0.2452+0.0488𝑖 - |10101010⟩: 0.2452+0.0488𝑖 - |10111011⟩: 0.2452+0.0488𝑖 - |11001100⟩: 0.2452+0.0488𝑖 - |11011101⟩: 0.2452+0.0488𝑖 - |11101110⟩: 0.2452+0.0488𝑖 - |11111111⟩: 0.2079−0.1389𝑖 + |00000000⟩: 0.2500+0.0000𝑖 + |00010001⟩: 0.2500+0.0000𝑖 + |00100010⟩: 0.2500+0.0000𝑖 + |00110011⟩: 0.2500+0.0000𝑖 + |01000100⟩: 0.2500+0.0000𝑖 + |01010101⟩: 0.2500+0.0000𝑖 + |01100110⟩: 0.2500+0.0000𝑖 + |01110111⟩: 0.2500+0.0000𝑖 + |10001000⟩: 0.2500+0.0000𝑖 + |10011001⟩: 0.2500+0.0000𝑖 + |10101010⟩: 0.2500+0.0000𝑖 + |10111011⟩: 0.2500+0.0000𝑖 + |11001100⟩: 0.2500+0.0000𝑖 + |11011101⟩: 0.2500+0.0000𝑖 + |11101110⟩: 0.2500+0.0000𝑖 + |11111111⟩: 0.1768−0.1768𝑖 "#]] .assert_eq(&dump); @@ -1765,38 +1765,38 @@ fn test_unrestricted_mctadj_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734+0.0345𝑖 - |0000100001⟩: 0.1734+0.0345𝑖 - |0001000010⟩: 0.1734+0.0345𝑖 - |0001100011⟩: 0.1734+0.0345𝑖 - |0010000100⟩: 0.1734+0.0345𝑖 - |0010100101⟩: 0.1734+0.0345𝑖 - |0011000110⟩: 0.1734+0.0345𝑖 - |0011100111⟩: 0.1734+0.0345𝑖 - |0100001000⟩: 0.1734+0.0345𝑖 - |0100101001⟩: 0.1734+0.0345𝑖 - |0101001010⟩: 0.1734+0.0345𝑖 - |0101101011⟩: 0.1734+0.0345𝑖 - |0110001100⟩: 0.1734+0.0345𝑖 - |0110101101⟩: 0.1734+0.0345𝑖 - |0111001110⟩: 0.1734+0.0345𝑖 - |0111101111⟩: 0.1734+0.0345𝑖 - |1000010000⟩: 0.1734+0.0345𝑖 - |1000110001⟩: 0.1734+0.0345𝑖 - |1001010010⟩: 0.1734+0.0345𝑖 - |1001110011⟩: 0.1734+0.0345𝑖 - |1010010100⟩: 0.1734+0.0345𝑖 - |1010110101⟩: 0.1734+0.0345𝑖 - |1011010110⟩: 0.1734+0.0345𝑖 - |1011110111⟩: 0.1734+0.0345𝑖 - |1100011000⟩: 0.1734+0.0345𝑖 - |1100111001⟩: 0.1734+0.0345𝑖 - |1101011010⟩: 0.1734+0.0345𝑖 - |1101111011⟩: 0.1734+0.0345𝑖 - |1110011100⟩: 0.1734+0.0345𝑖 - |1110111101⟩: 0.1734+0.0345𝑖 - |1111011110⟩: 0.1734+0.0345𝑖 - |1111111111⟩: 0.1470−0.0982𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.1250−0.1250𝑖 "#]] .assert_eq(&dump); @@ -1832,38 +1832,38 @@ fn test_base_mctadj_4_control() { ); expect![[r#" STATE: - |0000000000⟩: 0.1734+0.0345𝑖 - |0000100001⟩: 0.1734+0.0345𝑖 - |0001000010⟩: 0.1734+0.0345𝑖 - |0001100011⟩: 0.1734+0.0345𝑖 - |0010000100⟩: 0.1734+0.0345𝑖 - |0010100101⟩: 0.1734+0.0345𝑖 - |0011000110⟩: 0.1734+0.0345𝑖 - |0011100111⟩: 0.1734+0.0345𝑖 - |0100001000⟩: 0.1734+0.0345𝑖 - |0100101001⟩: 0.1734+0.0345𝑖 - |0101001010⟩: 0.1734+0.0345𝑖 - |0101101011⟩: 0.1734+0.0345𝑖 - |0110001100⟩: 0.1734+0.0345𝑖 - |0110101101⟩: 0.1734+0.0345𝑖 - |0111001110⟩: 0.1734+0.0345𝑖 - |0111101111⟩: 0.1734+0.0345𝑖 - |1000010000⟩: 0.1734+0.0345𝑖 - |1000110001⟩: 0.1734+0.0345𝑖 - |1001010010⟩: 0.1734+0.0345𝑖 - |1001110011⟩: 0.1734+0.0345𝑖 - |1010010100⟩: 0.1734+0.0345𝑖 - |1010110101⟩: 0.1734+0.0345𝑖 - |1011010110⟩: 0.1734+0.0345𝑖 - |1011110111⟩: 0.1734+0.0345𝑖 - |1100011000⟩: 0.1734+0.0345𝑖 - |1100111001⟩: 0.1734+0.0345𝑖 - |1101011010⟩: 0.1734+0.0345𝑖 - |1101111011⟩: 0.1734+0.0345𝑖 - |1110011100⟩: 0.1734+0.0345𝑖 - |1110111101⟩: 0.1734+0.0345𝑖 - |1111011110⟩: 0.1734+0.0345𝑖 - |1111111111⟩: 0.1470−0.0982𝑖 + |0000000000⟩: 0.1768+0.0000𝑖 + |0000100001⟩: 0.1768+0.0000𝑖 + |0001000010⟩: 0.1768+0.0000𝑖 + |0001100011⟩: 0.1768+0.0000𝑖 + |0010000100⟩: 0.1768+0.0000𝑖 + |0010100101⟩: 0.1768+0.0000𝑖 + |0011000110⟩: 0.1768+0.0000𝑖 + |0011100111⟩: 0.1768+0.0000𝑖 + |0100001000⟩: 0.1768+0.0000𝑖 + |0100101001⟩: 0.1768+0.0000𝑖 + |0101001010⟩: 0.1768+0.0000𝑖 + |0101101011⟩: 0.1768+0.0000𝑖 + |0110001100⟩: 0.1768+0.0000𝑖 + |0110101101⟩: 0.1768+0.0000𝑖 + |0111001110⟩: 0.1768+0.0000𝑖 + |0111101111⟩: 0.1768+0.0000𝑖 + |1000010000⟩: 0.1768+0.0000𝑖 + |1000110001⟩: 0.1768+0.0000𝑖 + |1001010010⟩: 0.1768+0.0000𝑖 + |1001110011⟩: 0.1768+0.0000𝑖 + |1010010100⟩: 0.1768+0.0000𝑖 + |1010110101⟩: 0.1768+0.0000𝑖 + |1011010110⟩: 0.1768+0.0000𝑖 + |1011110111⟩: 0.1768+0.0000𝑖 + |1100011000⟩: 0.1768+0.0000𝑖 + |1100111001⟩: 0.1768+0.0000𝑖 + |1101011010⟩: 0.1768+0.0000𝑖 + |1101111011⟩: 0.1768+0.0000𝑖 + |1110011100⟩: 0.1768+0.0000𝑖 + |1110111101⟩: 0.1768+0.0000𝑖 + |1111011110⟩: 0.1768+0.0000𝑖 + |1111111111⟩: 0.1250−0.1250𝑖 "#]] .assert_eq(&dump); diff --git a/library/std/src/Std/InternalHelpers.qs b/library/std/src/Std/InternalHelpers.qs index dc6844706d..63da64a158 100644 --- a/library/std/src/Std/InternalHelpers.qs +++ b/library/std/src/Std/InternalHelpers.qs @@ -52,13 +52,6 @@ internal operation ControllableGlobalPhase(theta : Double) : Unit is Ctl { } else { Controlled Rz(ctls[1...], (theta, ctls[0])); GlobalPhase(ctls[1...], theta / 2.0); - // With a single control qubit, the call to Rz uses no controls and global phase is corrected - // by just the call above. - // Multi-controlled Rz gates use a decomposition that introduces an additional global - // phase, so we need to correct for that here. - if Length(ctls) > 1 { - GlobalPhase([], -theta / 4.0); - } } } } @@ -90,6 +83,9 @@ internal operation CT(control : Qubit, target : Qubit) : Unit is Adj { CNOT(control, target); Adjoint Rz(angle, target); CNOT(control, target); + // This decomposition for controlled-T introduces a global phase (due to the unmatched call to Rz from above). + // We correct for this global phase in simulation, which is a no-op on hardware. + ApplyGlobalPhase(angle / 2.0); } internal operation MapPauli(qubit : Qubit, from : Pauli, to : Pauli) : Unit is Adj {