4 Created on Fri Jun 26 14:42:56 2020 5 Copyright 2020 Peter Rakyta, Ph.D. 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 11 http://www.apache.org/licenses/LICENSE-2.0 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see http://www.gnu.org/licenses/. 22 @author: Peter Rakyta, Ph.D. 29 from scipy.stats
import unitary_group
32 from squander
import utils
35 from mpi4py
import MPI
37 except ModuleNotFoundError:
42 qiskit_version = qiskit.version.get_version_info()
44 from qiskit
import QuantumCircuit
47 if qiskit_version[0] ==
'1' or qiskit_version[0] ==
'2':
48 from qiskit
import transpile
49 import qiskit_aer
as Aer
51 from qiskit
import execute
52 from qiskit
import Aer
59 This method is called by pytest. 60 Test to decompose a 4-qubit unitary State 65 from scipy.io
import loadmat
69 data = loadmat(
'data/Umtx.mat')
73 Umtx = data[
'Umtx'].conj().T
77 with pytest.raises(Exception):
78 cDecompose = qgd_N_Qubit_State_Preparation_adaptive(Umtx,
79 level_limit_max=5, level_limit_min=0)
84 from scipy.io
import loadmat
88 data = loadmat(
'data/Umtx.mat')
93 State = Umtx[:, 0].reshape(16, 1)
94 norm = np.sqrt( State.conj().T @ State )
98 config = {
'max_outer_iterations': 1,
99 'max_inner_iterations': 10000,
100 'max_inner_iterations_compression': 10000,
101 'max_inner_iterations_final': 1000,
102 'randomization_threshold':
int(1e4),
103 'Randomized_Radius': 0.3,
104 'randomized_adaptive_layers': 1,
105 'optimization_tolerance_agent': 1e-4,
106 'optimization_tolerance': 1e-4,
107 'compression_enabled': compression_enabled,
108 'number_of_agents': 4}
113 cDecompose = qgd_N_Qubit_State_Preparation_adaptive(State,
114 level_limit_max=5, level_limit_min=0, config = config)
118 cDecompose.set_Verbose(3)
122 cDecompose.set_Cost_Function_Variant(cost_func)
126 cDecompose.set_Optimizer(optimizer)
130 cDecompose.Start_Decomposition()
134 cDecompose.List_Gates()
138 circuit_qiskit = cDecompose.get_Qiskit_Circuit()
142 print (circuit_qiskit)
145 decomp_error = cDecompose.Optimization_Problem_Combined(cDecompose.get_Optimized_Parameters())[0]
146 assert decomp_error < 1e-4
147 print(f
"DECOMPOSITION ERROR: {decomp_error} ")
150 if qiskit_version[0] ==
'1' or qiskit_version[0] ==
'2':
152 circuit_qiskit.save_statevector()
154 backend = Aer.AerSimulator(method=
'statevector')
155 compiled_circuit = transpile(circuit_qiskit, backend)
156 result = backend.run(compiled_circuit).
result()
158 transformed_state = result.get_statevector(compiled_circuit)
161 elif qiskit_version[0] ==
'0':
164 simulator = Aer.get_backend(
'statevector_simulator')
166 backend = Aer.get_backend(
'aer_simulator')
167 result = execute(circuit_qiskit, simulator).
result()
169 transformed_state = result.get_statevector(circuit_qiskit)
171 overlap = np.abs( np.asarray(transformed_state).conj().T @ State )
173 print(
'Overlap integral with the initial state: ', overlap )
174 assert( np.abs(overlap - 1) < 1e-4 )
181 This method is called by pytest. 182 Test for a 4 qubit state preparation using the BFGS optimizer 190 This method is called by pytest. 191 Test for a 4 qubit state preparation using the Hilbert Schmidt test def test_State_Preparation_adaptive_false(self)
def State_Preparation_adaptive_base(self, optimizer, cost_func, compression_enabled=1)
def test_State_Preparation_BFGS(self)
def test_State_Preparation_HS(self)
result
the result of the Qiskit job