<commit_before>"""
Various sweeps for scanning experiment parameters
"""

from traits.api import HasTraits, Str, Float, Int, Bool, Dict, List, Enum, \
    Instance, Property, Array, cached_property, TraitListObject, on_trait_change
import enaml

from instruments.MicrowaveSources import MicrowaveSource
from instruments.Instrument import Instrument

import abc
import numpy as np
import json 

class Sweep(HasTraits):
    name = Str
    label = Str
    numSteps = Int
    enabled = Bool(True)
    order = Int(-1)

    @abc.abstractmethod
    def step(self, index):
        pass

class PointsSweep(Sweep):
    """
    A class for sweeps with floating points with one instrument
    """
    start = Float
    step = Float
    stop = Property(depends_on=['start', 'step', 'numPoints'])
    numPoints = Int
    points = Property(depends_on=['start', 'step', 'numPoints'])

    #if either the number of points or the stop is updated then update the other
    def _set_stop(self, stop):
        self.numPoints = np.arange(self.start, stop-2*np.finfo(float).eps, self.step).size+1 if self.step else 0

    def _get_stop(self):
        return self.start + (self.numPoints-1)*self.step

    @cached_property
    def _get_points(self):
        if self.step:
            return np.arange(self.start, self.start+self.numPoints*self.step, self.step)
        else:
            return None
<commit_msg>Update PointsSweep to reflect start/stop/step and linspace modes.<commit_after>"""
Various sweeps for scanning experiment parameters
"""

from traits.api import HasTraits, Str, Float, Int, Bool, Dict, List, Enum, \
    Instance, Property, Array, cached_property, TraitListObject, on_trait_change
import enaml

from instruments.MicrowaveSources import MicrowaveSource
from instruments.Instrument import Instrument

import abc
import numpy as np
import json 

class Sweep(HasTraits):
    name = Str
    label = Str
    enabled = Bool(True)
    order = Int(-1)

    @abc.abstractmethod
    def step(self, index):
        pass

class PointsSweep(Sweep):
    """
    A class for sweeps with floating points with one instrument.

    'step' and 'numPoints' both depend on the internal numPoints_ variable to break the dependency cycle
    """
    start = Float
    step = Property(depends_on=['numPoints_'])
    stop = Float
    numPoints = Property(depends_on=['step'])
    numPoints_ = Int

    def _set_step(self, step):
        self.numPoints_ = np.arange(self.start, self.stop-2*np.finfo(float).eps, step).size+1

    def _get_step(self):
        return (self.stop - self.start)/max(1, self.numPoints_-1)

    def _set_numPoints(self, numPoints):
        self.numPoints_ = numPoints

    def _get_numPoints(self):
        return self.numPoints_

    @on_trait_change('[start, stop]')
    def update_step(self):
        # update the step to keep numPoints fixed
        newStep = self.step
        self.numPoints_ = -1
        self.step = newStep

{'fraction_non_alphanumeric': 0.09618008185538882, 'fraction_numerical': 0.003751705320600273, 'mean_word_length': 3.2384393063583814, 'pattern_counts': {'":': 0, '<': 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': '6284597', 'n_tokens_mistral': 912, 'n_tokens_neox': 888, 'n_words': 268}