Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
swernli committed May 20, 2024
1 parent 79d2370 commit e57e3b1
Showing 1 changed file with 183 additions and 0 deletions.
183 changes: 183 additions & 0 deletions library/src/tests/intrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![allow(clippy::needless_raw_string_hashes, clippy::too_many_lines)]

use expect_test::expect;
use indoc::indoc;
use qsc::{interpret::Value, target::Profile, SparseSim};
Expand Down Expand Up @@ -2825,3 +2827,184 @@ fn global_phase_correct_for_triply_controlled_adjoint_r1() {
"#]]
.assert_eq(&dump);
}

#[test]
fn test_exp() {
let dump = test_expression(
indoc! {r#"
{
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Diagnostics;
for p in [PauliX, PauliY, PauliZ, PauliI] {
for i in 1 .. 4 {
Message($"Exp with {p} on {i} qubits:");
use qs = Qubit[i];
for q in qs {
H(q);
}
Exp(Repeated(p, i), PI() / 7.0, qs);
DumpMachine();
ResetAll(qs);
}
}
}
"#},
&Value::unit(),
);

expect![[r#"
Exp with PauliX on 1 qubits:
STATE:
|0⟩: 0.6371+0.3068𝑖
|1⟩: 0.6371+0.3068𝑖
Exp with PauliX on 2 qubits:
STATE:
|00⟩: 0.4505+0.2169𝑖
|01⟩: 0.4505+0.2169𝑖
|10⟩: 0.4505+0.2169𝑖
|11⟩: 0.4505+0.2169𝑖
Exp with PauliX on 3 qubits:
STATE:
|000⟩: 0.3185+0.1534𝑖
|001⟩: 0.3185+0.1534𝑖
|010⟩: 0.3185+0.1534𝑖
|011⟩: 0.3185+0.1534𝑖
|100⟩: 0.3185+0.1534𝑖
|101⟩: 0.3185+0.1534𝑖
|110⟩: 0.3185+0.1534𝑖
|111⟩: 0.3185+0.1534𝑖
Exp with PauliX on 4 qubits:
STATE:
|0000⟩: 0.2252+0.1085𝑖
|0001⟩: 0.2252+0.1085𝑖
|0010⟩: 0.2252+0.1085𝑖
|0011⟩: 0.2252+0.1085𝑖
|0100⟩: 0.2252+0.1085𝑖
|0101⟩: 0.2252+0.1085𝑖
|0110⟩: 0.2252+0.1085𝑖
|0111⟩: 0.2252+0.1085𝑖
|1000⟩: 0.2252+0.1085𝑖
|1001⟩: 0.2252+0.1085𝑖
|1010⟩: 0.2252+0.1085𝑖
|1011⟩: 0.2252+0.1085𝑖
|1100⟩: 0.2252+0.1085𝑖
|1101⟩: 0.2252+0.1085𝑖
|1110⟩: 0.2252+0.1085𝑖
|1111⟩: 0.2252+0.1085𝑖
Exp with PauliY on 1 qubits:
STATE:
|0⟩: 0.9439+0.0000𝑖
|1⟩: 0.3303+0.0000𝑖
Exp with PauliY on 2 qubits:
STATE:
|00⟩: 0.4505−0.2169𝑖
|01⟩: 0.4505+0.2169𝑖
|10⟩: 0.4505+0.2169𝑖
|11⟩: 0.4505−0.2169𝑖
Exp with PauliY on 3 qubits:
STATE:
|000⟩: 0.1651+0.0000𝑖
|001⟩: 0.4719+0.0000𝑖
|010⟩: 0.4719+0.0000𝑖
|011⟩: 0.1651+0.0000𝑖
|100⟩: 0.4719+0.0000𝑖
|101⟩: 0.1651+0.0000𝑖
|110⟩: 0.1651+0.0000𝑖
|111⟩: 0.4719+0.0000𝑖
Exp with PauliY on 4 qubits:
STATE:
|0000⟩: 0.2252+0.1085𝑖
|0001⟩: 0.2252−0.1085𝑖
|0010⟩: 0.2252−0.1085𝑖
|0011⟩: 0.2252+0.1085𝑖
|0100⟩: 0.2252−0.1085𝑖
|0101⟩: 0.2252+0.1085𝑖
|0110⟩: 0.2252+0.1085𝑖
|0111⟩: 0.2252−0.1085𝑖
|1000⟩: 0.2252−0.1085𝑖
|1001⟩: 0.2252+0.1085𝑖
|1010⟩: 0.2252+0.1085𝑖
|1011⟩: 0.2252−0.1085𝑖
|1100⟩: 0.2252+0.1085𝑖
|1101⟩: 0.2252−0.1085𝑖
|1110⟩: 0.2252−0.1085𝑖
|1111⟩: 0.2252+0.1085𝑖
Exp with PauliZ on 1 qubits:
STATE:
|0⟩: 0.6371+0.3068𝑖
|1⟩: 0.6371−0.3068𝑖
Exp with PauliZ on 2 qubits:
STATE:
|00⟩: 0.4505+0.2169𝑖
|01⟩: 0.4505−0.2169𝑖
|10⟩: 0.4505−0.2169𝑖
|11⟩: 0.4505+0.2169𝑖
Exp with PauliZ on 3 qubits:
STATE:
|000⟩: 0.3185+0.1534𝑖
|001⟩: 0.3185−0.1534𝑖
|010⟩: 0.3185−0.1534𝑖
|011⟩: 0.3185+0.1534𝑖
|100⟩: 0.3185−0.1534𝑖
|101⟩: 0.3185+0.1534𝑖
|110⟩: 0.3185+0.1534𝑖
|111⟩: 0.3185−0.1534𝑖
Exp with PauliZ on 4 qubits:
STATE:
|0000⟩: 0.2252+0.1085𝑖
|0001⟩: 0.2252−0.1085𝑖
|0010⟩: 0.2252−0.1085𝑖
|0011⟩: 0.2252+0.1085𝑖
|0100⟩: 0.2252−0.1085𝑖
|0101⟩: 0.2252+0.1085𝑖
|0110⟩: 0.2252+0.1085𝑖
|0111⟩: 0.2252−0.1085𝑖
|1000⟩: 0.2252−0.1085𝑖
|1001⟩: 0.2252+0.1085𝑖
|1010⟩: 0.2252+0.1085𝑖
|1011⟩: 0.2252−0.1085𝑖
|1100⟩: 0.2252+0.1085𝑖
|1101⟩: 0.2252−0.1085𝑖
|1110⟩: 0.2252−0.1085𝑖
|1111⟩: 0.2252+0.1085𝑖
Exp with PauliI on 1 qubits:
STATE:
|0⟩: 0.6371+0.3068𝑖
|1⟩: 0.6371+0.3068𝑖
Exp with PauliI on 2 qubits:
STATE:
|00⟩: 0.4505+0.2169𝑖
|01⟩: 0.4505+0.2169𝑖
|10⟩: 0.4505+0.2169𝑖
|11⟩: 0.4505+0.2169𝑖
Exp with PauliI on 3 qubits:
STATE:
|000⟩: 0.3185+0.1534𝑖
|001⟩: 0.3185+0.1534𝑖
|010⟩: 0.3185+0.1534𝑖
|011⟩: 0.3185+0.1534𝑖
|100⟩: 0.3185+0.1534𝑖
|101⟩: 0.3185+0.1534𝑖
|110⟩: 0.3185+0.1534𝑖
|111⟩: 0.3185+0.1534𝑖
Exp with PauliI on 4 qubits:
STATE:
|0000⟩: 0.2252+0.1085𝑖
|0001⟩: 0.2252+0.1085𝑖
|0010⟩: 0.2252+0.1085𝑖
|0011⟩: 0.2252+0.1085𝑖
|0100⟩: 0.2252+0.1085𝑖
|0101⟩: 0.2252+0.1085𝑖
|0110⟩: 0.2252+0.1085𝑖
|0111⟩: 0.2252+0.1085𝑖
|1000⟩: 0.2252+0.1085𝑖
|1001⟩: 0.2252+0.1085𝑖
|1010⟩: 0.2252+0.1085𝑖
|1011⟩: 0.2252+0.1085𝑖
|1100⟩: 0.2252+0.1085𝑖
|1101⟩: 0.2252+0.1085𝑖
|1110⟩: 0.2252+0.1085𝑖
|1111⟩: 0.2252+0.1085𝑖
"#]]
.assert_eq(&dump);
}

0 comments on commit e57e3b1

Please sign in to comment.