Code Monkey home page Code Monkey logo

scikit-quant's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scikit-quant's Issues

SNOBFIT number of requested points varies

Description

I ran the test03_Hartman6 test on the SNOBFIT implementation within the test_snobfit.py file with a number of required points per iteration of 2. I ran into an issue where SNOBFIT sometimes gives back more points than requested.

What I Did

Modified options in test03_Hartman6 to options = optset(maxmp=2,maxfail=10,verbose=True):

    def test03_Hartman6(self):
        """Minimize Hartman6 function"""

        import SQSnobFit

        def Hartman6(x):
            import numpy, math

            a = numpy.array(
                [[10.00,  0.05,  3.00, 17.00],
                 [ 3.00, 10.00,  3.50,  8.00],
                 [17.00, 17.00,  1.70,  0.05],
                 [ 3.50,  0.10, 10.00, 10.00],
                 [ 1.70,  8.00, 17.00,  0.10],
                 [ 8.00, 14.00,  8.00, 14.00]])

            p = numpy.array(
                [[0.1312, 0.2329, 0.2348, 0.4047],
                 [0.1696, 0.4135, 0.1451, 0.8828],
                 [0.5569, 0.8307, 0.3522, 0.8732],
                 [0.0124, 0.3736, 0.2883, 0.5743],
                 [0.8283, 0.1004, 0.3047, 0.1091],
                 [0.5886, 0.9991, 0.6650, 0.0381]])

            c = numpy.array([1.0, 1.2, 3.0, 3.2])

            d = numpy.zeros((4,))
            for i in range(4):
                d[i] = sum(a[:,i]*(x - p[:,i])**2)

            return -(c.dot(numpy.exp(-d)))

        def run_Hartman6(self, initial, expected):
            self.reset()

            bounds = np.array([[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]], dtype=float)
            budget = 250
            x0 = np.array(initial)

            from SQSnobFit import optset
            options = optset(maxmp=2,maxfail=10,verbose=True)
            result, history = SQSnobFit.minimize(Hartman6, x0, bounds, budget,options)

            assert np.round(sum(result.optpar)-sum(expected), 8) == 0

      # note: results are still subtly different from the reference, but the most likely
      # reason seems to be that the respective random number generators differ slightly
        run_Hartman6(self, [],      (0.2077,  0.14892, 0.4829,  0.2725,  0.31493, 0.66138))
        run_Hartman6(self, [0.5]*6, (0.20133, 0.1504,  0.47666, 0.27787, 0.3134,  0.65797))

I get the following result (I've marked the request with a higher number of requested points than 2):

request = [[0.89286015 0.57815346 0.07768236 0.82398406 0.61309601 0.95036579
         nan 5.        ]
 [0.05883729 0.89005364 0.84576855 0.01697197 0.97897697 0.14854018
         nan 5.        ]]
request = [[0.97629 0.04186 0.94599 0.51713 0.2887  0.18941     nan 5.     ]
 [0.05876 0.10166 0.03849 0.26412 0.15659 0.44159     nan 5.     ]]
request = [[0.052   0.38448 0.97762 0.81783 0.96246 0.98059     nan 5.     ]
 [0.19055 0.9258  0.98402 0.89153 0.08593 0.34229     nan 5.     ]]
request = [[9.9989e-01 7.4012e-01 2.7337e-01 1.8640e-02 1.5576e-01 3.3094e-01
         nan 5.0000e+00]
 [2.3390e-02 1.2100e-03 5.3584e-01 8.8518e-01 8.4055e-01 5.9060e-02
         nan 5.0000e+00]]
request = [[0.96048 0.98487 0.71085 0.64254 0.90261 0.12699     nan 5.     ]
 [0.02968 0.82501 0.06012 0.63189 0.80609 0.34523     nan 5.     ]]
request = [[0.51829 0.03263 0.88006 0.00706 0.12744 0.97094     nan 5.     ]
 [0.38494 0.07751 0.29262 0.26018 0.98906 0.88073     nan 5.     ]]
request = [[ 0.          0.          0.          0.          0.          0.98059
  -1.41873597  1.        ]
 [ 0.2673      0.55083     0.27487     0.63206     0.36219     0.7208
  -0.34840448  4.        ]]
--> request = [[ 0.          0.          0.          0.61224     0.          0.
  -1.84636489  1.        ]
 [ 0.12856     0.          0.          0.55454     0.          0.17209
  -1.62324414  2.        ]
 [ 0.3332      0.4629      0.74764     0.44576     0.32686     0.67114
  -0.18665852  4.        ]]
---> request = [[ 0.          0.86071     1.          0.          0.          0.8859
  -2.85157809  1.        ]
 [ 0.06884     0.57652     1.          0.22288     0.03394     0.82573
  -2.13363498  2.        ]
 [ 0.73787     0.37006     0.13668     0.21998     0.57788     0.66547
   0.39287415  4.        ]]
request = [[ 0.          0.30945     0.03849     0.          0.35441     0.18941
  -1.98193446  1.        ]
 [ 0.71816     0.74912     0.85542     0.32127     0.4513      0.56349
  -0.23594006  4.        ]]
---> request = [[ 0.          0.9258      0.6901      0.          0.          0.18941
  -5.84222689  1.        ]
 [ 0.07181     0.23145     0.91633     0.5753      0.39138     0.43028
  -2.54690387  2.        ]
 [ 0.68435     0.28908     0.29476     0.62265     0.30655     0.47518
  -0.21179275  4.        ]]
---> request = [[ 0.73787     0.          0.41905     0.          0.          0.34229
  -8.62727512  1.        ]
 [ 0.50639     0.29965     0.85187     0.66864     0.19106     0.83556
  -2.39295023  2.        ]
 [ 0.84218     0.64454     0.14738     0.81132     0.65328     0.23759
   3.47860584  4.        ]]
---> request = [[   0.            0.9258        0.13668       0.89153       0.
     0.4329     -134.4518582     1.        ]
 [   0.26718       0.4512        0.70861       0.31965       0.45421
     0.75705      -1.6486614     2.        ]
 [   0.84218       0.14454       0.14738       0.81132       0.65328
     0.23759      -0.27089426    4.        ]]
---> request = [[  0.64886      0.9258       0.13668      0.46274      0.
    0.99999    -10.16803038   1.        ]
 [  0.           0.           0.10364      0.44809      0.36724
    0.71109     -3.59657935   3.        ]
 [  0.86894      0.68503      0.32426      0.10999      0.78894
    0.33274      0.12086235   4.        ]]
request = [[ 0.          0.          0.26346     0.27472     0.51888     0.
  -2.93065464  1.        ]
 [ 0.85908     0.87456     0.68363     0.66063     0.22565     0.28174
   0.75573179  4.        ]]
request = [[ 0.          0.          0.74764     0.44619     0.21767     0.89227
  -3.51881477  1.        ]
 [ 0.19247     0.53875     0.46387     0.63009     0.77842     0.72265
  -0.06157975  4.        ]]
request = [[ 0.00899     0.55083     0.          0.46539     0.40727     0.
  -2.08025501  1.        ]
 [ 0.72607     0.27761     0.72891     0.25857     0.64435     0.38479
  -0.02950477  4.        ]]
request = [[ 0.19018     0.          0.31879     0.34778     0.48282     0.69368
  -1.80282844  1.        ]
 [ 0.65901     0.82227     0.32961     0.61632     0.32664     0.47518
  -0.18339269  4.        ]]
iteration limit exceeded
request = [[ 0.26173     0.          0.0271      0.35173     0.46291     0.59357
  -1.75492949  1.        ]
 [ 0.24962     0.22342     0.26792     0.44259     0.70417     0.31181
  -0.15499457  4.        ]]
---> request = [[ 0.68435     0.          0.60446     0.36189     0.5509      1.
  -2.11153083  1.        ]
 [ 0.26492     0.          0.46178     0.20564     0.2297      0.88134
  -2.22086722  3.        ]
 [ 0.26392     0.69224     0.80637     0.40892     0.76512     0.77258
  -0.57544502  4.        ]]
request = [[ 0.15663    0.         0.39287    0.         0.31965    0.769
  -2.033972   1.       ]
 [ 0.27234    0.28826    0.75563    0.61144    0.10717    0.41286
  -0.8198376  4.       ]]
---> request = [[ 0.21826     0.          0.35807     0.35516     0.33239     0.87419
  -1.8853654   1.        ]
 [ 0.49267     0.27939     0.56059     0.14516     0.28362     0.68141
  -2.3059765   3.        ]
 [ 0.13365     0.77541     0.13743     0.81603     0.1811      0.8604
  -0.07613432  4.        ]]
request = [[ 0.46337     0.55083     0.74764     0.          0.14129     0.44159
  -2.54599304  1.        ]
 [ 0.84218     0.14454     0.14738     0.81132     0.15328     0.23759
   0.33506744  4.        ]]
---> request = [[ 0.15545     0.          0.33414     0.41882     0.37664     1.
  -2.03854979  1.        ]
 [ 0.55764     0.37213     0.34864     0.29546     0.10326     0.73512
  -3.12552855  3.        ]
 [ 0.86894     0.68503     0.32426     0.10999     0.78894     0.83274
  -0.29258697  4.        ]]
request = [[ 0.36123     0.          0.25368     0.71032     0.10326     0.73289
  -4.81062133  1.        ]
 [ 0.85908     0.87456     0.68363     0.16063     0.22565     0.28174
   0.46192447  4.        ]]
---> request = [[ 0.23763     0.37213     0.26952     0.16564     0.25554     0.61599
  -2.49092568  1.        ]
 [ 0.46328     0.40314     0.40086     0.          0.46399     0.81035
  -3.06256371  3.        ]
 [ 0.8295      0.64454     0.1648      0.80816     0.16332     0.23759
   0.09248796  4.        ]]
request = [[ 0.          0.74426     0.          0.16053     0.38958     0.79237
  -3.96842798  1.        ]
 [ 0.66069     0.1397      0.55394     0.29546     0.38322     0.53664
  -3.83934096  3.        ]
 [ 0.33416     0.76938     0.23194     0.31504     0.88921     0.86132
   0.11101123  4.        ]]
---> request = [[ 0.20112     0.41643     0.42064     0.27255     0.1915      0.56934
  -2.36233287  1.        ]
 [ 0.07762     0.44998     0.48345     0.0362      0.1419      0.48331
  -3.04322045  3.        ]
 [ 0.12481     0.11171     0.63396     0.2213      0.85208     0.1559
   0.18174653  4.        ]]
---> request = [[ 0.43081     0.74426     0.          0.16617     0.34431     0.35064
  -2.7617182   1.        ]
 [ 0.41128     0.          0.26203     0.32686     0.10314     0.72534
  -3.21356483  3.        ]
 [ 0.86303     0.1388      0.86445     0.62928     0.82218     0.1924
  -0.09160735  4.        ]]
request = [[ 0.29159     0.24496     0.39705     0.273       0.33191     0.59915
  -2.37248558  1.        ]
 [ 0.13196     0.34612     0.90318     0.20446     0.88256     0.88629
  -0.08032674  4.        ]]
---> request = [[ 0.19876     0.          0.70861     0.14295     0.10314     0.31696
  -4.63951771  1.        ]
 [ 0.27027     0.16283     0.40188     0.31113     0.4463      0.45806
  -4.13745185  2.        ]
 [ 0.25276     0.63532     0.25653     0.31594     0.68694     0.17262
  -0.06935558  4.        ]]
---> request = [[ 0.          0.2638      0.23351     0.19928     0.56068     0.83329
  -4.63088256  1.        ]
 [ 0.29818     0.36744     0.44016     0.4095      0.4463      0.74024
  -6.07245938  2.        ]
 [ 0.86894     0.18503     0.20952     0.21066     0.18341     0.67114
  -0.90515389  4.        ]]
---> request = [[ 0.26731     0.27686     0.56059     0.22553     0.31562     0.54548
  -3.06887361  1.        ]
 [ 0.252       0.21625     0.45756     0.20475     0.32353     0.60682
  -3.26522436  2.        ]
 [ 0.66746     0.69396     0.84181     0.83032     0.4513      0.64087
  -0.04699162  4.        ]]
---> request = [[ 0.32128     0.28949     0.26952     0.14093     0.48282     0.53301
  -3.24200901  1.        ]
 [ 0.07062     0.18384     0.70612     0.33564     0.22876     0.65127
  -5.18693164  3.        ]
 [ 0.65901     0.82227     0.32961     0.61632     0.82664     0.47518
  -0.02498895  4.        ]]
request = [[ 0.11565     0.14862     0.45779     0.19728     0.1881      0.64927
  -3.36321401  1.        ]
 [ 0.26734     0.66784     0.64936     0.50849     0.77338     0.35655
  -0.02454716  4.        ]]
request = [[ 0.16191     0.20307     0.53639     0.27491     0.40809     0.67238
  -3.23535212  1.        ]
 [ 0.13367     0.83392     0.82468     0.75424     0.88669     0.17828
  -0.41012949  4.        ]]
request = [[ 0.36388     0.12336     0.36316     0.20202     0.25335     0.67963
  -3.17927921  1.        ]
 [ 0.71816     0.74912     0.85542     0.32127     0.78978     0.56349
  -0.05832895  4.        ]]
request = [[ 0.24966     0.17658     0.48077     0.26854     0.31009     0.65807
  -3.11712424  1.        ]
 [ 0.67239     0.34252     0.16213     0.26565     0.57788     0.16637
  -0.22498647  4.        ]]
request = [[ 3.18190000e-01  1.52250000e-01  5.98380000e-01  3.40110000e-01
   3.12370000e-01  7.35810000e-01 -3.69634169e+00  1.00000000e+00]
 [ 2.63920000e-01  6.92240000e-01  8.06370000e-01  7.15600000e-01
   7.65120000e-01  7.72580000e-01 -3.30484926e-03  4.00000000e+00]]
iteration limit exceeded
request = [[ 1.15650000e-01  3.39420000e-01  3.63160000e-01  4.09500000e-01
   1.73880000e-01  7.92320000e-01 -4.17350833e+00  1.00000000e+00]
 [ 6.59010000e-01  3.05680000e-01  3.29610000e-01  6.16320000e-01
   8.26640000e-01  4.75180000e-01 -2.26254535e-03  4.00000000e+00]]
request = [[ 0.23962     0.16331     0.43733     0.38433     0.22535     0.61096
  -3.33013233  1.        ]
 [ 0.37151     0.2256      0.8543      0.65982     0.511       0.37852
  -1.44719633  4.        ]]
iteration limit exceeded
---> request = [[ 0.21263     0.25251     0.36316     0.24646     0.32113     0.79236
  -3.43564682  1.        ]
 [ 0.44198     0.04466     0.63463     0.39929     0.37934     0.64065
  -5.07468163  3.        ]
 [ 0.83034     0.32653     0.65195     0.64773     0.19161     0.26832
  -1.31761941  4.        ]]
---> request = [[ 0.21872     0.          0.47263     0.2774      0.30729     0.63163
  -3.42645976  1.        ]
 [ 0.2154      0.49838     0.15849     0.          0.13977     1.
  -4.85670738  3.        ]
 [ 0.6682      0.68606     0.17432     0.14773     0.23504     0.36756
  -0.25210638  4.        ]]
---> request = [[ 0.24679     0.1275      0.52785     0.26925     0.31147     0.65824
  -3.31937489  1.        ]
 [ 0.2913      0.          0.54955     0.22394     0.3594      0.50677
  -4.0106712   3.        ]
 [ 0.7532      0.14982     0.68185     0.83432     0.09553     0.70787
  -0.88554552  4.        ]]
---> request = [[ 0.23028     0.14227     0.46583     0.28444     0.32513     0.66787
  -3.31075843  1.        ]
 [ 0.35643     0.28992     0.47882     0.28308     0.40077     0.69576
  -3.91136435  3.        ]
 [ 0.67239     0.27755     0.36068     0.10533     0.27511     0.83557
  -0.63257159  4.        ]]
---> request = [[ 0.18023     0.161       0.48237     0.29683     0.31678     0.64693
  -3.3334547   1.        ]
 [ 0.24005     0.07613     0.49772     0.27243     0.26451     0.83098
  -3.91626166  3.        ]
 [ 0.12638     0.81766     0.12826     0.15797     0.84347     0.36859
  -0.53248663  4.        ]]
request = [[ 0.2093      0.14973     0.48064     0.28542     0.3159      0.65291
  -3.31024376  1.        ]
 [ 0.27234     0.28826     0.75563     0.61144     0.10717     0.72251
  -0.5188296   4.        ]]
---> request = [[ 0.20072     0.13549     0.48255     0.28994     0.31086     0.66079
  -3.32173354  1.        ]
 [ 0.1944      0.09192     0.74195     0.26646     0.31842     0.53077
  -4.54984368  3.        ]
 [ 0.13365     0.41312     0.13743     0.81603     0.1811      0.8604
  -0.4947544   4.        ]]
---> request = [[ 0.19842     0.13665     0.46986     0.2743      0.31554     0.65062
  -3.32065978  1.        ]
 [ 0.24966     0.12626     0.27318     0.42992     0.25718     0.75291
  -4.60413709  3.        ]
 [ 0.30476     0.63978     0.63881     0.87712     0.72724     0.37142
  -0.46868477  4.        ]]
request = [[ 0.20572     0.14341     0.46853     0.27918     0.31228     0.65287
  -3.31938407  1.        ]
 [ 0.13367     0.83392     0.82468     0.38561     0.88669     0.17828
  -0.56051866  4.        ]]
request = [[ 0.20599     0.14394     0.46494     0.27884     0.31102     0.6535
  -3.32039317  1.        ]
 [ 0.84218     0.14454     0.14738     0.81132     0.15328     0.59398
  -0.37641793  4.        ]]
request = [[ 0.20969     0.13792     0.4738      0.28081     0.30792     0.64383
  -3.32270347  1.        ]
 [ 0.86894     0.18503     0.32426     0.10999     0.78894     0.83274
  -0.29258697  4.        ]]
---> request = [[ 0.19927     0.15847     0.48453     0.27072     0.30919     0.66458
  -3.32747361  1.        ]
 [ 0.16885     0.06313     0.1685      0.31597     0.3342      0.68194
  -4.45718181  3.        ]
 [ 0.84218     0.25668     0.80223     0.68094     0.77545     0.79009
  -0.26706055  4.        ]]
request = [[ 0.07133     0.05144     0.2503      0.24991     0.25989     0.58582
  -3.95802693  3.        ]
 [ 0.85908     0.87456     0.68363     0.16063     0.22565     0.78174
  -0.18771372  4.        ]]
request = [[ 0.37993     0.28935     0.84284     0.4069      0.56694     0.65127
  -3.8392923   3.        ]
 [ 0.30033     0.27867     0.81698     0.44259     0.70993     0.36023
  -0.17501925  4.        ]]
request = [[ 0.46832     0.18606     0.27427     0.          0.19161     0.09565
  -3.74892815  3.        ]
 [ 0.8295      0.64454     0.1648      0.80816     0.16332     0.59398
  -0.15893089  4.        ]]
request = [[ 0.33047     0.18939     0.37786     0.54387     0.3342      0.68194
  -3.72162546  3.        ]
 [ 0.8766      0.33159     0.84092     0.58608     0.23326     0.85394
  -0.14799916  4.        ]]
request = [[ 0.1587      0.2298      0.58195     0.40482     0.1391      0.59923
  -3.71874478  3.        ]
 [ 0.7532      0.1658      0.67638     0.46196     0.11663     0.71706
  -0.88695793  4.        ]]
request = [[ 0.          0.13788     0.58195     0.40482     0.31842     0.71152
  -4.34888057  3.        ]
 [ 0.3332      0.81008     0.74764     0.66865     0.32686     0.67114
  -0.14577737  4.        ]]
request = [[ 0.          0.13788     0.58799     0.30105     0.1391      0.71152
  -3.87537914  3.        ]
 [ 0.33416     0.76938     0.23194     0.81504     0.88921     0.86132
  -0.1383031   4.        ]]
Traceback (most recent call last):
  File "test_snobfit.py", line 152, in <module>
    tester.test03_Hartman6()
  File "test_snobfit.py", line 130, in test03_Hartman6
    run_Hartman6(self, [],      (0.2077,  0.14892, 0.4829,  0.2725,  0.31493, 0.66138))
  File "test_snobfit.py", line 126, in run_Hartman6
    assert np.round(sum(result.optpar)-sum(expected), 8) == 0
AssertionError

What might cause this:

The loop in lines 515-528 of _snobfit.py generates a new requested point before checking the break statement (whether number of generated points for request equals number of requested points by user):

    for l in isplit.flatten():
        jj = find(ind==l)
        ind = numpy.delete(ind, jj) #ind(jj) = []
        y1, f1 = snobpoint(x[l], xl[l], xu[l], f[l,0:2], g[l], sigma[l], u1, v1, dx)

        if numpy.max(numpy.abs(y1-x[l]) - dx) >= -numpy.spacing(1) and \
                (not sreq or numpy.min( \
                     numpy.max(numpy.abs(request[:,:n] - numpy.outer(numpy.ones(sreq), y1)) - \
                     numpy.outer(numpy.ones(sreq), dx), axis=1)) >= -numpy.spacing(1)):
            request = numpy.vstack((request, numpy.concatenate((y1, numpy.array((f1, 4), ndmin=2)), axis=1)))

        sreq = len(request)
        if sreq == nreq:
            break

Possible adjustment:

Moving the the break statement to the beginning of the loop (see below). This solves the issue, however I'm not sure whether this is correct, as in the original SNOBFIT Matlab code (v2.1) the break statement is also at the end of the loop.

    for l in isplit.flatten():
        if sreq == nreq:
            break
        jj = find(ind==l)
        ind = numpy.delete(ind, jj) #ind(jj) = []
        y1, f1 = snobpoint(x[l], xl[l], xu[l], f[l,0:2], g[l], sigma[l], u1, v1, dx)

        if numpy.max(numpy.abs(y1-x[l]) - dx) >= -numpy.spacing(1) and \
                (not sreq or numpy.min( \
                     numpy.max(numpy.abs(request[:,:n] - numpy.outer(numpy.ones(sreq), y1)) - \
                     numpy.outer(numpy.ones(sreq), dx), axis=1)) >= -numpy.spacing(1)):
            request = numpy.vstack((request, numpy.concatenate((y1, numpy.array((f1, 4), ndmin=2)), axis=1)))

        sreq = len(request)

_snobfit.py, line 208

    request, xbest, fbest = snobfit(x0.reshape(1, len(x0)),
        numpy.array([objfunc(x0), math.sqrt(numpy.spacing(1))]).reshape(1, 2),
        config, dx)

Is it intended that one can specify only one initial point x0? For a two-dimensional problem with e.g. 8 initial points I get:

    _snobfit.py", line 209, in minimize
         request, xbest, fbest = snobfit(x0.reshape(1, len(x0)),
      ValueError: cannot reshape array of size 16 into shape (1,8)

Example for x0:
[[260 471]
[269 421]
[263 195]
[248 292]
[282 203]
[249 27]
[285 399]
[237 189]]

_imfil.py, line 149

if not isinstance(x0, numpy.ndarray):
x0 = numpy.array(x0, shape=(len(x), 1))

I suppose there is a small typo, instead of len(x), it should be len(x0). Also the shape argument in np.array() seems to be outdated.

A simple fix would be

x0 = numpy.reshape(x0, (len(x0), 1))

minimize function options

Is minimize function allow constraints parameter. If yes can you please give some example code for that. your help very much appreciated.

error in imfil with multivariate function (3/4)

Code to produce the error:

import numpy as np
from skquant.opt import minimize

def g(a):
    return a[0]**2 - a[0] +a[1]**3 -4*a[1]

bounds=np.array([[0,2],[-2,2]],dtype=np.float)
init=np.array([1.,0.])
res,hist=minimize(g,init,bounds,method='imfil')

The error:

Traceback (most recent call last):
  File "/Users/sumneralperin-lea/science_git/Tequila/examples/debug.py", line 16, in <module>
    res,hist=minimize(g,init,bounds,method='imfil')
  File "/Users/sumneralperin-lea/git/scikit-quant/skquant/opt/__init__.py", line 54, in minimize
    return optimizer.minimize(func, x0, bounds, budget, options, **optkwds)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_imfil.py", line 208, in minimize
    imfil_core(z0, f_internal, budget, core_data, bounds)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_imfil.py", line 402, in imfil_core
    error_check('first_eval', funs, options, iff)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_util.py", line 33, in error_check
    return check_first_eval(funs, options, iflag)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_util.py", line 75, in check_first_eval
    mf, nf = funs.shape
ValueError: not enough values to unpack (expected 2, got 0)

This one is somewhat weird; when I look at this file throwing the error on your github, it isn't identical, but when I install either the package as downloaded by pip install or by installing from the git repository, I still get the same file version that is throwing the error.

skquant.interopt not installed

I just installed scikit-quant into a fresh venv on Python 3.9.1 (on Windows) and while the direct interface works, the Scipy interface does not.
It looks like skquant.interopt is not installed at all (I get ModuleNotFoundError: No module named 'skquant.interopt' on import.)

Is there something I should have done to install it? I have not found anything in the documentation, so I assumed it would just work.

I installed the package using python -m pip install scikit-quant[NOMAD]. The package version is 0.8.2.

I know nothing about Python packaging, but I have noticed that __all__ in skquant/__init__.py does not include interopt - could it be connected?

documentation for minimize function

For the minimize function what are all the parameters we need to pass do you have any documentation for parameters with description and also we can pass kwargs for last parameter. What are key value pairs we can pass in kwargs. If you have any documentation with some examples it would be a great help for us.

SQNomad installation issue

Could not build wheels for SQNomad which use PEP 517 and cannot be installed directl. Your help is very much appreciated!

System Specifications:
Python Version: 3.7
OS: Windows 10

Error with snobfit for a complicated function (4/4, kinda long)

Alright, this one is tougher to go into detail, since I haven't actually managed to write a simple example that reproduces the error, so I have to dig a little deeper here. Sorry for the trouble.

Background:

I'm trying to interface skquant optimization in another package i'm developing, as a way to optimize (functions of) quantum circuits. This involves some wrappers that convert arrays into dictionaries; the important part is I have callable objects where a dictionary goes in, and a float comes out.

The code basically looks like this: the object called my_object here is a callable; essentially, a parametrized quantum circuit, with some bells and whistles on top. it takes a single argument, variables, which have to match the named parameters inside it for it to work. it's return type is a float.

def parse_array(objective,passives,arr):
 op = objective.extract_variables() ### this is a list of hashables
    if passives is not None: ### passives is a dictionary of variables NOT to optimize.
        for i, thing in enumerate(op):
            if thing in passives.keys():
                op.remove(thing)
    if arr.shape ==():
        array=numpy.asarray([arr])
    else:
        array=arr
    back={v:array[i] for i,v in enumerate(op)}
    if passives is not None:
        for k,v in passives.items():
            back[k]=v
    return back

def get_skquant_function(my_object,passive_variables):
    return lambda array: my_object(variables=parse_array(my_object,passive_variables,array)

def call_skquant(my_object,initial_values,variables,maxiter,method)
   
        active_angles = {}
        for v in variables:
            active_angles[v] = initial_values[v]

        passive_angles = {}
        for k, v in initial_values.items():
            if k not in active_angles.keys():
                passive_angles[k] = v

        bounds=numpy.array([[-2*numpy.pi,2*numpy.pi] for k in  active_angles.keys()],dtype=numpy.float)
        f = get_skquant_function(my_object,passive_angles)
        start_array=numpy.array([active_angles[k] for k in active_angles.keys()],dtype=numpy.float)
        result, hist = skquant.opt.minimize(f,start_array,bounds,budget=maxiter,method=method)

The error is thrown in this case by a circuit that has four active variables and no passive ones.

the error I get, from my real code, with a little extra information, is here:

../../../git/scikit-quant/skquant/opt/__init__.py:54: in minimize
    return optimizer.minimize(func, x0, bounds, budget, options, **optkwds)
../../../anaconda3/envs/quantum/lib/python3.6/site-packages/SQSnobFit/_snobfit.py:223: in minimize
    request, xbest, fbest = snobfit(x, vals, config)
../../../anaconda3/envs/quantum/lib/python3.6/site-packages/SQSnobFit/_snobfit.py:374: in snobfit
    y[j], f[j,2], c, sigma[j] = snoblocf(j, x, f[:,0:2], near, dx, u, v)
../../../anaconda3/envs/quantum/lib/python3.6/site-packages/SQSnobFit/_snoblocf.py:98: in snoblocf
    y = snobround(x0+p, u, v, dx)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

x = array([[ 0.11950618,  6.28318531, -6.12598001, -0.20483184]])
u = array([[-6.28318531, -6.28318531, -6.28318531, -6.28318531]])
v = array([[6.28318531, 6.28318531, 6.28318531, 6.28318531]])
dx = array([0.00012566, 0.00012566, 0.00012566, 0.00012566])

    def snobround(x, u, v, dx):
        """
          function x = snobround(x, u, v, dx)
    
          A point x is projected into the interior of [u, v] and x[i] is
          rounded to the nearest integer multiple of dx[i].
    
          Input:
          x         vector of length n
          u, v      vectors of length n such that u < v
          dx        vector of length n
    
          Output:
          x         projected and rounded version of x
        """
    
        x = numpy.minimum(numpy.maximum(x,u), v)
        x = numpy.round(x/dx)*dx
        i1 = find(x<u)
        if i1.size > 0:
            x[i1] = x[i1] + dx[i1]
    
        i2 = find(x>v)
        if i2.size > 0:
>           x[i2] = x[i2] - dx[i2]
E           IndexError: index 1 is out of bounds for axis 0 with size 1

../../../anaconda3/envs/quantum/lib/python3.6/site-packages/SQSnobFit/_snoblocf.py:168: IndexError

I'll try to get a more complete test case up in running if the problem isn't sufficiently clear.

High maxfail causes error

Description

I ran the test03_Hartman6 test on the SNOBFIT implementation within the test_snobfit.py file with a high threshold for stopping, setting maxfail to high values (about >20). This causes in issue with line 354 in snobfit.py when calling snobupdt.py.

What I Did

Run test03_Hartman6 with options = optset(maxmp=6+6, maxfail=500), same with values for maxfail > 20:

    def test03_Hartman6(self):
    """Minimize Hartman6 function"""

    import SQSnobFit

        def Hartman6(x):
            import numpy, math

            a = numpy.array(
                [[10.00,  0.05,  3.00, 17.00],
                 [ 3.00, 10.00,  3.50,  8.00],
                 [17.00, 17.00,  1.70,  0.05],
                 [ 3.50,  0.10, 10.00, 10.00],
                 [ 1.70,  8.00, 17.00,  0.10],
                 [ 8.00, 14.00,  8.00, 14.00]])

            p = numpy.array(
                [[0.1312, 0.2329, 0.2348, 0.4047],
                 [0.1696, 0.4135, 0.1451, 0.8828],
                 [0.5569, 0.8307, 0.3522, 0.8732],
                 [0.0124, 0.3736, 0.2883, 0.5743],
                 [0.8283, 0.1004, 0.3047, 0.1091],
                 [0.5886, 0.9991, 0.6650, 0.0381]])

            c = numpy.array([1.0, 1.2, 3.0, 3.2])

            d = numpy.zeros((4,))
            for i in range(4):
                d[i] = sum(a[:,i]*(x - p[:,i])**2)

            return -(c.dot(numpy.exp(-d)))

        def run_Hartman6(self, initial, expected, options=None):
            self.reset()

            bounds = np.array([[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]], dtype=float)
            budget = 2000
            x0 = np.array(initial)

            from SQSnobFit import optset
            if options is None:
                options = optset(maxmp=6+6, maxfail=500)
            result, history = SQSnobFit.minimize(Hartman6, x0, bounds, budget, options)

            assert np.round(sum(result.optpar)-sum(expected), 8) == 0

      # note: results are still subtly different from the reference, but the errors seem to
      # accumulate over many iterations, not produced by a single step going wrong and the
      # results here actually slightly outperform (?)
        run_Hartman6(self, [],      (0.20687, 0.14968, 0.48076, 0.27357, 0.3145,  0.66129))
        run_Hartman6(self, [0.5]*6, (0.21015, 0.12032, 0.46593, 0.27053, 0.30835, 0.66478))

      # regression: the following used to fail
        run_Hartman6(self, [],      (0.02423, 0.12107, 0.98254, 0.05482, 0.07433, 0.86491), {'maxmp' : 1})
        run_Hartman6(self, [],      (0.24101, 0.16523, 0.43633, 0.28035, 0.31964, 0.64909), {'maxmp' : 2, 'maxfail' : 10})

I got the following error:

Traceback (most recent call last):
  File "test_snobfit.py", line 258, in <module>
    tester.test03_Hartman6()
  File "test_snobfit.py", line 133, in test03_Hartman6
    run_Hartman6(self, [],      (0.20687, 0.14968, 0.48076, 0.27357, 0.3145,  0.66129))
  File "test_snobfit.py", line 126, in run_Hartman6
    result, history = SQSnobFit.minimize(Hartman6, x0, bounds, budget, options)
  File "..\python\SQSnobFit\_snobfit.py", line 223, in minimize
    request, xbest, fbest = snobfit(x, vals, config)
  File "..\python\SQSnobFit\_snobfit.py", line 354, in snobfit
    snobupdt(xl, xu, x, f, nsplit, small, near, d, np, t, xnew, fnew, fnan, u, v, u1, v1, dx)
  File "..\python\SQSnobFit\_snobupdt.py", line 185, in snobupdt
    xl[j] = xl0[k]
ValueError: could not broadcast input array from shape (2,1,6) into shape (6)

What might cause this:

At some point in line 184 k = find(numpy.sum(x0 == numpy.ones((nxj,1))*x[j,:], axis=1) == n) of _snobupt.py k contains more than one value.

Ask-and-tell interface

Really nice project! Making these optimizers available in Python is a great idea!
I would be very interested in using them but for my research it would be desirable to have control over the optimizer rather than having the optimizer control my objective function.

Currently, the objective function is passed to minimize:

result, history = \
    minimize(objective_function, x0, bounds, budget, method='imfil')

I was wondering if you would consider providing an ask-and-tell interface too?
This is how that could look like:

opt = MyOptimizer(...)
sim = MyComplexSimulation(...)
func = MyFunction(...)

while not opt.stop():
    x = optimizer.ask()

    # Here we start a complex simulation or an experiment in the real world.
    # This is usually not only a single function call and I would like to have
    # control and not be controlled by the optimizer.
    result = sim.do_simulation(x, ...)
    y = func(result)

    optimizer.tell(x, y)

copy-pasted from this issue: scikit-optimize/scikit-optimize#68

error with snobfit for univariate function (2/4)

For snobfit with one variable, the following code throws the following error:

import numpy as np
from skquant.opt import minimize

def f(a):
    return a[0]**2 - a[0]

bounds=np.array([[0,2]],dtype=np.float)
init=np.array([1.])
res,hist=minimize(f,init,bounds,method='snobfit')

Traceback (most recent call last):
  File "/Users/sumneralperin-lea/science_git/Tequila/examples/debug.py", line 9, in <module>
    res,hist=minimize(f,init,bounds,method='snobfit')
  File "/Users/sumneralperin-lea/git/scikit-quant/skquant/opt/__init__.py", line 54, in minimize
    return optimizer.minimize(func, x0, bounds, budget, options, **optkwds)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQSnobFit/_snobfit.py", line 223, in minimize
    request, xbest, fbest = snobfit(x, vals, config)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQSnobFit/_snobfit.py", line 374, in snobfit
    y[j], f[j,2], c, sigma[j] = snoblocf(j, x, f[:,0:2], near, dx, u, v)
IndexError: index 2 is out of bounds for axis 1 with size 2

(edited to fix formatting)

Optimizer questions

I have a question:

  1. Do the optimization algorithms support parallel computing, typically Nomad?

Thank you,
Jenny

SQNomad Installtion issue

Operating System: Windows 10
Python version: 3.7.4

I tried to install SQNomad with pip. It is giving below error.

C:\IPMBOLT\Platform\oct-dist\Python37>python -m pip install SQNomad
Collecting SQNomad
Using cached SQNomad-0.2.3.tar.gz (455 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: SQCommon in c:\ipmbolt\platform\oct-dist\python37\lib\site-packages (from SQNomad) (0.3.2)
Requirement already satisfied: numpy in c:\ipmbolt\platform\oct-dist\python37\lib\site-packages (from SQNomad) (1.17.1+mkl)
Building wheels for collected packages: SQNomad
Building wheel for SQNomad (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: 'C:\IPMBOLT\Platform\oct-dist\Python37\python.exe' 'C:\IPMBOLT\Platform\oct-dist\Python37\lib\site-packages\pip_vendor\pep517_in_process.py' build_wheel 'C:\Users\pentipra\AppData\Local\Temp\tmp6j8mtzgw'
cwd: C:\Users\pentipra\AppData\Local\Temp\pip-install-f9rjvq59\sqnomad_f7171878c0cf4f298ae72dccd1254df5
Complete output (143 lines):
running bdist_wheel
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
running build_src
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\SQNomad
copying python\SQNomad_nomad.py -> build\lib.win-amd64-3.7\SQNomad
copying python\SQNomad_version.py -> build\lib.win-amd64-3.7\SQNomad
copying python\SQNomad_init_.py -> build\lib.win-amd64-3.7\SQNomad
running build_ext
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
customize MSVCCompiler
customize MSVCCompiler using my_build_extension
CCompilerOpt.cc_test_flags[999] : testing flags (/O2)
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils
creating C:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks
CCompilerOpt.cc_test_flags[999] : testing flags (/WX)
CCompilerOpt.init[1147] : feature 'AVX512_KNL' is disabled, MSVC compiler doesn't support it
CCompilerOpt.init[1147] : feature 'AVX512_KNM' is disabled, MSVC compiler doesn't support it
CCompilerOpt.init[1674] : check requested baseline
CCompilerOpt.cc_test_flags[999] : testing flags (/arch:SSE)
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[701] : Flags in command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\test_flags.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\test_flags.obj /arch:SSE) aren't supported by the compiler, output ->
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE'
test_flags.c

CCompilerOpt.cc_test_flags[1003] : testing failed
CCompilerOpt.cc_test_flags[999] : testing flags (/arch:SSE2)
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[701] : Flags in command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\test_flags.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\test_flags.obj /arch:SSE2) aren't supported by the compiler, output ->
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
test_flags.c

CCompilerOpt.cc_test_flags[1003] : testing failed
CCompilerOpt.feature_test[1446] : testing feature 'SSE2' with flags ()
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse2.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse2.obj /WX) failed with exit status 2 output ->
cpu_sse2.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.feature_test[1446] : testing feature 'SSE' with flags ()
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse.obj /WX) failed with exit status 2 output ->
cpu_sse.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.init[1683] : check requested dispatch-able features
CCompilerOpt.cc_test_flags[999] : testing flags (/arch:AVX)
CCompilerOpt.cc_test_flags[999] : testing flags (/arch:AVX2)
CCompilerOpt.feature_test[1446] : testing feature 'AVX2' with flags (/arch:AVX2)
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_avx2.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_avx2.obj /arch:AVX2 /WX) failed with exit status 2 output ->
cpu_avx2.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.cc_test_flags[999] : testing flags (/arch:AVX512)
CCompilerOpt.feature_test[1446] : testing feature 'AVX512CD' with flags (/arch:AVX512)
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_avx512cd.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_avx512cd.obj /arch:AVX512 /WX) failed with exit status 2 output ->
cpu_avx512cd.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.feature_test[1446] : testing feature 'SSE42' with flags ()
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse42.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse42.obj /WX) failed with exit status 2 output ->
cpu_sse42.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.feature_test[1446] : testing feature 'AVX512_CLX' with flags (/arch:AVX512)
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_avx512_clx.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_avx512_clx.obj /arch:AVX512 /WX) failed with exit status 2 output ->
cpu_avx512_clx.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.feature_test[1446] : testing feature 'SSE3' with flags ()
CCompilerOpt.dist_test[576] : CCompilerOpt._dist_test_spawn[713] : Command (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /TcC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse3.c /FoC:\Users\pentipra\AppData\Local\Temp\tmpgazn7idg\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\distutils\checks\cpu_sse3.obj /WX) failed with exit status 2 output ->
cpu_sse3.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include\xmmintrin.h(75): fatal error C1083: Cannot open include file: 'malloc.h': No such file or directory

CCompilerOpt.feature_test[1458] : testing failed
CCompilerOpt.init[1699] : initialize targets groups
CCompilerOpt.init[1701] : parse target group simd_test
CCompilerOpt._parse_target_tokens[1912] : skip targets ((AVX2 FMA3) VSX2 VSX3 XOP SSE42 NEON AVX512F VSX FMA4 ASIMD SSE2 AVX512_SKX) not part of baseline or dispatch-able features
CCompilerOpt.generate_dispatch_header[2236] : generate CPU dispatch header: (C:\Users\pentipra\AppData\Local\Temp\src.win-amd64-3.7\numpy\distutils\include\npy_cpu_dispatch_config.h)
Detected changes on compiler optimizations, force rebuilding
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
customize MSVCCompiler
Missing compiler_cxx fix for MSVCCompiler
customize MSVCCompiler using my_build_extension
building 'libsqnomad' extension
compiling C sources
creating build\temp.win-amd64-3.7\Release\src
creating build\temp.win-amd64-3.7\Release\src\Algos
creating build\temp.win-amd64-3.7\Release\src\Cache
creating build\temp.win-amd64-3.7\Release\src\Eval
creating build\temp.win-amd64-3.7\Release\src\Math
creating build\temp.win-amd64-3.7\Release\src\Output
creating build\temp.win-amd64-3.7\Release\src\Param
creating build\temp.win-amd64-3.7\Release\src\Python
creating build\temp.win-amd64-3.7\Release\src\sgtelib
creating build\temp.win-amd64-3.7\Release\src\Type
creating build\temp.win-amd64-3.7\Release\src\Util
creating build\temp.win-amd64-3.7\Release\src\Algos\LatinHypercubeSampling
creating build\temp.win-amd64-3.7\Release\src\Algos\Mads
creating build\temp.win-amd64-3.7\Release\src\Algos\NelderMead
creating build\temp.win-amd64-3.7\Release\src\Algos\PhaseOne
creating build\temp.win-amd64-3.7\Release\src\Algos\PSDMads
creating build\temp.win-amd64-3.7\Release\src\Algos\QuadModel
creating build\temp.win-amd64-3.7\Release\src\Algos\SgtelibModel
creating build\temp.win-amd64-3.7\Release\src\Algos\SSDMads
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc -IC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\core\include -IC:\Users\pentipra\AppData\Local\Temp\src.win-amd64-3.7\numpy\distutils\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /EHsc /Tpsrc\Algos\Algorithm.cpp /Fobuild\temp.win-amd64-3.7\Release\src\Algos\Algorithm.obj -IC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\core/include/numpy /std:c++14 /DDLL_EXPORTS /Zm1000
Algorithm.cpp
src\Algos\Algorithm.cpp(47): fatal error C1083: Cannot open include file: 'signal.h': No such file or directory

########### EXT COMPILER OPTIMIZATION ###########
Platform :
Architecture: x64
Compiler : msvc

CPU baseline :
Requested : 'min'
Enabled : none
Flags : none
Extra checks: none

CPU dispatch :
Requested : 'max -xop -fma4'
Enabled : none
Generated : none
CCompilerOpt._cache_write[796] : write cache to path -> C:\Users\pentipra\AppData\Local\Temp\pip-install-f9rjvq59\sqnomad_f7171878c0cf4f298ae72dccd1254df5\build\temp.win-amd64-3.7\Release\ccompiler_opt_cache_ext.py
error: Command "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc -IC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\core\include -IC:\Users\pentipra\AppData\Local\Temp\src.win-amd64-3.7\numpy\distutils\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\IPMBOLT\Platform\oct-dist\Python37\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include /EHsc /Tpsrc\Algos\Algorithm.cpp /Fobuild\temp.win-amd64-3.7\Release\src\Algos\Algorithm.obj -IC:\Users\pentipra\AppData\Local\Temp\pip-build-env-w4wehrr6\overlay\Lib\site-packages\numpy\core/include/numpy /std:c++14 /DDLL_EXPORTS /Zm1000" failed with exit status 2

ERROR: Failed building wheel for SQNomad
Failed to build SQNomad
ERROR: Could not build wheels for SQNomad which use PEP 517 and cannot be installed directly

Compatibility with NumPy 1.24.0 and above

In 1.24.0 NumPy followed through with deprecation warnings on constructing arrays of ragged sequences (e.g. array([[1,2], [3]])) which seems to break the snobfit optimizer. Here's a minimal example

import numpy as np
from skquant.opt import minimize

def objective_function(x):
    res = np.prod([np.cos(x_i) for i, x_i in enumerate(x)])
    return res

budget = 40

x0 = 0.5 * np.ones(10)

# bounds = [(-3.1415, 3.1415)] * x0.size  # works!
bounds = [(-3.14, 3.14)] * x0.size  # breaks!

result, history = minimize(objective_function, x0, bounds, method="snobfit")
print(result)

leading to

  File "/Users/jul/opt/miniconda3/envs/py10/lib/python3.10/site-packages/SQSnobFit/_snobfit.py", line 522, in snobfit
    request = numpy.vstack((request, numpy.concatenate((y1, numpy.array((f1, 3), ndmin=2)), axis=1)))
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

It seems that the construction numpy.array((f1, 3), ndim=2) breaks as f1 is not a float but wrapped into a list twice, like [[value]] instead of value. Maybe that happens when if-clause on L515 is taken? But that's just a guess since the error only occurs for some settings (see the different bounds above).

The above snippet was run on

scikit-quant==0.8.2
SQSnobFit==0.4.5
numpy==1.24.0

SNOBFIT error for initialization with nreq=1

Description

I ran the test03_Hartman6 test on the SNOBFIT implementation within the test_snobfit.py file with a number of required points per iteration of 1 and no initial points given. This causes in issue with line 331 in snobfit.py when calling snob5.py.

What I Did

Run test03_Hartman6 with options = optset(maxmp=1):

    def test03_Hartman6(self):
        """Minimize Hartman6 function"""

        import SQSnobFit

        def Hartman6(x):
            import numpy, math

            a = numpy.array(
                [[10.00,  0.05,  3.00, 17.00],
                 [ 3.00, 10.00,  3.50,  8.00],
                 [17.00, 17.00,  1.70,  0.05],
                 [ 3.50,  0.10, 10.00, 10.00],
                 [ 1.70,  8.00, 17.00,  0.10],
                 [ 8.00, 14.00,  8.00, 14.00]])

            p = numpy.array(
                [[0.1312, 0.2329, 0.2348, 0.4047],
                 [0.1696, 0.4135, 0.1451, 0.8828],
                 [0.5569, 0.8307, 0.3522, 0.8732],
                 [0.0124, 0.3736, 0.2883, 0.5743],
                 [0.8283, 0.1004, 0.3047, 0.1091],
                 [0.5886, 0.9991, 0.6650, 0.0381]])

            c = numpy.array([1.0, 1.2, 3.0, 3.2])

            d = numpy.zeros((4,))
            for i in range(4):
                d[i] = sum(a[:,i]*(x - p[:,i])**2)

            return -(c.dot(numpy.exp(-d)))

        def run_Hartman6(self, initial, expected):
            self.reset()

            bounds = np.array([[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]], dtype=float)
            budget = 250
            x0 = np.array(initial)

            from SQSnobFit import optset
            options = optset(maxmp=1,verbose=True)
            config = {"bounds": bounds, "nreq": 1, "p": .5}
            result, history = SQSnobFit.minimize(Hartman6, x0, bounds, budget, config, optin=options)
            print(result)
            assert np.round(sum(result.optpar)-sum(expected), 8) == 0


      # note: results are still subtly different from the reference, but the most likeley
      # reason seems to be that the respective random number generators differ slightly
        run_Hartman6(self, [],      (0.2077,  0.14892, 0.4829,  0.2725,  0.31493, 0.66138))
        run_Hartman6(self, [0.5]*6, (0.20133, 0.1504,  0.47666, 0.27787, 0.3134,  0.65797))

I get the following error:

Traceback (most recent call last):
  File "test_snobfit.py", line 383, in <module>
    tester.test03_Hartman6()
  File "test_snobfit.py", line 132, in test03_Hartman6
    run_Hartman6(self, [],      (0.2077,  0.14892, 0.4829,  0.2725,  0.31493, 0.66138))
  File "test_snobfit.py", line 125, in run_Hartman6
    result, history = SQSnobFit.minimize(Hartman6, x0, bounds, budget, config, optin=options)
  File "..\python\SQSnobFit\_snobfit.py", line 206, in minimize
    config, dx)
  File "..\python\SQSnobFit\_snobfit.py", line 338, in snobfit
    request = numpy.concatenate((x5, numpy.nan*numpy.ones((nreq,1)), 5*numpy.ones((nreq,1))), 1)
numpy.AxisError: axis 1 is out of bounds for array of dimension 1

What might cause this:

_snob5.py returns a one-dimensional array if nreq=1 and no initial points are given.

Possible adjustment:

Change line 73 in _snob5.py from x5 = xnew[0,:] to x5 = [xnew[0,:]]

ValueError: setting an array element with a sequence in _snobfit.py

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
^ This is the error that I get from from line 482 in _snobfit.py:
request = numpy.vstack((request, numpy.concatenate((y1, numpy.array((f1, 2), ndmin=2)), axis=1)))
After a superficial inspection, it appears that the issue stems from the preceding block of code:

if numpy.sum(y1 == y[l0]) < n:
    D = f[l0,1]/dx**2
    #Possibly problem area!
    f1 = f[l0,0] + g[l0].dot((y1 - x[l0]).T) + sigma[l0]*( \
        (y1 - x[l0]).dot(diag(D).dot((y1-x[l0]).T) + f[l0,1]))
else:
    f1 = f[l0,2]

If the execution goes through the else clause, then the type of f1 is a plain float, but if it goes through the if clause, then the type of f1 is a 1x1 numpy array that would not be type-compatible with numpy.array((f1, 2), ndmin=2) part of line 482.

One way to solve this is to add numpy.squeeze(f1), at least as long as the array remains 1x1:
request = numpy.vstack((request, numpy.concatenate((y1, numpy.array((numpy.squeeze(f1), 2), ndmin=2)), axis=1)))

The same issue also happens on line 522 for the same reasons.

Errors with imfil for univariate functions

I'll be posting four different issues since, even though the code to reproduce them is nearly the same, the four cases throw different errors.

To reproduce the first error

import numpy as np
from skquant.opt import minimize

def f(a):
    return a**2 - a

bounds=np.array([[0,2]],dtype=np.float)
init=np.array([1.])
res,hist=minimize(f,init,bounds,method='imfil')

Error is:

Traceback (most recent call last):
  File "/Users/sumneralperin-lea/science_git/Tequila/examples/debug.py", line 9, in <module>
    res,hist=minimize(f,init,bounds,method='imfil')
  File "/Users/sumneralperin-lea/git/scikit-quant/skquant/opt/__init__.py", line 54, in minimize
    return optimizer.minimize(func, x0, bounds, budget, options, **optkwds)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_imfil.py", line 208, in minimize
    imfil_core(z0, f_internal, budget, core_data, bounds)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_imfil.py", line 391, in imfil_core
    funs, iff, icf, noise_val = f(x, h, core_data)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQImFil/_imfil.py", line 591, in f_internal
    res = objfunc(*call_args)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQCommon/_objective.py", line 39, in __call__
    self.stats.add_history(val, par)
  File "/Users/sumneralperin-lea/anaconda3/envs/quantum/lib/python3.6/site-packages/SQCommon/_stats.py", line 14, in add_history
    self._history.append([fval]+list(par))
TypeError: iteration over a 0-d array

Typo in readme

In the readme (and in pypi) you write pip install sckit-quant. However when I try installing through that command I get the following error

ERROR: Could not find a version that satisfies the requirement sckit-quant
ERROR: No matching distribution found for sckit-quant

Could it be that you have a typo? It works fine if I try pip install scikit-quant.

nomad nonlinear constraints

Can we pass non linear constraints to minimize function. if yes can you give me some example. Your help would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.