Is using "break" in if statement not allowed in mumax3??

653 views
Skip to first unread message

irohanihoheto

unread,
May 20, 2021, 6:35:17 AM5/20/21
to mumax2
Hi . I ran if-statement below in mumax input script.

for i := 0; i < 5; i++ {
if i == 3 {
break
}
print(i) 
}

and I've got an error like this.
": not allowed: BranchStmtc/github.com/mumax/3/cmd/mumax3/main.go:110 script line 8: break"

Is using "break" in if statement not allowed in mumax3??

If any of you have any idea, please let me know.
Thanks in advance.

Sincerely.

Gaureesh K

unread,
Aug 15, 2022, 7:14:40 AM8/15/22
to mumax2
I'm getting a similar error for if else statement. 
if N%2 == 1 {
    
    for a:=0;a<=Floor(N/2);a++{
        film1=film1.sub(cyl.transl((2*a*D),0,0))
        film1=film1.sub(cyl.transl((-2*a*D),0,0))
        }


}     else{
    for b:=0;b<N/2;b++{
        film1=film1.sub(cyl.transl((2*b+1)*D,0,0))
        film1=film1.sub(cyl.transl(-(2*b+1)*D,0,0))

    }
   

}
Is using If statement not allowed in mumax3?

If any of you have any idea, please let me know.
Thanks in advance.

Sincerely.

Josh Lauzier

unread,
Aug 15, 2022, 9:04:33 PM8/15/22
to mumax2
Hello,

By default, mumax is only a subset of golang code. If you want full access to all golang features, you can give mumax3 a full go script (I do not recommend this, as it's rather complicated and not well documented). More details in this discussion and similar discussions on the board.

If/else statements are available within mumax. Break is not, but you can get most of the functionality with if/else statements

For the second case, can you post the full script, and the error message? It's likely more an issue with formatting. % is from golang and is not accessible via mumax, but there is a mod() function to perform modulus operations. 

I've attached an example script that uses if, else, and mod(). Hopefully that helps.

Cheers,
Josh L.
mumaxifelse.txt

Gaureesh K

unread,
Aug 19, 2022, 10:45:04 PM8/19/22
to mumax2
Thanks for the reply, the problem was resolved using mod().
Is there a way to use array values in mumax?? I'm using ext_bubblepos[0] which seems to give an error.


setgridsize(256,128,1)
setcellsize(1e-9,1e-9,1e-9)
film:=cuboid(256e-9,128e-9,1e-9)
setgeom(film)
saveas(geom,"film")
setpbc(4,0,0)
Msat=221e2
Aex=2.6e-13
Dind=8.0e-6
Ku1=0.18e4
AnisU=vector(0,0,1)
alpha=0.1
i:=0
m=neelskyrmion(-1,1).transl(-100e-9,0,0)
for (ext_bubblepos[0]<1e-9) || (ext_bubbleposx>128e-9) || (ext_bubbleposx<(-128e-9)){
    Msat+=221e3
    m=neelskyrmion(-1,1).transl(-100e-9,0,0)
    minimize()
    i++
    print(i)
}

error-message--C:/Users/jmulkers/GO/src/github.com/mumax/3/cmd/mumax3/main.go:110 script line 22: for (ext_bubblepos[0]<1e-9) || (ext_b: can not index *engine.VectorValueos(0)<(-128e-9)){

Gaureesh K

unread,
Aug 19, 2022, 10:49:35 PM8/19/22
to mumax2
edit: a typo in the for loop :  for (ext_bubblepos[0]<1e-9) || (ext_bubblepos[0]>128e-9) || (ext_bubblepos[0]<(-128e-9)){

Josh Lauzier

unread,
Aug 20, 2022, 7:06:15 PM8/20/22
to mumax2
Hello,

The syntax for bubblepos is a bit nonintuitive. You need to do "ext_bubblepos.average()[0]".  It's a bit confusing, if you try "print( ext_bubblepos )", it does the averaging implicitly for you, but really it's doing "print( ext_bubblepos.average() )" to the command line instead. 

Mumax usually does this implicit averaging for things that are entire arrays/slices (like the magnetization, which is defined for every cell. if you do print(m), it only gives the average components), presumably as a shortcut so it doesn't have to print every cell value into the terminal. I'm not sure why bubblepos acts this way, I haven't used it, but it happens for similar variable types. Usually the giveaway is either the variable type, or if you save it to a file and it generates a full space-dependent ovf (which does not match what is printed to the console, especially if the console matches the average value). Even if the values are the same for each cell.

Best,
Josh L.

Gaureesh K

unread,
Aug 21, 2022, 2:55:55 PM8/21/22
to mumax2
Hello,
I'm now getting an error : type mismatch: can not use type *engine.RegionwiseScalar as float64<
because of the comparison (ext_bubblepos.average()[0]<1e-9).
adding a float64 ()  to typecast didn't work
How do I resolve this? 
thank you
Regards
Gaureesh K

Josh Lauzier

unread,
Aug 21, 2022, 6:58:22 PM8/21/22
to mumax2
Hello,

When I run your script (with the changes), I am not getting that error. It's giving the " *engine.RegionwiseScalar as float64" for Msat, for trying to do Msat+=. 

Again, that's because there is some shortcutting. Msat is not just a float (so it doesn't have access to +=), it's setting Msat for the entire universe behind the scenes.  You can set it by using a dummy variable float to increment. The following script seems to run without errors:

setgridsize(256,128,1)
setcellsize(1e-9,1e-9,1e-9)
film:=cuboid(256e-9,128e-9,1e-9)
setgeom(film)
saveas(geom,"film")
setpbc(4,0,0)
Msat=221e2
Aex=2.6e-13
Dind=8.0e-6
Ku1=0.18e4
AnisU=vector(0,0,1)
alpha=0.1
i:=0
Msat_float:=221e3
m=neelskyrmion(-1,1).transl(-100e-9,0,0)
for (ext_bubblepos.average()[0]<1e-9) || (ext_bubblepos.average()[0]>128e-9) || (ext_bubblepos.average()[0]<(-128e-9)){
    Msat_float+=Msat_float
    Msat=Msat_float
    m=neelskyrmion(-1,1).transl(-100e-9,0,0)
    minimize()
    i++
    print(i)
}

Basically, Msat is not actually float, but it can take a float argument/assignment (and it does stuff behind the scenes with it).

Best,
Josh L.
Reply all
Reply to author
Forward
0 new messages