@@ -53,6 +53,9 @@ def tearDown(self):
53
53
def _create_eigs (matrix , num_ancillae , negative_evals , use_circuit_library = True ):
54
54
# Adding an additional flag qubit for negative eigenvalues
55
55
ne_qfts = [None , None ]
56
+ if not use_circuit_library :
57
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning )
58
+
56
59
if negative_evals :
57
60
num_ancillae += 1
58
61
if use_circuit_library :
@@ -65,25 +68,27 @@ def _create_eigs(matrix, num_ancillae, negative_evals, use_circuit_library=True)
65
68
else :
66
69
iqft = StandardIQFTS (num_ancillae )
67
70
68
- return EigsQPE (MatrixOperator (matrix = matrix ),
69
- iqft ,
70
- num_time_slices = 1 ,
71
- num_ancillae = num_ancillae ,
72
- expansion_mode = 'suzuki' ,
73
- expansion_order = 2 ,
74
- evo_time = None ,
75
- negative_evals = negative_evals ,
76
- ne_qfts = ne_qfts )
71
+ eigs_qpe = EigsQPE (MatrixOperator (matrix = matrix ),
72
+ iqft ,
73
+ num_time_slices = 1 ,
74
+ num_ancillae = num_ancillae ,
75
+ expansion_mode = 'suzuki' ,
76
+ expansion_order = 2 ,
77
+ evo_time = None ,
78
+ negative_evals = negative_evals ,
79
+ ne_qfts = ne_qfts )
80
+
81
+ if not use_circuit_library :
82
+ warnings .filterwarnings ('always' , category = DeprecationWarning )
83
+
84
+ return eigs_qpe
77
85
78
86
@data ([[0 , 1 ], False ], [[1 , 0 ], False ], [[1 , 0.1 ], False ], [[1 , 1 ], False ], [[1 , 10 ], False ],
79
87
[[0 , 1 ], True ], [[1 , 0 ], True ], [[1 , 0.1 ], True ], [[1 , 1 ], True ], [[1 , 10 ], True ])
80
88
@unpack
81
89
def test_hhl_diagonal (self , vector , use_circuit_library ):
82
90
""" hhl diagonal test """
83
91
self .log .debug ('Testing HHL simple test in mode Lookup with statevector simulator' )
84
- if not use_circuit_library :
85
- # ignore deprecation warnings from QFTs
86
- warnings .filterwarnings (action = "ignore" , category = DeprecationWarning )
87
92
88
93
matrix = [[1 , 0 ], [0 , 1 ]]
89
94
@@ -108,9 +113,13 @@ def test_hhl_diagonal(self, vector, use_circuit_library):
108
113
109
114
algo = HHL (matrix , vector , truncate_powerdim , truncate_hermitian , eigs ,
110
115
init_state , reci , num_q , num_a , orig_size )
116
+ if not use_circuit_library :
117
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning )
111
118
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('statevector_simulator' ),
112
119
seed_simulator = aqua_globals .random_seed ,
113
120
seed_transpiler = aqua_globals .random_seed ))
121
+ if not use_circuit_library :
122
+ warnings .filterwarnings ('always' , category = DeprecationWarning )
114
123
115
124
hhl_solution = hhl_result ['solution' ]
116
125
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
@@ -124,9 +133,6 @@ def test_hhl_diagonal(self, vector, use_circuit_library):
124
133
self .log .debug ('fidelity HHL to algebraic: %s' , fidelity )
125
134
self .log .debug ('probability of result: %s' , hhl_result ["probability_result" ])
126
135
127
- if not use_circuit_library :
128
- warnings .filterwarnings (action = "always" , category = DeprecationWarning )
129
-
130
136
@data ([[- 1 , 0 ], False ], [[0 , - 1 ], False ], [[- 1 , - 1 ], False ],
131
137
[[- 1 , 0 ], True ], [[0 , - 1 ], True ], [[- 1 , - 1 ], True ])
132
138
@unpack
@@ -157,9 +163,14 @@ def test_hhl_diagonal_negative(self, vector, use_circuit_library):
157
163
158
164
algo = HHL (matrix , vector , truncate_powerdim , truncate_hermitian , eigs ,
159
165
init_state , reci , num_q , num_a , orig_size )
166
+ if not use_circuit_library :
167
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning )
160
168
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('statevector_simulator' ),
161
169
seed_simulator = aqua_globals .random_seed ,
162
170
seed_transpiler = aqua_globals .random_seed ))
171
+ if not use_circuit_library :
172
+ warnings .filterwarnings ('always' , category = DeprecationWarning )
173
+
163
174
hhl_solution = hhl_result ['solution' ]
164
175
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
165
176
@@ -201,9 +212,12 @@ def test_hhl_diagonal_longdivison(self, vector):
201
212
202
213
algo = HHL (matrix , vector , truncate_powerdim , truncate_hermitian , eigs ,
203
214
init_state , reci , num_q , num_a , orig_size )
215
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning )
204
216
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('statevector_simulator' ),
205
217
seed_simulator = aqua_globals .random_seed ,
206
218
seed_transpiler = aqua_globals .random_seed ))
219
+ warnings .filterwarnings ('always' , category = DeprecationWarning )
220
+
207
221
hhl_solution = hhl_result ['solution' ]
208
222
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
209
223
@@ -246,9 +260,11 @@ def test_hhl_diagonal_qasm(self, vector):
246
260
247
261
algo = HHL (matrix , vector , truncate_powerdim , truncate_hermitian , eigs ,
248
262
init_state , reci , num_q , num_a , orig_size )
263
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning )
249
264
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('qasm_simulator' ), shots = 1000 ,
250
265
seed_simulator = aqua_globals .random_seed ,
251
266
seed_transpiler = aqua_globals .random_seed ))
267
+ warnings .filterwarnings ('always' , category = DeprecationWarning )
252
268
hhl_solution = hhl_result ['solution' ]
253
269
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
254
270
@@ -339,6 +355,7 @@ def test_hhl_negative_eigs(self):
339
355
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('statevector_simulator' ),
340
356
seed_simulator = aqua_globals .random_seed ,
341
357
seed_transpiler = aqua_globals .random_seed ))
358
+
342
359
hhl_solution = hhl_result ["solution" ]
343
360
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
344
361
@@ -380,9 +397,12 @@ def test_hhl_random_hermitian(self):
380
397
381
398
algo = HHL (matrix , vector , truncate_powerdim , truncate_hermitian , eigs ,
382
399
init_state , reci , num_q , num_a , orig_size )
400
+ warnings .filterwarnings ('ignore' , category = DeprecationWarning )
383
401
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('statevector_simulator' ),
384
402
seed_simulator = aqua_globals .random_seed ,
385
403
seed_transpiler = aqua_globals .random_seed ))
404
+ warnings .filterwarnings ('always' , category = DeprecationWarning )
405
+
386
406
hhl_solution = hhl_result ['solution' ]
387
407
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
388
408
@@ -426,6 +446,7 @@ def test_hhl_non_hermitian(self):
426
446
hhl_result = algo .run (QuantumInstance (BasicAer .get_backend ('statevector_simulator' ),
427
447
seed_simulator = aqua_globals .random_seed ,
428
448
seed_transpiler = aqua_globals .random_seed ))
449
+
429
450
hhl_solution = hhl_result ['solution' ]
430
451
hhl_normed = hhl_solution / np .linalg .norm (hhl_solution )
431
452
# compare result
0 commit comments