Fix window closing event

This commit is contained in:
timofej 2023-08-19 22:18:44 +02:00
parent c37f63f7bf
commit 899aa9990b
2 changed files with 30 additions and 10 deletions

View File

@ -9,15 +9,18 @@ Created on Fri Aug 18 19:05:04 2023
import numpy as np import numpy as np
from neuropercolation import Simulate1Layer from neuropercolation import Simulate1Layer
eps_space = np.linspace(0.005,0.5,100) #eps_space = np.linspace(0.005,0.5,100)
for dim in range(4,10): eps_space = np.linspace(0.135,0.15,4)
for dim in [49,100]:
for eps in eps_space: for eps in eps_space:
eps = round(eps,3) eps = round(eps,3)
Simulate1Layer(dim, Simulate1Layer(dim,
eps, eps,
res=2, res=2,
path=f'/cloud/Public/_data/neuropercolation/1lay/dim={dim:02}/', path=f'/cloud/Public/_data/neuropercolation/1lay/steps=100000/dim={dim:02}/',
draw=None #draw=None
).run(evolutions_per_second=0, ).run(evolutions_per_second=30,
last_evolution_step=100000) last_evolution_step=100000,
save_states=False)
print(f'Done eps={eps:.3f} at dim={dim}') print(f'Done eps={eps:.3f} at dim={dim}')

View File

@ -17,6 +17,7 @@ limitations under the License.
# pylint: disable=all # pylint: disable=all
import os import os
import sys
import json import json
import time import time
import operator import operator
@ -85,6 +86,7 @@ class Simulate1Layer:
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._cellular_automaton = Neurolattice(dim,eps) self._cellular_automaton = Neurolattice(dim,eps)
self.__active = True
self.__cell_size = [res,res] self.__cell_size = [res,res]
self.__dimension = dim self.__dimension = dim
self.__epsilon = eps self.__epsilon = eps
@ -113,7 +115,7 @@ class Simulate1Layer:
else: else:
self._append_activation() self._append_activation()
with contextlib.suppress(KeyboardInterrupt): with contextlib.suppress(KeyboardInterrupt):
while self._not_at_the_end(last_evolution_step): while self.__active and self._not_at_the_end(last_evolution_step):
time_ca_start = time.time() time_ca_start = time.time()
self._cellular_automaton.evolve(evolutions_per_draw) self._cellular_automaton.evolve(evolutions_per_draw)
if save_states: if save_states:
@ -129,6 +131,11 @@ class Simulate1Layer:
evolution_step=self._cellular_automaton.evolution_step, evolution_step=self._cellular_automaton.evolution_step,
runlendig=len(str(last_evolution_step))) runlendig=len(str(last_evolution_step)))
self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second)
for event in self.__draw_engine._pygame.event.get():
if event.type == self.__draw_engine._pygame.QUIT:
self.__active = False
if self.__draw_engine is not None: if self.__draw_engine is not None:
try: try:
self.__draw_engine._pygame.quit() self.__draw_engine._pygame.quit()
@ -239,6 +246,7 @@ class Simulate2Layers:
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._cellular_automaton = Neuropercolation(dim,eps) self._cellular_automaton = Neuropercolation(dim,eps)
self.__active = True
self.__cell_size = [res,res] self.__cell_size = [res,res]
self.__dimension = dim self.__dimension = dim
self.__epsilon = eps self.__epsilon = eps
@ -269,7 +277,7 @@ class Simulate2Layers:
else: else:
self._append_activation() self._append_activation()
with contextlib.suppress(KeyboardInterrupt): with contextlib.suppress(KeyboardInterrupt):
while self._not_at_the_end(last_evolution_step): while self.__active and self._not_at_the_end(last_evolution_step):
time_ca_start = time.time() time_ca_start = time.time()
self._cellular_automaton.evolve(evolutions_per_draw) self._cellular_automaton.evolve(evolutions_per_draw)
if save_states: if save_states:
@ -285,7 +293,11 @@ class Simulate2Layers:
evolution_step=self._cellular_automaton.evolution_step, evolution_step=self._cellular_automaton.evolution_step,
runlendig=len(str(last_evolution_step))) runlendig=len(str(last_evolution_step)))
self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second)
for event in self.__draw_engine._pygame.event.get():
if event.type == self.__draw_engine._pygame.QUIT:
self.__active = False
if self.__draw_engine is not None: if self.__draw_engine is not None:
try: try:
self.__draw_engine._pygame.quit() self.__draw_engine._pygame.quit()
@ -402,6 +414,7 @@ class Simulate4Layers:
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling) self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling)
self.__active = True
self.__cell_size = [res,res] self.__cell_size = [res,res]
self.__dimension = dim self.__dimension = dim
self.__epsilon = eps self.__epsilon = eps
@ -432,7 +445,7 @@ class Simulate4Layers:
self._append_state() self._append_state()
else: else:
self._append_activation() self._append_activation()
while self._not_at_the_end(last_evolution_step): while self.__active and self._not_at_the_end(last_evolution_step):
time_ca_start = time.time() time_ca_start = time.time()
self._cellular_automaton.evolve(evolutions_per_draw) self._cellular_automaton.evolve(evolutions_per_draw)
if save_states: if save_states:
@ -448,6 +461,10 @@ class Simulate4Layers:
evolution_step=self._cellular_automaton.evolution_step, evolution_step=self._cellular_automaton.evolution_step,
runlendig=len(str(last_evolution_step))) runlendig=len(str(last_evolution_step)))
self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second)
for event in self.__draw_engine._pygame.event.get():
if event.type == self.__draw_engine._pygame.QUIT:
self.__active = False
if self.__draw_engine is not None: if self.__draw_engine is not None:
try: try:
self.__draw_engine._pygame.quit() self.__draw_engine._pygame.quit()