paulknysh / blackbox

A Python module for parallel optimization of expensive black-box functions
MIT License
439 stars 60 forks source link

Sample code fails with TypeError #29

Open JSchoeck opened 2 years ago

JSchoeck commented 2 years ago

The sample code from the readme fails on my Python 3.10.5 install.

result = bb.minimize(f=fun, # given function
    domain=[[-5, 5], [-5, 5]], # ranges of each parameter
    budget=20, # total number of function calls available
    batch=4 # number of calls that will be evaluated in parallel
)
print(result["best_x"])
print(result["best_f"])

Leads to:

INFO     evaluating batch 1/5 (samples 1..4/20) 10-06 10:54:00
INFO     evaluating batch 2/5 (samples 5..8/20) 10-06 10:54:04
INFO     evaluating batch 3/5 (samples 9..12/20) 10-06 10:54:09
Traceback (most recent call last):
  File "Optimierung_Logistikkosten_BlackBox.py", line 273, in <module>
    main()
  File "Optimierung_Logistikkosten_BlackBox.py", line 208, in main
    result = bb.minimize(f=fun, # given function
  File "\blackbox\blackbox.py", line 86, in minimize
    v1 = compute_volume_unit_ball(d)
  File "\blackbox\blackbox.py", line 165, in compute_volume_unit_ball
    v1 = np.pi ** (d / 2) / np.math.factorial(d / 2)
TypeError: 'float' object cannot be interpreted as an integer

Note that I have redacted the path information.

paulknysh commented 2 years ago

@JSchoeck thanks, I actually didn't know it errors (seems like in Python 3.10 and above), thought it's just a warning.

Do you want to open a small PR with a fix? (if not, I can do that)