1
00:00:00,150 --> 00:00:01,830
So now everything is prepared.

2
00:00:01,980 --> 00:00:09,420
We have our array of the coordinates and of the magnetic moments that we have generated randomly and

3
00:00:09,450 --> 00:00:17,220
we have defined our function for a single metropolis step, which includes the information about the

4
00:00:17,220 --> 00:00:20,880
energy that we have implemented according to the exchange interaction.

5
00:00:21,690 --> 00:00:24,450
So now we can go ahead and run the actual one to kind of.

6
00:00:25,470 --> 00:00:27,510
So I said already, this is pretty simple.

7
00:00:27,510 --> 00:00:29,760
It's just a loop, basically.

8
00:00:30,330 --> 00:00:33,090
So we must specify how many steps we will do.

9
00:00:33,180 --> 00:00:37,410
So a number of steps and we can do really many of those.

10
00:00:37,410 --> 00:00:38,970
We will go up to a million other things.

11
00:00:38,970 --> 00:00:45,120
So let's start with 10K and then we loop for I in range.

12
00:00:45,780 --> 00:00:47,370
No steps.

13
00:00:49,470 --> 00:00:54,030
And then what we do is we just write this one.

14
00:00:55,740 --> 00:01:01,530
And the first output or with the zero index will be the magnetization, which is updated.

15
00:01:02,130 --> 00:01:09,450
And the second outputs with the index one will be the energy so and g change.

16
00:01:12,510 --> 00:01:14,070
And this will be like this.

17
00:01:15,270 --> 00:01:24,150
OK, so the thing is, we don't really need the information about the change of the energy because the

18
00:01:24,150 --> 00:01:32,490
way that reprogrammed it is that we calculate the energy two times anyway, so we don't need to load

19
00:01:32,490 --> 00:01:32,920
it here.

20
00:01:33,390 --> 00:01:38,020
So this means we don't actually have to have the information here about the energy.

21
00:01:38,850 --> 00:01:44,070
So it turns out that this would already be sufficient.

22
00:01:45,060 --> 00:01:51,630
And the only thing the energy information is nice forward to really track our progress.

23
00:01:51,900 --> 00:01:54,330
And so I will write here that this is optional.

24
00:01:56,250 --> 00:02:06,840
So it is optional in the sense that we just write the energy in the beginning is just an energy exchange

25
00:02:07,260 --> 00:02:07,870
off mark.

26
00:02:08,220 --> 00:02:12,660
So this is really calculating once the total energy of the whole sample.

27
00:02:13,290 --> 00:02:20,580
And then we will store your energy list, as is an empty list.

28
00:02:20,950 --> 00:02:27,240
Or we could also add the particular value here from the start, but we could also make it empty for

29
00:02:27,240 --> 00:02:27,760
the beginning.

30
00:02:28,290 --> 00:02:32,640
And now we say in the loop, it's also optional.

31
00:02:32,640 --> 00:02:38,940
Of course, we you update the list or we will add the values to the list.

32
00:02:39,150 --> 00:02:53,330
So we say energy is equal to energy plus energy change and then energy list dot append energy.

33
00:02:54,900 --> 00:02:56,800
But as I said, these took two months.

34
00:02:56,850 --> 00:03:01,770
Commands are optional and these two commands are optional, basically, this one is the only one we

35
00:03:01,770 --> 00:03:02,070
need.

36
00:03:03,270 --> 00:03:07,270
OK, so now let's run it and you see it's already finished.

37
00:03:07,320 --> 00:03:09,390
These are 10000 loops.

38
00:03:09,840 --> 00:03:11,670
And let's see what happens.

39
00:03:11,820 --> 00:03:16,200
And before we look at the magnetization, let us look at the energy.

40
00:03:16,650 --> 00:03:22,850
So Peel Dot plot will be range 40.

41
00:03:23,070 --> 00:03:28,410
So for for the x axis, this will be just indices or in the index for the number of to step.

42
00:03:29,340 --> 00:03:32,400
So range no steps.

43
00:03:32,880 --> 00:03:39,270
And then we write here plus one because we included the starting value here and for the y axis we plot,

44
00:03:39,270 --> 00:03:41,580
of course, the energy so energy list.

45
00:03:42,750 --> 00:03:48,390
And you see, this is now the energy and this is the number of the step.

46
00:03:49,500 --> 00:03:50,960
So I will not add labels here.

47
00:03:50,970 --> 00:03:52,320
You can do this yourself.

48
00:03:52,320 --> 00:03:53,410
It's pretty easy to do.

49
00:03:53,430 --> 00:03:58,530
We have done it so many times already and you see at the beginning, we start at an energy that's very

50
00:03:58,530 --> 00:04:02,070
close to zero because at the beginning everything was randomly.

51
00:04:02,520 --> 00:04:06,630
And then the energy decreases and decreases and decreases.

52
00:04:07,050 --> 00:04:11,100
And sometimes it stays maybe constant as here, but it never increases.

53
00:04:11,280 --> 00:04:15,630
And you see, we really go to a very, very negative energy here.

54
00:04:15,630 --> 00:04:16,800
So it looks pretty good.

55
00:04:17,910 --> 00:04:21,029
But also, you see that the energy is still decreasing.

56
00:04:21,029 --> 00:04:25,020
So it seems as if the simulation isn't finished yet.

57
00:04:25,950 --> 00:04:29,100
So let's see what the profile actually looks like.

58
00:04:29,280 --> 00:04:34,920
So I will just scroll up here and copy this code from the plot.

59
00:04:35,550 --> 00:04:39,930
And since we have updated the magnetization, we can just run it as it is.

60
00:04:41,460 --> 00:04:44,430
And here is our new magnetization.

61
00:04:45,420 --> 00:04:51,600
So I think it doesn't look as confusing as before, but it doesn't look like a ferromagnetic yet.

62
00:04:52,050 --> 00:04:54,660
So probably it's just not finished yet.

63
00:04:55,830 --> 00:05:03,720
So I would say, let's go to 100000 steps, and if we would run rather just right away, we would continue

64
00:05:03,720 --> 00:05:04,710
from this point.

65
00:05:05,220 --> 00:05:10,920
This would also be OK, but I want to start from the beginning, so I just restart and run the whole

66
00:05:11,100 --> 00:05:11,610
notebook.

67
00:05:13,890 --> 00:05:15,630
So now, of course, it takes a bit of time.

68
00:05:16,170 --> 00:05:23,190
And here you see on the energy once again, starting at zero and you see this time we approach a stage

69
00:05:23,190 --> 00:05:28,950
where the energy almost remains constant, so it still keeps on decreasing a bit.

70
00:05:28,950 --> 00:05:33,150
So maybe we are not perfectly at the minimum yet, but it looks much better this time.

71
00:05:34,590 --> 00:05:37,410
But still, it is kind of difficult.

72
00:05:37,800 --> 00:05:45,420
Still, it looks non linear, but we have here some areas where it is already quite thorough magnetic.

73
00:05:46,320 --> 00:05:53,760
So maybe the problem is just that this system size is still too large and we could not just increase

74
00:05:53,760 --> 00:05:59,460
the number of steps, but maybe it's easier to just decrease the size of the system and go to a length

75
00:05:59,460 --> 00:06:00,390
equal to 20.

76
00:06:01,870 --> 00:06:03,850
So once again, restart and run all.

77
00:06:09,680 --> 00:06:10,210
OK.

78
00:06:10,460 --> 00:06:18,680
Still didn't converge, so you see, it sometimes is really tricky to arrive at a good solution in the

79
00:06:18,680 --> 00:06:23,840
Monte Carlo because everything is totally random and it's never guaranteed that you get a good result.

80
00:06:24,140 --> 00:06:28,880
You have to really play with the parameters and run these things many times.

81
00:06:29,450 --> 00:06:31,150
So you see, I have added here another zero.

82
00:06:31,160 --> 00:06:35,900
We are now at one million steps and this will now probably take a few seconds.

83
00:06:36,740 --> 00:06:37,360
But let's see.

84
00:06:39,670 --> 00:06:42,100
We are now running the loop.

85
00:06:43,930 --> 00:06:50,170
And it's still running, so you see, it's not anymore a question of a few seconds, but it takes a

86
00:06:50,170 --> 00:06:50,770
bit of time.

87
00:06:51,940 --> 00:06:54,580
But I think should finish pretty soon.

88
00:06:55,180 --> 00:06:57,730
And then I hope we will get a good result this time.

89
00:06:58,300 --> 00:07:02,350
And you see here, the line is pretty much straight at the end.

90
00:07:02,350 --> 00:07:05,770
So I'm pretty confident that this time it works.

91
00:07:05,770 --> 00:07:08,050
Better still didn't work out.

92
00:07:08,080 --> 00:07:08,680
Oh man.

93
00:07:08,870 --> 00:07:13,810
OK, but you see here it's it's getting somewhere very audits.

94
00:07:14,380 --> 00:07:17,500
So in neighboring moments are almost parallel here.

95
00:07:18,190 --> 00:07:21,610
So it looks pretty good already, but not perfect.

96
00:07:22,180 --> 00:07:29,530
So the thing is, you now have to either increase the number of steps even further or you have to just

97
00:07:29,530 --> 00:07:34,630
rerun the whole thing many, many times and then look every time at the energy.

98
00:07:34,990 --> 00:07:46,030
So for example, here what we can do is we can see an energy list and then minus one, which will be

99
00:07:46,030 --> 00:07:47,770
the last entry from the energy list.

100
00:07:48,190 --> 00:07:55,540
And we can now also check if we did everything correctly by writing Energy mix change.

101
00:07:56,560 --> 00:08:00,580
Not sorry, not with these brackets, but with these ones.

102
00:08:02,980 --> 00:08:05,170
Yeah, OK, at least we did everything correctly.

103
00:08:05,530 --> 00:08:12,970
So on the magnetization, the energy is updated every time in our list and we did it correctly because

104
00:08:12,970 --> 00:08:16,540
when we recalculate the energy at the end, it gives us the correct results.

105
00:08:18,760 --> 00:08:23,770
So we what we would have to do is we would have to rerun this whole simulation many, many times.

106
00:08:24,040 --> 00:08:27,640
And then the correct solution would be the one with the lowest energy.

107
00:08:28,390 --> 00:08:33,490
So I will not stop the recording and run this a few times and see if I will get a better result in minus

108
00:08:33,490 --> 00:08:34,780
seven six three.

109
00:08:36,340 --> 00:08:42,039
So I have rerun this whole thing several times, and the best result that I got was an energy, which

110
00:08:42,039 --> 00:08:43,110
is even lower.

111
00:08:43,120 --> 00:08:44,890
It's minus seven seven nine.

112
00:08:46,510 --> 00:08:53,800
From our initial thought about the energy, we can actually tell what the correct solution would be.

113
00:08:54,280 --> 00:08:57,010
It would be minus eight hundreds.

114
00:08:57,490 --> 00:09:00,160
So we are still pretty far from the correct solution.

115
00:09:00,640 --> 00:09:02,710
And you see, this is what we end up with.

116
00:09:03,160 --> 00:09:09,010
It looks pretty ferromagnetic at some regions, for example, here looks ferromagnetic even here.

117
00:09:09,280 --> 00:09:15,040
But I think the main problem is that we always end up with some strange structure like this world here

118
00:09:15,430 --> 00:09:19,420
and these worlds, and they are actually very hard to get rid of.

119
00:09:19,480 --> 00:09:26,350
So just by changing here, a single magnetic moment will never really help that much to get really to

120
00:09:26,350 --> 00:09:27,400
the energetic minimum.

121
00:09:28,240 --> 00:09:34,840
And this is the problem of our very first version of the of the Monte Carlo algorithm.

122
00:09:35,290 --> 00:09:41,230
It is that we can get stuck in some energetic minimum that is just a local minimum.

123
00:09:41,500 --> 00:09:48,430
So it describes some rather stable configuration, but not the actual global energetic minimum.

124
00:09:49,180 --> 00:09:56,860
And so in the following lecture, I will show you an update to our code that helps us to better converge

125
00:09:56,870 --> 00:10:01,300
the result and to get better results and also in the shorter amount of time.

126
00:10:02,020 --> 00:10:05,290
So let's stay tuned and let's improve our code in the next lecture.

