Repository navigation
[BUG] Unable to use basinhopping algorithm in code #336
Description
Describe the bug
As part of the documentation for impedance.py, the circuit fit mentions you can use global_opt = true to switch to basinhopping instead of curve_fit. However, despite having a piece of code that fits a set of data using the curve_fit method, adding global_opt = true makes the code throw a bunch of divide by zero errors. exactly like #291 . What is confusing me is that the code works perfectly fine without activating basinhopping, so it's not something in the data formatting as far as I can tell. I am, however, not a very experienced coder, so I could be missing plenty.
To Reproduce
Steps to reproduce the behavior:
while repeats:
data = repeats.pop(0)
repeat = os.path.splitext(data)[0]
frequencies, Z = preprocessing.readCSV(dir+data)
# frequencies, Z = impedance.preprocessing.cropFrequencies(frequencies, Z, freqmax=100000)
circ_string = 'R0-p(CPE1,R1)'
initial_guess = [370, 1.3e-8, 0.9, 68000000]
circuit = CustomCircuit(circ_string, initial_guess=initial_guess, name=data)
circuit.fit(frequencies,Z, weight_by_modulus = True)
# circuit.fit(frequencies,Z, global_opt = True)
fitting.append(circuit.parameters_)
error.append(circuit.conf_)
repeatnum.append(repeat)
I comment out the frequency trim as necessary, and I switch between the weight by modulus and global_opt, as the documentation mentions only one can be true at once. They are not both active at the same time.
- Full error info
See Error? #291 as well
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: overflow encountered in power
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in multiply
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in divide
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:81: RuntimeWarning: invalid value encountered in divide
z += 1 / elem
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:82: RuntimeWarning: invalid value encountered in divide
return 1 / z
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: overflow encountered in power
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in multiply
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in divide
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:81: RuntimeWarning: invalid value encountered in divide
z += 1 / elem
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:82: RuntimeWarning: invalid value encountered in divide
return 1 / z
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: overflow encountered in power
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: overflow encountered in multiply
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in multiply
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in divide
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:81: RuntimeWarning: invalid value encountered in divide
z += 1 / elem
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:82: RuntimeWarning: invalid value encountered in divide
return 1 / z
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: overflow encountered in power
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in multiply
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in divide
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:81: RuntimeWarning: invalid value encountered in divide
z += 1 / elem
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:82: RuntimeWarning: invalid value encountered in divide
return 1 / z
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: overflow encountered in power
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in multiply
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:208: RuntimeWarning: invalid value encountered in divide
Z = 1.0 / (Q * (1j * omega) ** alpha)
C:\Users\blah\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\impedance\models\circuits\elements.py:81: RuntimeWarning: invalid value encountered in divide
z += 1 / elem
(this is a section of it, the errors ran off the terminal)
Expected behavior
The same behavior as curve_fit, with a generation of a fit to the data and extractable values and errors. again, without using basinhopping there's no issues
Additional context
Activity