ich probiere im Moment Numba ein wenig aus, um ein paar Simulationen eventuell zu beschleunigen. Allerding habe ich ein Verständnisproblem. Ich habe eine Liste mit Tupeln, jedes Tupel repräsentiert ein Element meiner Simulation. In diesem Tupel sind z.B. Koordinaten und Eigenschaften zu diesen Elementen gespeichert. Wenn ich die Tupel-Liste jetzt einer Funktion übergebe bekomm ich einen Fehler, sobald ich die Werte in einem Tupel verändern möchte. Ich versteh aber nicht, wieso ich die Werte in den Tupeln nicht verändern kann. Gibt es dazu einen Trick?
Code:
Code: Alles auswählen
@nb.njit
def IsDropletGrowth(x, y, Droplets, ND):
dropletgrow = False
for i in range(ND):
if (math.sqrt(math.pow(Droplets[i][0] - x, 2) + math.pow(Droplets[i][1] - y, 2)) <= Droplets[i][3]):
Droplets[i][2] += 1
Droplets[i][3] = calc_radius(Droplets[i][2])
Droplets[i][4] = calc_Gibbs_Thomson(Droplets[i][2])
dropletgrow = True
return dropletgrow, Droplets
nucleation, Monomers, Droplets, SimField, ND, N1 = IsNucleation(x, y, Monomers, Droplets, SimField, SimSize, ND, N1)
if not nucleation:
dropletgrow, Droplets = IsDropletGrowth(x, y, Droplets, ND)
if not dropletgrow:
SimField[x][y] += 1
Monomers.append((x,y))
N1 += 1
runfile('C:/Simulationen/Skripte/Python/kMC_DropletsV2.py', wdir='C:/Simulationen/Skripte/Python')
Traceback (most recent call last):
File "C:\Simulationen\Skripte\Python\kMC_DropletsV2.py", line 245, in <module>
kMC(SimSize, Dif, Det, t_stop)
File "C:\Users\st3fa\anaconda3\lib\site-packages\numba\core\dispatcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "C:\Users\st3fa\anaconda3\lib\site-packages\numba\core\dispatcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "C:\Users\st3fa\anaconda3\lib\site-packages\numba\core\utils.py", line 80, in reraise
raise value.with_traceback(tb)
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (UniTuple(float64 x 5), Literal[int](2), float64)
* parameterized
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
In definition 2:
All templates rejected with literals.
In definition 3:
All templates rejected without literals.
In definition 4:
All templates rejected with literals.
In definition 5:
All templates rejected without literals.
In definition 6:
All templates rejected with literals.
In definition 7:
All templates rejected without literals.
In definition 8:
All templates rejected with literals.
In definition 9:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: typing of staticsetitem at C:\Simulationen\Skripte\Python\kMC_DropletsV2.py (100)
File "kMC_DropletsV2.py", line 100:
def IsDropletGrowth(x, y, Droplets, ND):
<source elided>
if (math.sqrt(math.pow(Droplets[0] - x, 2) + math.pow(Droplets[1] - y, 2)) <= Droplets[3]):
#Droplets[2] += 1
^
[1] During: resolving callee type: type(CPUDispatcher(<function IsDropletGrowth at 0x0000020A62B6A828>))
[2] During: typing of call at C:\Simulationen\Skripte\Python\kMC_DropletsV2.py (140)
[3] During: resolving callee type: type(CPUDispatcher(<function IsDropletGrowth at 0x0000020A62B6A828>))
[4] During: typing of call at C:\Simulationen\Skripte\Python\kMC_DropletsV2.py (140)
File "kMC_DropletsV2.py", line 140:
def AddMonomerTo(x, y, Monomers, Droplets, SimField, SimSize, ND, N1):
<source elided>
if nucleation==False:
dropletgrow, Droplets = IsDropletGrowth(x, y, Droplets, ND)
^
[1] During: resolving callee type: type(CPUDispatcher(<function AddMonomerTo at 0x0000020A62B6A288>))
[2] During: typing of call at C:\Simulationen\Skripte\Python\kMC_DropletsV2.py (208)
[3] During: resolving callee type: type(CPUDispatcher(<function AddMonomerTo at 0x0000020A62B6A288>))
[4] During: typing of call at C:\Simulationen\Skripte\Python\kMC_DropletsV2.py (208)
[5] During: resolving callee type: type(CPUDispatcher(<function AddMonomerTo at 0x0000020A62B6A288>))
[6] During: typing of call at C:\Simulationen\Skripte\Python\kMC_DropletsV2.py (208)
Sobald ich diese Zeilen raus kommentiere startet das Programm ohne Fehler:
Code: Alles auswählen
Droplets[i][2] += 1
Droplets[i][3] = calc_radius(Droplets[i][2])
Droplets[i][4] = calc_Gibbs_Thomson(Droplets[i][2])
Viele Grüße
Stefan