1919import random
2020import tempfile
2121import unittest
22- import warnings
23- import re
2422
2523import ddt
2624import numpy as np
@@ -925,16 +923,7 @@ def test_pauli_feature_map_legacy(self):
925923 qpy_file = io .BytesIO ()
926924 dump (qc , qpy_file )
927925 qpy_file .seek (0 )
928- with warnings .catch_warnings (record = True ) as w :
929- warnings .simplefilter ("always" )
930- new_circuit = load (qpy_file )[0 ]
931- for warning in w :
932- self .assertFalse (
933- re .search (
934- r"is not fully identical to its pre-serialization state" ,
935- str (warning .message ),
936- )
937- )
926+ new_circuit = load (qpy_file )[0 ]
938927 self .assertEqual (qc , new_circuit )
939928
940929 def test_pauli_feature_map_new (self ):
@@ -945,16 +934,7 @@ def test_pauli_feature_map_new(self):
945934 qpy_file = io .BytesIO ()
946935 dump (qc , qpy_file )
947936 qpy_file .seek (0 )
948- with warnings .catch_warnings (record = True ) as w :
949- warnings .simplefilter ("always" )
950- new_circuit = load (qpy_file )[0 ]
951- for warning in w :
952- self .assertFalse (
953- re .search (
954- r"is not fully identical to its pre-serialization state" ,
955- str (warning .message ),
956- )
957- )
937+ new_circuit = load (qpy_file )[0 ]
958938 self .assertEqual (qc , new_circuit )
959939
960940 def test_zz_feature_map_legacy (self ):
@@ -966,16 +946,7 @@ def test_zz_feature_map_legacy(self):
966946 qpy_file = io .BytesIO ()
967947 dump (qc , qpy_file )
968948 qpy_file .seek (0 )
969- with warnings .catch_warnings (record = True ) as w :
970- warnings .simplefilter ("always" )
971- new_circuit = load (qpy_file )[0 ]
972- for warning in w :
973- self .assertFalse (
974- re .search (
975- r"is not fully identical to its pre-serialization state" ,
976- str (warning .message ),
977- )
978- )
949+ new_circuit = load (qpy_file )[0 ]
979950 self .assertEqual (qc , new_circuit )
980951
981952 def test_zz_feature_map_new (self ):
@@ -986,16 +957,7 @@ def test_zz_feature_map_new(self):
986957 qpy_file = io .BytesIO ()
987958 dump (qc , qpy_file )
988959 qpy_file .seek (0 )
989- with warnings .catch_warnings (record = True ) as w :
990- warnings .simplefilter ("always" )
991- new_circuit = load (qpy_file )[0 ]
992- for warning in w :
993- self .assertFalse (
994- re .search (
995- r"is not fully identical to its pre-serialization state" ,
996- str (warning .message ),
997- )
998- )
960+ new_circuit = load (qpy_file )[0 ]
999961 self .assertEqual (qc , new_circuit )
1000962
1001963 def test_real_amplitudes_legacy (self ):
@@ -1007,16 +969,7 @@ def test_real_amplitudes_legacy(self):
1007969 qpy_file = io .BytesIO ()
1008970 dump (qc , qpy_file )
1009971 qpy_file .seek (0 )
1010- with warnings .catch_warnings (record = True ) as w :
1011- warnings .simplefilter ("always" )
1012- new_circuit = load (qpy_file )[0 ]
1013- for warning in w :
1014- self .assertFalse (
1015- re .search (
1016- r"is not fully identical to its pre-serialization state" ,
1017- str (warning .message ),
1018- )
1019- )
972+ new_circuit = load (qpy_file )[0 ]
1020973 self .assertEqual (qc , new_circuit )
1021974
1022975 def test_real_amplitudes_new (self ):
@@ -1027,16 +980,7 @@ def test_real_amplitudes_new(self):
1027980 qpy_file = io .BytesIO ()
1028981 dump (qc , qpy_file )
1029982 qpy_file .seek (0 )
1030- with warnings .catch_warnings (record = True ) as w :
1031- warnings .simplefilter ("always" )
1032- new_circuit = load (qpy_file )[0 ]
1033- for warning in w :
1034- self .assertFalse (
1035- re .search (
1036- r"is not fully identical to its pre-serialization state" ,
1037- str (warning .message ),
1038- )
1039- )
983+ new_circuit = load (qpy_file )[0 ]
1040984 self .assertEqual (qc , new_circuit )
1041985
1042986 def test_duplicated_param_name_legacy (self ):
@@ -1053,16 +997,7 @@ def test_duplicated_param_name_legacy(self):
1053997 qpy_file = io .BytesIO ()
1054998 dump (qc , qpy_file )
1055999 qpy_file .seek (0 )
1056- with warnings .catch_warnings (record = True ) as w :
1057- warnings .simplefilter ("always" )
1058- new_circuit = load (qpy_file )[0 ]
1059- for warning in w :
1060- self .assertFalse (
1061- re .search (
1062- r"is not fully identical to its pre-serialization state" ,
1063- str (warning .message ),
1064- )
1065- )
1000+ new_circuit = load (qpy_file )[0 ]
10661001 self .assertEqual (qc , new_circuit )
10671002
10681003 def test_duplicated_param_name_new (self ):
@@ -1078,16 +1013,7 @@ def test_duplicated_param_name_new(self):
10781013 qpy_file = io .BytesIO ()
10791014 dump (qc , qpy_file )
10801015 qpy_file .seek (0 )
1081- with warnings .catch_warnings (record = True ) as w :
1082- warnings .simplefilter ("always" )
1083- new_circuit = load (qpy_file )[0 ]
1084- for warning in w :
1085- self .assertFalse (
1086- re .search (
1087- r"is not fully identical to its pre-serialization state" ,
1088- str (warning .message ),
1089- )
1090- )
1016+ new_circuit = load (qpy_file )[0 ]
10911017 self .assertEqual (qc , new_circuit )
10921018
10931019 def test_parameter_expression_global_phase (self ):
@@ -1165,8 +1091,7 @@ def dump_load_param_vec(qc):
11651091 x = ParameterVector ("γ" , 2 )
11661092 qc = QuantumCircuit (3 )
11671093 qc .rzz (x [0 ], 0 , 1 )
1168- with self .assertWarns (UserWarning ):
1169- params , new_params , vector , new_vector = dump_load_param_vec (qc )
1094+ params , new_params , vector , new_vector = dump_load_param_vec (qc )
11701095
11711096 self .assertTrue (all (p == q for p , q in zip (params , new_params )))
11721097 # vector[0] is part of the circuit
@@ -1209,19 +1134,6 @@ def test_parameter_vector_element_in_expression(self):
12091134 self .assertEqual ([x .name for x in new_circuit .parameters ], expected_params )
12101135 self .assertDeprecatedBitProperties (qc , new_circuit )
12111136
1212- def test_parameter_vector_incomplete_warns (self ):
1213- """Test that qpy's deserialization warns if a ParameterVector isn't fully identical."""
1214- vec = ParameterVector ("test" , 3 )
1215- qc = QuantumCircuit (1 , name = "fun" )
1216- qc .rx (vec [1 ], 0 )
1217- qpy_file = io .BytesIO ()
1218- dump (qc , qpy_file )
1219- qpy_file .seek (0 )
1220- with self .assertWarnsRegex (UserWarning , r"^The ParameterVector.*Elements 0, 2.*fun$" ):
1221- new_circuit = load (qpy_file )[0 ]
1222- self .assertEqual (qc , new_circuit )
1223- self .assertDeprecatedBitProperties (qc , new_circuit )
1224-
12251137 def test_parameter_vector_global_phase (self ):
12261138 """Test that a circuit with a standalone ParameterVectorElement phase works."""
12271139 vec = ParameterVector ("phase" , 1 )
0 commit comments