Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ising_monte_carlo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Ramos Salamanca
ising_monte_carlo
Commits
4068b3bc
Commit
4068b3bc
authored
4 years ago
by
David Ramos Salamanca
Browse files
Options
Downloads
Patches
Plain Diff
add docstrings to functions
parent
3933a5f8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.py
+5
-7
5 additions, 7 deletions
main.py
metropolis.py
+19
-1
19 additions, 1 deletion
metropolis.py
observables.py
+18
-1
18 additions, 1 deletion
observables.py
sampling.py
+20
-15
20 additions, 15 deletions
sampling.py
with
62 additions
and
24 deletions
main.py
+
5
−
7
View file @
4068b3bc
import
numpy
as
np
from
timeit
import
default_timer
as
timer
from
parameters
import
*
from
observables
import
*
#from metropolis import *
from
sampling
import
*
from
parameters
import
t_min
,
t_max
,
nt
,
eqSteps
,
mcSteps
,
Ns
from
sampling
import
finite_ising
T
=
np
.
linspace
(
t_min
,
t_max
,
nt
)
Ns
=
np
.
array
(
Ns
)
...
...
@@ -15,6 +12,7 @@ for N in Ns:
result
=
finite_ising
(
N
,
mcSteps
,
eqSteps
,
T
)
end
=
timer
()
print
(
'
Time the code takes to run for a lattice size of
'
+
str
(
N
)
+
'
:
'
+
str
((
end
-
start
)
/
60
)
+
'
minutes.
'
)
print
(
'
Time the code takes to run for a lattice of size
'
+
str
(
N
),
+
'
:
'
+
str
((
end
-
start
)
/
60
)
+
'
minutes.
'
)
np
.
savetxt
(
"
data/data_ising_
"
+
str
(
N
)
+
"
.csv
"
,
result
.
T
,
delimiter
=
"
,
"
)
np
.
savetxt
(
"
data/data_ising_
"
+
str
(
N
)
+
"
.csv
"
,
result
.
T
,
delimiter
=
"
,
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
metropolis.py
+
19
−
1
View file @
4068b3bc
import
numpy
as
np
def
pi_0
(
N
):
"""
Genera un arreglo NxN de numpy con valores 1 o -1 escogidos aleatoriamente.
Argumentos:
N -- int
tamaño de la red
"""
Pi_0
=
2
*
np
.
random
.
randint
(
2
,
size
=
(
N
,
N
))
-
1
return
Pi_0
def
MC_metropolis
(
arreglo
,
beta
,
N
):
"""
Ejecuta un paso de monte carlo sobre una configuración de espines
Argumentos:
arreglo -- arreglo NxN de numpy
valores del espin en cada sitio
beta -- flotante
inverso de la temperatura en unidades donde kb = J = 1
N -- int
"""
for
i
in
range
(
0
,
2
*
N
**
2
):
a
,
b
=
np
.
random
.
randint
(
0
,
N
),
np
.
random
.
randint
(
0
,
N
)
rand_spin
=
arreglo
[
a
,
b
]
vecinos
=
arreglo
[(
a
+
1
)
%
N
,
b
]
+
arreglo
[
a
,
(
b
+
1
)
%
N
]
+
arreglo
[(
a
-
1
)
%
N
,
b
]
+
arreglo
[
a
,
(
b
-
1
)
%
N
]
vecinos
=
arreglo
[(
a
+
1
)
%
N
,
b
]
+
arreglo
[
a
,
(
b
+
1
)
%
N
]
+
\
arreglo
[(
a
-
1
)
%
N
,
b
]
+
arreglo
[
a
,
(
b
-
1
)
%
N
]
delta_energia
=
2
*
rand_spin
*
vecinos
if
delta_energia
<
0
:
arreglo
[
a
,
b
]
*=
-
1
...
...
This diff is collapsed.
Click to expand it.
observables.py
+
18
−
1
View file @
4068b3bc
import
numpy
as
np
def
energia
(
arreglo
,
N
):
"""
Devuelve la energia de una configuración de espines.
Argumentos:
arreglo -- arreglo NxN de numpy
valores del espin en cada sitio
N -- entero
tamaño de la red
"""
energia
=
0
for
i
in
range
(
0
,
N
):
for
j
in
range
(
0
,
N
):
spin
=
arreglo
[
i
,
j
]
vecinos
=
arreglo
[(
i
+
1
)
%
N
,
j
]
+
arreglo
[
i
,
(
j
+
1
)
%
N
]
+
arreglo
[(
i
-
1
)
%
N
,
j
]
+
arreglo
[
i
,
(
j
-
1
)
%
N
]
vecinos
=
arreglo
[(
i
+
1
)
%
N
,
j
]
+
arreglo
[
i
,
(
j
+
1
)
%
N
]
+
\
arreglo
[(
i
-
1
)
%
N
,
j
]
+
arreglo
[
i
,
(
j
-
1
)
%
N
]
energia
+=
-
spin
*
vecinos
return
energia
/
2
def
magnetizacion
(
arreglo
):
"""
Devuelve la magnetización de una configuración de espines.
Argumentos:
arreglo -- arreglo NxN de numpy
valores del espin en cada sitio
"""
magnetizacion
=
np
.
sum
(
arreglo
)
return
abs
(
magnetizacion
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
sampling.py
+
20
−
15
View file @
4068b3bc
import
numpy
as
np
from
parameters
import
*
from
observables
import
*
from
metropolis
import
*
from
observables
import
energia
,
magnetizacion
from
metropolis
import
pi_0
,
MC_metropolis
def
finite_ising
(
N
,
mcSteps
,
eqSteps
,
T
):
"""
Devuelve los observables físicos para los valores de temperatura
y tamaño de la red dados.
Argumentos:
N -- entero
tamaño de la red
eqSteps -- entero
numero de pasos de Monte Carlo para termalización
mcSteps -- entero
numero de pasos de Monte Carlo para realizar el muestreo
T -- arreglo de numpy
conjunto de temperaturas para las que se calcularan las cantidades fisicas
"""
nt
=
len
(
T
)
E
,
M
,
C
,
X
,
U
=
np
.
zeros
(
nt
),
np
.
zeros
(
nt
),
np
.
zeros
(
nt
),
np
.
zeros
(
nt
),
np
.
zeros
(
nt
)
#, np.zeros(nt)
E
,
M
,
C
,
X
,
U
=
np
.
zeros
(
nt
),
np
.
zeros
(
nt
),
np
.
zeros
(
nt
),
np
.
zeros
(
nt
),
np
.
zeros
(
nt
)
N2
=
N
*
N
for
t
in
range
(
nt
):
...
...
@@ -17,21 +30,13 @@ def finite_ising(N,mcSteps,eqSteps,T):
if
t
>
1.5
and
t
<
4.5
:
eqSteps_p
=
eqSteps
for
i
in
range
(
eqSteps_p
):
# esto es supuestamente para llevarlo al equilibrio
for
i
in
range
(
eqSteps_p
):
arreglo
=
MC_metropolis
(
arreglo
,
beta
,
N
)
#magn = magnetizacion(arreglo)
#energ = energia(arreglo)
#full_M.append(magn/N2)
#full_E.append(energ)
else
:
for
i
in
range
(
eqSteps
):
# esto es supuestamente para llevarlo al equilibrio
for
i
in
range
(
eqSteps
):
arreglo
=
MC_metropolis
(
arreglo
,
beta
,
N
)
#magn = magnetizacion(arreglo)
#energ = energia(arreglo)
#full_M.append(magn/N2)
#full_E.append(energ)
for
i
in
range
(
mcSteps
):
# y aquí supuestamente el sistema se está desenvolviendo en el equilibrio
for
i
in
range
(
mcSteps
):
arreglo
=
MC_metropolis
(
arreglo
,
beta
,
N
)
energ
=
energia
(
arreglo
,
N
)
magn
=
magnetizacion
(
arreglo
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment