Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ __pycache__/exceptions.cpython-38.pyc
test.py

.idea/
*.txt
23 changes: 15 additions & 8 deletions board.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,25 @@ def physical_move(self, particle: Particle) -> None:
old_energy = self.calculate_particle_energy(particle)
old_coordinates = particle.get_coordinates()

old_neighbors = utils.get_neighboring_elements(self.grid, particle.get_coordinates(), self.cfg.is_cyclic)
num_of_similar_old_neighbors = len([x for x in old_neighbors.values()
if self.particles[x].inner_state == particle.inner_state])

# move particle and recalculate energy
self.do_move_particle(particle, new_coordinates)
new_energy = self.calculate_particle_energy(particle)
new_neighbors = utils.get_neighboring_elements(self.grid, new_coordinates, self.cfg.is_cyclic)
num_of_similar_new_neighbors = len([x for x in new_neighbors.values()
if self.particles[x].inner_state == particle.inner_state])

reversed_local_drive = 0
if num_of_similar_old_neighbors >= 2:
reversed_local_drive -= self.targets[particle.inner_state].local_drive
if num_of_similar_new_neighbors >= 2:
reversed_local_drive += self.targets[particle.inner_state].local_drive

# if the move is accepted, we keep it
if utils.metropolis(-(new_energy - old_energy)):
if utils.metropolis(-(new_energy - old_energy)+reversed_local_drive):
# update adjacency matrix
self.adjacency_matrix[:, particle.id] = -1
self.adjacency_matrix[particle.id, :] = -1
Expand Down Expand Up @@ -195,15 +208,9 @@ def state_change(self, particle: Particle) -> None:
if self.particles[n].inner_state == original_state])
num_of_neighbors_in_new_state = len([n for n in neighbors.values()
if self.particles[n].inner_state == new_state])
local_drive = 0

if num_of_neighbors_in_original_state >= 2:
local_drive -= self.targets[original_state].local_drive
if num_of_neighbors_in_new_state >= 2:
local_drive += self.targets[new_state].local_drive

# Check change probabilty and edit adjacency_matrix.
if utils.metropolis(-(new_energy - old_energy) + local_drive):
if utils.metropolis(-(new_energy - old_energy)):
for n in neighbors.values():
self.adjacency_matrix[particle.id][n] = 10 * new_state + self.particles[n].inner_state
self.adjacency_matrix[n][particle.id] = 10 * self.particles[n].inner_state + new_state
Expand Down
4 changes: 2 additions & 2 deletions cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"targets_cfg": [
{
"weak_interaction": -1,
"strong_interaction": -7,
"num_of_instances": 1,
"strong_interaction": -4,
"num_of_instances": 4,
"local_drive": 0
}
],
Expand Down
26 changes: 17 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,38 @@
CFG_FILE = "cfg.json"


def main():
def main(filename):
global_result = []
runs = [-6, -6.5, -7, -7.5, -8, -8.5]
runs = [8, 9, 10, 11]

start_time = datetime.now()

with open(CFG_FILE, "r") as f_cfg:
cfg = load_cfg(f_cfg)

with open("output.txt", "w") as outfile:
with open(filename, "w") as outfile:
CallbackGlobals.COUNTER = 0
print(str(cfg.__dict__))
outfile.write(str(cfg.__dict__))
print(str([target_cfg.__dict__ for target_cfg in cfg.targets_cfg]))
outfile.write(str([target_cfg.__dict__ for target_cfg in cfg.targets_cfg]))
outfile.write("begining sim with with strong interaction = {}------\n".format(cfg.targets_cfg[0].strong_interaction))
print("begining sim with with strong interaction = {}------\n".format(cfg.targets_cfg[0].strong_interaction))
for run in runs:
outfile.write("begining run with strong interaction = {}------\n".format(run))
cfg.targets_cfg[0].strong_interaction = run
for i in range(5):
outfile.write("begining run with mu interaction = {}------\n".format(run))
outfile.flush()
for j in range(len(cfg.targets_cfg)):
cfg.targets_cfg[j].local_drive = run
for i in range(6):
CallbackGlobals.MIN_DISTANCE = 1000
print("begining run {} with interaction {}".format(i, run))
print("begining run {} with mu interaction {}".format(i, run))
board = Board(cfg, outfile, False) # Random initialization for TFAS measurements
board.run_simulation(5 * (10 ** 7), tfas_turn_callback, CallbackGlobals.COUNTER)
CallbackGlobals.COUNTER += 1
print('\nend run--------------')

outfile.flush()
print(datetime.now() - start_time)


if __name__ == '__main__':
main()
main("output_5_4_21_4.5strong_4targets.txt")