11"""
22This test verifies that Q# code generated by this library actually compiles to
33an operation, which applies specified matrix to a register of qubits.
4-
5- Here we just test just few small random matrices. More thorough tests are in
6- quantum_decomp_test.py.
74"""
85
9- from contextlib import redirect_stdout
6+ import io
107import tempfile
8+ from contextlib import redirect_stdout
9+
10+ import cirq
1111import numpy as np
1212import qsharp
13- import io
1413from scipy .stats import unitary_group
1514
1615import quantum_decomp as qd
17- from quantum_decomp .src .test_utils import QFT_2 , SWAP , CNOT
16+ from quantum_decomp .src .test_utils import CNOT , QFT_2 , SWAP
1817from quantum_decomp .src .utils import permute_matrix
1918
2019
2120def change_int_endianness (val , n ):
22- return sum (((val >> i ) & 1 ) << (n - 1 - i ) for i in range (n ))
21+ return sum (((val >> i ) & 1 ) << (n - 1 - i ) for i in range (n ))
2322
2423
2524def change_matrix_endianness (matrix , n ):
@@ -61,12 +60,12 @@ def check_on_matrix(matrix):
6160 op_code = qd .matrix_to_qsharp (matrix , op_name = 'Op' )
6261 qubits_count = int (np .log2 (matrix .shape [0 ]))
6362 dump_matrix = dump_qsharp_unitary (op_code , qubits_count )
64- assert np . allclose (matrix , dump_matrix , atol = 1e-4 )
63+ assert cirq . equal_up_to_global_phase (matrix , dump_matrix , atol = 1e-4 )
6564
6665
6766def test_qsharp_integration_2x2 ():
68- check_on_matrix ( unitary_group . rvs ( 2 ))
69- check_on_matrix (unitary_group .rvs (2 ))
67+ for _ in range ( 10 ):
68+ check_on_matrix (unitary_group .rvs (2 ))
7069
7170
7271def test_qsharp_integration_4x4 ():
@@ -75,3 +74,12 @@ def test_qsharp_integration_4x4():
7574 check_on_matrix (QFT_2 )
7675 for _ in range (10 ):
7776 check_on_matrix (unitary_group .rvs (4 ))
77+
78+
79+ def test_qsharp_integration_8x8 ():
80+ for _ in range (10 ):
81+ check_on_matrix (unitary_group .rvs (8 ))
82+
83+
84+ def test_qsharp_integration_16x16 ():
85+ check_on_matrix (unitary_group .rvs (16 ))
0 commit comments