<commit_before>from pmmcontrol.simulator.detector import Detector
import numpy as np
from time import sleep

class Control(Detector):

    def __init__(self):
        # define number of rows and columns
        self.rows = 9
        self.columns = 10

        # define resistor values
        self.R_primary = 620
        self.R_auxiliary = 2400

        self.max_voltage = 14

        Detector.__init__(self, self.rows, self.columns)

    def selectMagnet(self, row, column, isPrimary=True, isArrayMode=False, sign='positive'):

        # check inputs
        if sign != 'positive' and sign != 'negative':
            raise ValueError("parameter 'sign' must be either 'positive' or 'negative'")
        if (not isinstance(row, int)) or row < 0 or row > self.rows - 1:
            raise ValueError("parameter 'row' must be an integer and between 0 and " +
                             str(self.rows - 1))
        if (not isinstance(column, int)) or column < 0 or column > self.columns - 1:
            raise ValueError("parameter 'column' must be an integer and between 0 and " +
                             str(self.columns - 1))

        # record state
        self.curr_row = row
        self.curr_column = column
        self.curr_sign = sign
        self.curr_isPrimary = isPrimary
        self.curr_isArrayMode = isArrayMode

        # state values to be set later
        self.curr_posDAC = None
        self.curr_voltage = None

        return True

    def setCurrent(self, current):
        '''
        Set current in milli amps
        '''
        if not hasattr(self, 'curr_sign'):
            raise AttributeError("Some attributes have not been set. " +
                                 " Run 'selectMagnet()' first")
        if not self.curr_isPrimary and self.curr_isArrayMode:
            raise ValueError("Can only set currents in array mode if magnet has been selected as primary")

        #in mA
        set_current = current / 1000

        #adjust sign of current
        if self.curr_sign == 'negative':
            set_current = -set_current

        max_current = round((2*self.max_voltage) /
                            self.__chooseResistor(self.curr_isPrimary), 4)

        if set_current > max_current:
            raise ValueError('The maximum current allowed on any magnet is ' +
                             str(max_current * 1000)[:5] + ' mA')

        # to achieve I current on current magnet, we send I/2 down the row and the column
        self.setRowCurrent(set_current/2, self.curr_row)
        self.setColCurrent(set_current/2, self.curr_column)

        # if in array mode we need to send (I/2)/3 in the opposite direction across all other rows/cols
        if self.curr_isArrayMode:
            for row in range(self.rows):
                if row != self.curr_row:
                    self.setRowCurrent(-set_current/6, row)
            for col in range(self.cols):
                if col != self.curr_column:
                    self.setColCurrent(-set_current/6, col)
<commit_msg>set rows and column back to 0 current after magnetizing<commit_after>from pmmcontrol.simulator.detector import Detector
import numpy as np
from time import sleep

class Control(Detector):

    def __init__(self):
        # define number of rows and columns
        self.rows = 9
        self.columns = 10

        # define resistor values
        self.R_primary = 620
        self.R_auxiliary = 2400

        self.max_voltage = 14

        Detector.__init__(self, self.rows, self.columns)

    def selectMagnet(self, row, column, isPrimary=True, isArrayMode=False, sign='positive'):

        # check inputs
        if sign != 'positive' and sign != 'negative':
            raise ValueError("parameter 'sign' must be either 'positive' or 'negative'")
        if (not isinstance(row, int)) or row < 0 or row > self.rows - 1:
            raise ValueError("parameter 'row' must be an integer and between 0 and " +
                             str(self.rows - 1))
        if (not isinstance(column, int)) or column < 0 or column > self.columns - 1:
            raise ValueError("parameter 'column' must be an integer and between 0 and " +
                             str(self.columns - 1))

        # record state
        self.curr_row = row
        self.curr_column = column
        self.curr_sign = sign
        self.curr_isPrimary = isPrimary
        self.curr_isArrayMode = isArrayMode

        # state values to be set later
        self.curr_posDAC = None
        self.curr_voltage = None

        return True

    def setCurrent(self, current):
        '''
        Set current in milli amps
        '''
        if not hasattr(self, 'curr_sign'):
            raise AttributeError("Some attributes have not been set. " +
                                 " Run 'selectMagnet()' first")
        if not self.curr_isPrimary and self.curr_isArrayMode:
            raise ValueError("Can only set currents in array mode if magnet has been selected as primary")

        #in mA
        set_current = current / 1000

        #adjust sign of current
        if self.curr_sign == 'negative':
            set_current = -set_current

        max_current = round((2*self.max_voltage) /
                            self.__chooseResistor(self.curr_isPrimary), 4)

        if set_current > max_current:
            raise ValueError('The maximum current allowed on any magnet is ' +
                             str(max_current * 1000)[:5] + ' mA')

        # to achieve I current on current magnet, we send I/2 down the row and the column
        self.setRowCurrent(set_current/2, self.curr_row)
        self.setColCurrent(set_current/2, self.curr_column)

        # if in array mode we need to send (I/2)/3 in the opposite direction across all other rows/cols
        if self.curr_isArrayMode:
            for row in range(self.rows):
                if row != self.curr_row:
                    self.setRowCurrent(-set_current/6, row)
            for col in range(self.cols):
                if col != self.curr_column:
                    self.setColCurrent(-set_current/6, col)

        # simulate turning on the DAC after setting all pins
        self.updateRes()

        # allow enough time for full magnetization
        sleep(.5)

        # simulate turning off the DAC
        for row in range(self.rows):
            self.setRowCurrent(0, row)
        for col in range(self.cols):
            self.setColCurrent(0, col)
{'fraction_non_alphanumeric': 0.08092575333954645, 'fraction_numerical': 0.012426219322771047, 'mean_word_length': 1.9201814058956916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2863236', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1691, 'n_words': 575}