<commit_before>from ..external.qt import *
import numpy as np
from itertools import product
import random

class ControlWidget(QWidget):
    """Control a simulator with buttons or from the interactive console."""

    start_inverting_frames = Signal()
    stop_inverting_frames = Signal()

    def __init__(self, simulator, **kwargs):
        """:param simulator: The simulator object to control."""
        super(ControlWidget, self).__init__(**kwargs)

        self.sim = simulator

        self.sim_timer = QTimer(self)
        self.sim_timer.timeout.connect(self.sim.step)

        self.timer_delay = 0

        self._setup_ui()

    def closeEvent(self, event):
        self.sim_timer.stop()

    def _setup_ui(self):
        """Setup the widgets, connect the signals&slots."""
        l = QHBoxLayout(self)
        self.start_button = QPushButton("&Start", self)
        self.start_button.setObjectName("start")
        self.stop_button = QPushButton("&Stop", self)
        self.stop_button.setObjectName("stop")
        self.stop_button.hide()

        delay = QSpinBox()
        delay.setMinimum(0)
        delay.setMaximum(10000)
        delay.setSuffix(" ms")
        delay.setValue(self.timer_delay)
        delay.setObjectName("delay")

        l.addWidget(self.start_button)
        l.addWidget(self.stop_button)
        l.addWidget(delay)

        l.addSpacing(11)
        reset_button = QPushButton("&reset", self)
        reset_button.clicked.connect(self.set_config)
        reset_button.setObjectName("reset")
        l.addWidget(reset_button)

        self.zero_percentage = QDoubleSpinBox(self)
        self.zero_percentage.setMaximum(1)
        self.zero_percentage.setMinimum(0)
        self.zero_percentage.setValue(0.5)
        self.zero_percentage.setSingleStep(0.01)
        self.zero_percentage.setDecimals(4)
        self.zero_percentage.setSuffix(" black")
        self.zero_percentage.setObjectName("zero_percentage")
        l.addWidget(self.zero_percentage)

        self.invert_frames = QCheckBox(self)
        self.invert_frames.setChecked(False)
        self.invert_frames.setText("&invert odd frames")
        self.invert_frames.stateChanged.connect(self.invert_odd)
        self.invert_frames.setObjectName("invert_frames")
        l.addWidget(self.invert_frames)

        self.framerate = FramerateWidget(self.sim)
        l.addWidget(self.framerate)

        self.setLayout(l)

        self.start_button.clicked.connect(self.start)
        self.stop_button.clicked.connect(self.stop)
        delay.valueChanged.connect(self.change_delay)

    def invert_odd(self, value):
        if value == Qt.Checked:
            self.start_inverting_frames.emit()
        else:
            self.stop_inverting_frames.emit()

    def start(self):
        """Start running the simulator."""
        self.sim_timer.start(self.timer_delay)
        self.sim.start()
        self.start_button.hide()
        self.stop_button.show()

    def stop(self):
        """Stop the simulator."""
        self.sim_timer.stop()
        self.sim.stop()
        self.stop_button.hide()
        self.start_button.show()

    def change_delay(self, delay):
        """Change the timer delay of the simulator steps."""
        if isinstance(delay, basestring) and delay.endswith("ms"):
            delay = delay[:-2]
        self.timer_delay = int(delay)
        if self.timer.started():
            self.start()

    def set_config(self, conf=None):
        if conf is None:
            conf = np.zeros(self.sim.get_config().shape, self.sim.get_config().dtype)
            positions = product(*[range(size) for size in conf.shape])
            zero_perc = self.zero_percentage.value()
            for pos in positions:<commit_msg>silly mistake in control.py<commit_after>from ..external.qt import *
import numpy as np
from itertools import product
import random

class ControlWidget(QWidget):
    """Control a simulator with buttons or from the interactive console."""

    start_inverting_frames = Signal()
    stop_inverting_frames = Signal()

    def __init__(self, simulator, **kwargs):
        """:param simulator: The simulator object to control."""
        super(ControlWidget, self).__init__(**kwargs)

        self.sim = simulator

        self.sim_timer = QTimer(self)
        self.sim_timer.timeout.connect(self.sim.step)

        self.timer_delay = 0

        self._setup_ui()

    def closeEvent(self, event):
        self.sim_timer.stop()

    def _setup_ui(self):
        """Setup the widgets, connect the signals&slots."""
        l = QHBoxLayout(self)
        self.start_button = QPushButton("&Start", self)
        self.start_button.setObjectName("start")
        self.stop_button = QPushButton("&Stop", self)
        self.stop_button.setObjectName("stop")
        self.stop_button.hide()

        delay = QSpinBox()
        delay.setMinimum(0)
        delay.setMaximum(10000)
        delay.setSuffix(" ms")
        delay.setValue(self.timer_delay)
        delay.setObjectName("delay")

        l.addWidget(self.start_button)
        l.addWidget(self.stop_button)
        l.addWidget(delay)

        l.addSpacing(11)
        reset_button = QPushButton("&reset", self)
        reset_button.clicked.connect(self.set_config)
        reset_button.setObjectName("reset")
        l.addWidget(reset_button)

        self.zero_percentage = QDoubleSpinBox(self)
        self.zero_percentage.setMaximum(1)
        self.zero_percentage.setMinimum(0)
        self.zero_percentage.setValue(0.5)
        self.zero_percentage.setSingleStep(0.01)
        self.zero_percentage.setDecimals(4)
        self.zero_percentage.setSuffix(" black")
        self.zero_percentage.setObjectName("zero_percentage")
        l.addWidget(self.zero_percentage)

        self.invert_frames = QCheckBox(self)
        self.invert_frames.setChecked(False)
        self.invert_frames.setText("&invert odd frames")
        self.invert_frames.stateChanged.connect(self.invert_odd)
        self.invert_frames.setObjectName("invert_frames")
        l.addWidget(self.invert_frames)

        self.framerate = FramerateWidget(self.sim)
        l.addWidget(self.framerate)

        self.setLayout(l)

        self.start_button.clicked.connect(self.start)
        self.stop_button.clicked.connect(self.stop)
        delay.valueChanged.connect(self.change_delay)

    def invert_odd(self, value):
        if value == Qt.Checked:
            self.start_inverting_frames.emit()
        else:
            self.stop_inverting_frames.emit()

    def start(self):
        """Start running the simulator."""
        self.sim_timer.start(self.timer_delay)
        self.sim.start()
        self.start_button.hide()
        self.stop_button.show()

    def stop(self):
        """Stop the simulator."""
        self.sim_timer.stop()
        self.sim.stop()
        self.stop_button.hide()
        self.start_button.show()

    def change_delay(self, delay):
        """Change the timer delay of the simulator steps."""
        if isinstance(delay, basestring) and delay.endswith("ms"):
            delay = delay[:-2]
        self.timer_delay = int(delay)
        if self.sim_timer.isActive():
            self.start()

    def set_config(self, conf=None):
        if conf is None:
            conf = np.zeros(self.sim.get_config().shape, self.sim.get_config().dtype)
            positions = product(*[range(size) for size in conf.shape])
            zero_perc = self.zero_percentage.value()
            for pos in positions:
{'fraction_non_alphanumeric': 0.11283215382561089, 'fraction_numerical': 0.004807050340499399, 'mean_word_length': 2.592326139088729, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3178527', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2239, 'n_words': 384}