<commit_before>import os.path
import tempfile
import shutil
import neo.io
import numpy as np
from pype9.cmd import simulate
from pype9.cmd._utils import parse_units
import ninemlcatalog
from pype9.simulator.neuron import (
    Simulation as NeuronSimulation,
    CellMetaClass as NeuronCellMetaClass,
    Network as NetworkNEURON)
from pype9.simulator.nest import (
    Simulation as NESTSimulation,
    CellMetaClass as NESTCellMetaClass,
    Network as NetworkNEST)
import nineml
import nineml.units as un
if __name__ == '__main__':
    from pype9.utils.testing import DummyTestCase as TestCase  # @UnusedImport
else:
    from unittest import TestCase  # @Reimport


class TestSimulateCell(TestCase):

    ref_path = ''

    # Izhikevich simulation params
    t_stop = 100.0
    dt = 0.001
    U = (-1.625, 'pA')  # (-14.0, 'mV/ms')
    V = (-65.0, 'mV')
    izhi_path = '//neuron/Izhikevich#IzhikevichFastSpikingDefault'
    isyn_path = os.path.join(os.path.relpath(ninemlcatalog.root), 'input',
                             'StepCurrent.xml#StepCurrent')
    isyn_amp = (100.0, 'pA')
    isyn_onset = (50.0, 'ms')
    isyn_init = (0.0, 'pA')

    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.tmpdir)

    def test_single_cell(self):
        in_path = '{}/isyn.pkl'.format(self.tmpdir)
        out_path = '{}/v.pkl'.format(self.tmpdir)
        # First simulate input signal to have something to play into izhikevich
        # cell
        argv = ("{input_model} nest {t_stop} {dt} "
                "--record current_output {out_path} "
                "--prop amplitude {amp} "
                "--prop onset {onset} "
                "--init_value current_output {init} "
                "--build_mode force"  # FIXME: This should be converted to lazy
                .format(input_model=self.isyn_path, out_path=in_path,
                        t_stop=self.t_stop, dt=self.dt,
                        amp='{} {}'.format(*self.isyn_amp),
                        onset='{} {}'.format(*self.isyn_onset),
                        init='{} {}'.format(*self.isyn_init)))
        # Run input signal simulation
        simulate.run(argv.split())
        isyn = neo.io.PickleIO(in_path).read()[0].analogsignals[0]
        # Check sanity of input signal
        self.assertEqual(isyn.max(), self.isyn_amp[0],
                         "Max of isyn input signal {} ({}) did not match "
                         "specified amplitude, {}".format(
                             isyn.max(), in_path, self.isyn_amp[0]))
        self.assertEqual(isyn.min(), self.isyn_init[0],
                         "Min of isyn input signal {} ({}) did not match "
                         "specified initial value, {}"
                         .format(isyn.min(), in_path, self.isyn_init[0]))
        for simulator in ('nest', 'neuron'):
            argv = (
                "{nineml_model} {sim} {t_stop} {dt} "
                "--record V {out_path} "
                "--init_value U {U} "
                "--init_value V {V} "
                "--init_regime subVb "
                "--play iSyn {in_path} "
                "--build_mode force"
                .format(nineml_model=self.izhi_path, sim=simulator,
                        out_path=out_path, in_path=in_path, t_stop=self.t_stop,
                        dt=self.dt, U='{} {}'.format(*self.U),
                        V='{} {}'.format(*self.V),
                        isyn_amp='{} {}'.format(*self.isyn_amp),
                        isyn_onset='{} {}'.format(*self.isyn_onset),
                        isyn_init='{} {}'.format(*self.isyn_init)))
            simulate.run(argv.split())
            data_seg = neo.io.PickleIO(out_path).read()[0]
            v = data_seg.analogsignals[0]
            regimes = data_seg.epocharrays[0]
            ref_v, ref_regimes = self._ref_single_cell(simulator, isyn)
            self.assertTrue(all(v == ref_v),
                             "'simulate' command produced different results to"
                             " to api reference for izhikevich model using "
                             "'{}' simulator".format(simulator))
            # FIXME: Need a better test
            self.assertGreater(
                v.max(), -60.0,
                "No spikes generated for '{}' (max val: {}) version of Izhi "
                "model. Probably error in 'play' method if all dynamics tests "
                "pass ".format(simulator, v.max()))
            self.assertTrue(all(regimes.times == ref_regimes.times))
            self.assertTrue(all(regimes.durations == ref_regimes.durations))
            self.assertEqual(regimes.labels, ref_regimes.labels)<commit_msg>switched up izhikevich properties version used in test_simulate<commit_after>import os.path
import tempfile
import shutil
import neo.io
import numpy as np
from pype9.cmd import simulate
from pype9.cmd._utils import parse_units
import ninemlcatalog
from pype9.simulator.neuron import (
    Simulation as NeuronSimulation,
    CellMetaClass as NeuronCellMetaClass,
    Network as NetworkNEURON)
from pype9.simulator.nest import (
    Simulation as NESTSimulation,
    CellMetaClass as NESTCellMetaClass,
    Network as NetworkNEST)
import nineml
import nineml.units as un
if __name__ == '__main__':
    from pype9.utils.testing import DummyTestCase as TestCase  # @UnusedImport
else:
    from unittest import TestCase  # @Reimport


class TestSimulateCell(TestCase):

    ref_path = ''

    # Izhikevich simulation params
    t_stop = 100.0
    dt = 0.001
    U = (-1.625, 'pA')  # (-14.0, 'mV/ms')
    V = (-65.0, 'mV')
    izhi_path = '//neuron/Izhikevich#SampleIzhikevichFastSpiking'
    isyn_path = os.path.join(os.path.relpath(ninemlcatalog.root), 'input',
                             'StepCurrent.xml#StepCurrent')
    isyn_amp = (100.0, 'pA')
    isyn_onset = (50.0, 'ms')
    isyn_init = (0.0, 'pA')

    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.tmpdir)

    def test_single_cell(self):
        in_path = '{}/isyn.pkl'.format(self.tmpdir)
        out_path = '{}/v.pkl'.format(self.tmpdir)
        # First simulate input signal to have something to play into izhikevich
        # cell
        argv = ("{input_model} nest {t_stop} {dt} "
                "--record current_output {out_path} "
                "--prop amplitude {amp} "
                "--prop onset {onset} "
                "--init_value current_output {init} "
                "--build_mode force"  # FIXME: This should be converted to lazy
                .format(input_model=self.isyn_path, out_path=in_path,
                        t_stop=self.t_stop, dt=self.dt,
                        amp='{} {}'.format(*self.isyn_amp),
                        onset='{} {}'.format(*self.isyn_onset),
                        init='{} {}'.format(*self.isyn_init)))
        # Run input signal simulation
        simulate.run(argv.split())
        isyn = neo.io.PickleIO(in_path).read()[0].analogsignals[0]
        # Check sanity of input signal
        self.assertEqual(isyn.max(), self.isyn_amp[0],
                         "Max of isyn input signal {} ({}) did not match "
                         "specified amplitude, {}".format(
                             isyn.max(), in_path, self.isyn_amp[0]))
        self.assertEqual(isyn.min(), self.isyn_init[0],
                         "Min of isyn input signal {} ({}) did not match "
                         "specified initial value, {}"
                         .format(isyn.min(), in_path, self.isyn_init[0]))
        for simulator in ('nest', 'neuron'):
            argv = (
                "{nineml_model} {sim} {t_stop} {dt} "
                "--record V {out_path} "
                "--init_value U {U} "
                "--init_value V {V} "
                "--init_regime subVb "
                "--play iSyn {in_path} "
                "--build_mode force"
                .format(nineml_model=self.izhi_path, sim=simulator,
                        out_path=out_path, in_path=in_path, t_stop=self.t_stop,
                        dt=self.dt, U='{} {}'.format(*self.U),
                        V='{} {}'.format(*self.V),
                        isyn_amp='{} {}'.format(*self.isyn_amp),
                        isyn_onset='{} {}'.format(*self.isyn_onset),
                        isyn_init='{} {}'.format(*self.isyn_init)))
            simulate.run(argv.split())
            data_seg = neo.io.PickleIO(out_path).read()[0]
            v = data_seg.analogsignals[0]
            regimes = data_seg.epocharrays[0]
            ref_v, ref_regimes = self._ref_single_cell(simulator, isyn)
            self.assertTrue(all(v == ref_v),
                             "'simulate' command produced different results to"
                             " to api reference for izhikevich model using "
                             "'{}' simulator".format(simulator))
            # FIXME: Need a better test
            self.assertGreater(
                v.max(), -60.0,
                "No spikes generated for '{}' (max val: {}) version of Izhi "
                "model. Probably error in 'play' method if all dynamics tests "
                "pass ".format(simulator, v.max()))
            self.assertTrue(all(regimes.times == ref_regimes.times))
            self.assertTrue(all(regimes.durations == ref_regimes.durations))
            self.assertEqual(regimes.labels, ref_regimes.labels)
            self.assertEqual(len(regimes.times), 2)
{'fraction_non_alphanumeric': 0.1246717781745615, 'fraction_numerical': 0.009347757588488603, 'mean_word_length': 1.8457860131500299, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6063570', 'n_tokens_mistral': 3016, 'n_tokens_neox': 2871, 'n_words': 630}