33import pytest
44import time
55
6- """
7- some definitions
8- Classical 1= the combination of (Spider parser, spider ansatz, pytorch model, pytorchtrainer)
9- Classical 2= the combination of (bobCatParser , spider ansatz, pytorch model, pytorchtrainer)
10- Quantum1= (IQPansatz+TKetmodel+Quantum Trainer+ bob cat parser)- this runs on a simulation f a quantum computer
11- Quantum2 = **Quantum2-simulation-actual quantum computer**=(penny lane model, bob cat parser, iqp ansatz, pytorchtrainer):
12- """
13- # def test_food_it_classical1(monkeypatch):
6+ # """
7+ # some definitions
8+ # Classical 1= the combination of (Spider parser, spider ansatz, pytorch model, pytorchtrainer)
9+ # Classical 2= the combination of (bobCatParser , spider ansatz, pytorch model, pytorchtrainer)
10+ # Quantum1= (IQPansatz+TKetmodel+Quantum Trainer+ bob cat parser)- this runs on a simulation f a quantum computer
11+ # Quantum2 = **Quantum2-simulation-actual quantum computer**=(penny lane model, bob cat parser, iqp ansatz, pytorchtrainer):
12+ # """
13+ # # def test_food_it_classical1(monkeypatch):
14+ # # monkeypatch.setattr(sys, 'argv',
15+ # # ['classify.py',
16+ # # '--dataset', 'food_it',
17+ # # '--parser', 'Spider'
18+ # # ])
19+ # # smart_loss, smart_acc=classify.main()
20+ # # assert round(smart_loss,2) == 0.32
21+ # # assert round(smart_acc,1) >= 0.8
22+ # # assert round(smart_acc,1) <= 0.9
23+
24+
25+ # #for a combination of train=20,val=10,test=10+exposing val data during initialization of model 1
26+ # def test_sst2_classical1_yes_expose_val(monkeypatch):
1427# monkeypatch.setattr(sys, 'argv',
1528# ['classify.py',
16- # '--dataset', 'food_it',
17- # '--parser', 'Spider'
29+ # '--dataset', 'sst2',
30+ # '--parser', 'Spider',
31+ # '--ansatz', 'SpiderAnsatz',
32+ # '--model14type', 'PytorchModel',
33+ # '--trainer', 'PytorchTrainer',
34+ # '--epochs_train_model1', '7',
35+ # '--no_of_training_data_points_to_use', '20',
36+ # '--no_of_val_data_points_to_use', '10',
37+ # '--expose_model1_val_during_model_initialization',
38+ # '--max_tokens_per_sent', '10'
39+ # ])
40+ # model4_loss, model4_acc=classify.main()
41+ # assert round(model4_loss,2) >= 0.6
42+ # assert round(model4_loss,2) <= 0.7
43+ # assert round(model4_acc,1) >= 0.5
44+ # assert round(model4_acc,1) <= 0.6
45+
46+
47+ # #for a combination of train=20,val=10,test=10 +not exposing val data during initialization of model 1
48+ # """
49+ # python classify.py --dataset sst2 --parser Spider --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10
50+ # """
51+ # def test_sst2_classical1_no_expose_val(monkeypatch):
52+ # monkeypatch.setattr(sys, 'argv',
53+ # ['classify.py',
54+ # '--dataset', 'sst2',
55+ # '--parser', 'Spider',
56+ # '--ansatz', 'SpiderAnsatz',
57+ # '--model14type', 'PytorchModel',
58+ # '--trainer', 'PytorchTrainer',
59+ # '--epochs_train_model1', '7',
60+ # '--no_of_training_data_points_to_use', '20',
61+ # '--no_of_val_data_points_to_use', '10',
62+ # '--max_tokens_per_sent', '10'
63+ # ])
64+ # model4_loss, model4_acc=classify.main()
65+ # assert round(model4_loss,2) >= 0.6
66+ # assert round(model4_loss,2) <= 0.7
67+ # assert round(model4_acc,1) >= 0.5
68+ # assert round(model4_acc,1) <= 0.65
69+
70+
71+ # """#for a combination of all classical 1 components+train=20,val=10,test=10 + yes exposing val data during initialization of model 1
72+ # the actual command used to run this will be:
73+ # python classify.py --dataset sst2 --parser BobCatParser --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10 --expose_model1_val_during_model_initialization
74+ # """
75+ # def test_sst2_classical2_yes_expose_val(monkeypatch):
76+ # monkeypatch.setattr(sys, 'argv',
77+ # ['classify.py',
78+ # '--dataset', 'sst2',
79+ # '--parser', 'Spider',
80+ # '--ansatz', 'SpiderAnsatz',
81+ # '--model14type', 'PytorchModel',
82+ # '--trainer', 'PytorchTrainer',
83+ # '--epochs_train_model1', '7',
84+ # '--no_of_training_data_points_to_use', '20',
85+ # '--no_of_val_data_points_to_use', '10',
86+ # '--max_tokens_per_sent', '10' ,
87+ # '--expose_model1_val_during_model_initialization'
1888# ])
19- # smart_loss, smart_acc=classify.main()
20- # assert round(smart_loss,2) == 0.32
21- # assert round(smart_acc,1) >= 0.8
22- # assert round(smart_acc,1) <= 0.9
89+ # try:
2390
91+ # model4_loss, model4_acc=classify.main()
92+ # except Exception as ex:
93+ # print(ex)
94+ # assert type(ex) == RuntimeError
95+
2496
25- #for a combination of train=20,val=10,test=10+exposing val data during initialization of model 1
26- def test_sst2_classical1_yes_expose_val (monkeypatch ):
27- monkeypatch .setattr (sys , 'argv' ,
28- ['classify.py' ,
29- '--dataset' , 'sst2' ,
30- '--parser' , 'Spider' ,
31- '--ansatz' , 'SpiderAnsatz' ,
32- '--model14type' , 'PytorchModel' ,
33- '--trainer' , 'PytorchTrainer' ,
34- '--epochs_train_model1' , '7' ,
35- '--no_of_training_data_points_to_use' , '20' ,
36- '--no_of_val_data_points_to_use' , '10' ,
37- '--expose_model1_val_during_model_initialization' ,
38- '--max_tokens_per_sent' , '10'
39- ])
40- model4_loss , model4_acc = classify .main ()
41- assert round (model4_loss ,2 ) >= 0.6
42- assert round (model4_loss ,2 ) <= 0.7
43- assert round (model4_acc ,1 ) >= 0.5
44- assert round (model4_acc ,1 ) <= 0.6
4597
4698
47- #for a combination of train=20,val=10,test=10 +not exposing val data during initialization of model 1
48- """
49- python classify.py --dataset sst2 --parser Spider --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10
50- """
51- def test_sst2_classical1_no_expose_val (monkeypatch ):
52- monkeypatch .setattr (sys , 'argv' ,
53- ['classify.py' ,
54- '--dataset' , 'sst2' ,
55- '--parser' , 'Spider' ,
56- '--ansatz' , 'SpiderAnsatz' ,
57- '--model14type' , 'PytorchModel' ,
58- '--trainer' , 'PytorchTrainer' ,
59- '--epochs_train_model1' , '7' ,
60- '--no_of_training_data_points_to_use' , '20' ,
61- '--no_of_val_data_points_to_use' , '10' ,
62- '--max_tokens_per_sent' , '10'
63- ])
64- model4_loss , model4_acc = classify .main ()
65- assert round (model4_loss ,2 ) >= 0.6
66- assert round (model4_loss ,2 ) <= 0.7
67- assert round (model4_acc ,1 ) >= 0.5
68- assert round (model4_acc ,1 ) <= 0.65
99+ # """#for a combination of all classical 1 components+train=20,val=10,test=10 + not exposing val data during initialization of model 1
100+ # the actual command used to run this will be:
101+ # python classify.py --dataset sst2 --parser BobCatParser --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10
102+ # """
103+
104+ # def test_sst2_classical2_no_expose_val(monkeypatch):
105+ # monkeypatch.setattr(sys, 'argv',
106+ # ['classify.py',
107+ # '--dataset', 'sst2',
108+ # '--parser', 'Spider',
109+ # '--ansatz', 'SpiderAnsatz',
110+ # '--model14type', 'PytorchModel',
111+ # '--trainer', 'PytorchTrainer',
112+ # '--epochs_train_model1', '7',
113+ # '--no_of_training_data_points_to_use', '20',
114+ # '--no_of_val_data_points_to_use', '10',
115+ # '--max_tokens_per_sent', '10'
116+ # ])
117+ # try:
69118
119+ # model4_loss, model4_acc=classify.main()
120+ # except Exception as ex:
121+ # print(ex)
122+ # assert type(ex) == RuntimeError
70123
71- """#for a combination of all classical 1 components+train=20,val=10,test=10 + yes exposing val data during initialization of model 1
72- the actual command used to run this will be:
73- python classify.py --dataset sst2 --parser BobCatParser --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10 --expose_model1_val_during_model_initialization
74- """
75- def test_sst2_classical2_yes_expose_val (monkeypatch ):
76- monkeypatch .setattr (sys , 'argv' ,
77- ['classify.py' ,
78- '--dataset' , 'sst2' ,
79- '--parser' , 'Spider' ,
80- '--ansatz' , 'SpiderAnsatz' ,
81- '--model14type' , 'PytorchModel' ,
82- '--trainer' , 'PytorchTrainer' ,
83- '--epochs_train_model1' , '7' ,
84- '--no_of_training_data_points_to_use' , '20' ,
85- '--no_of_val_data_points_to_use' , '10' ,
86- '--max_tokens_per_sent' , '10' ,
87- '--expose_model1_val_during_model_initialization'
88- ])
89- try :
90124
91- model4_loss , model4_acc = classify .main ()
92- except Exception as ex :
93- print (ex )
94- assert type (ex ) == RuntimeError
95-
125+ # # python classify.py --dataset uspantek --parser Spider --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10
96126
127+ # def test_uspantek_classical1_no_expose_val(monkeypatch):
128+ # monkeypatch.setattr(sys, 'argv',
129+ # ['classify.py',
130+ # '--dataset', 'uspantek',
131+ # '--parser', 'Spider',
132+ # '--ansatz', 'SpiderAnsatz',
133+ # '--model14type', 'PytorchModel',
134+ # '--trainer', 'PytorchTrainer',
135+ # '--epochs_train_model1', '7',
136+ # '--no_of_training_data_points_to_use', '20',
137+ # '--no_of_val_data_points_to_use', '10',
138+ # '--max_tokens_per_sent', '10'
139+ # ])
140+ # model4_loss, model4_acc=classify.main()
141+ # assert round(model4_loss,2) >= 0.6
142+ # assert round(model4_loss,2) <= 0.75
143+ # assert round(model4_acc,1) >= 0.4
144+ # assert round(model4_acc,1) <= 0.5
97145
98146
99- """#for a combination of all classical 1 components+train=20,val=10,test=10 + not exposing val data during initialization of model 1
100- the actual command used to run this will be:
101- python classify.py --dataset sst2 --parser BobCatParser --ansatz SpiderAnsatz --model14type PytorchModel --trainer PytorchTrainer --epochs_train_model1 7 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10
102- """
103147
104- def test_sst2_classical2_no_expose_val (monkeypatch ):
148+ def test_uspantek_classical1_yes_expose_val (monkeypatch ):
105149 monkeypatch .setattr (sys , 'argv' ,
106150 ['classify.py' ,
107- '--dataset' , 'sst2 ' ,
151+ '--dataset' , 'uspantek ' ,
108152 '--parser' , 'Spider' ,
109153 '--ansatz' , 'SpiderAnsatz' ,
110154 '--model14type' , 'PytorchModel' ,
111155 '--trainer' , 'PytorchTrainer' ,
112156 '--epochs_train_model1' , '7' ,
113157 '--no_of_training_data_points_to_use' , '20' ,
114158 '--no_of_val_data_points_to_use' , '10' ,
115- '--max_tokens_per_sent' , '10'
159+ '--max_tokens_per_sent' , '10' ,
160+ '--expose_model1_val_during_model_initialization'
116161 ])
117- try :
118-
119- model4_loss , model4_acc = classify .main ()
120- except Exception as ex :
121- print (ex )
122- assert type (ex ) == RuntimeError
123-
124- """# Quantum1= (IQPansatz+TKetmodel+Quantum Trainer+ bob cat parser)- this runs on a simulation f a quantum computer
125-
126- python classify.py --dataset sst2 --parser BobCatParser --ansatz IQPAnsatz --model14type TketModel --trainer QuantumTrainer --epochs_train_model1 30 --no_of_training_data_points_to_use 20 --no_of_val_data_points_to_use 10 --max_tokens_per_sent 10
127- note: this combination is just stuck in the first .fit(). - most likely due to less
128- memory to handle all the circuits.. so for now calling
129- it time out error, just to move on with ife
130- """
131-
132- # @pytest.mark.timeout(30)
133- # def test_sst2_quantum1_no_expose_val(monkeypatch):
134- # try:
135- # monkeypatch.setattr(sys, 'argv',
136- # ['classify.py',
137- # '--dataset', 'sst2',
138- # '--parser', 'BobCatParser',
139- # '--ansatz', 'IQPAnsatz',
140- # '--model14type', 'TketModel',
141- # '--trainer', 'QuantumTrainer',
142- # '--epochs_train_model1', '30',
143- # '--no_of_training_data_points_to_use', '20',
144- # '--no_of_val_data_points_to_use', '10',
145- # '--max_tokens_per_sent', '10'
146- # ])
147-
148- # model4_loss, model4_acc=classify.main()
149- # except Exception as ex:
150- # assert type(ex) == TypeError
151-
152-
153-
154- # def test_sst2_quantum1_no_expose_val_with_timeout(monkeypatch):
155- # try:
156- # sst2_quantum1_no_expose_val(monkeypatch)
157- # except Exception as ex:
158- # assert type(ex) == TypeError
159-
160- # def main(monkeypatch):
161- # test_sst2_quantum1_no_expose_val_with_timeout(monkeypatch)
162-
163-
164- # if __name__=="__main__":
165- # main()
166-
167-
168-
169-
170-
162+ model4_loss , model4_acc = classify .main ()
163+ assert round (model4_loss ,2 ) >= 0.6
164+ assert round (model4_loss ,2 ) <= 0.7
165+ assert round (model4_acc ,1 ) >= 0.5
166+ assert round (model4_acc ,1 ) <= 0.6
0 commit comments