Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_Unitary.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 Created on Fri Jun 26 14:42:56 2020
4 Copyright 2020 Peter Rakyta, Ph.D.
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see http://www.gnu.org/licenses/.
20 
21 @author: Peter Rakyta, Ph.D.
22 """
23 
25 
26 
27 
28 # cerate unitary q-bit matrix
29 from scipy.stats import unitary_group
30 import numpy as np
31 
32 
33 try:
34  from mpi4py import MPI
35  MPI_imported = True
36 except ModuleNotFoundError:
37  MPI_imported = False
38 
39 from squander import N_Qubit_Decomposition_adaptive
40 from scipy.io import loadmat
41 
43  # load the unitary from file
44  data = loadmat('data/Umtx.mat')
45  # The unitary to be decomposed
46  Umtx = data['Umtx']
47  # creating a class to decompose the unitary
48  cDecompose = N_Qubit_Decomposition_adaptive( Umtx.conj().T, level_limit_max=5, level_limit_min=0 )
49  Umtx_assert = cDecompose.get_Unitary()
50 
51  assert(np.sum(np.abs(Umtx_assert-Umtx.conj().T))<0.00001)
52 
53  Umtx_assert[0,0]=1
54  cDecompose.set_Unitary(Umtx_assert)
55  Umtx_assert_new=cDecompose.get_Unitary()
56 
57  assert(Umtx_assert_new[0,0]==1)