{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Check for capabilities at the instance level in a LEMSModel" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import neuronunit\n", "NU = neuronunit.__path__[0]" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from neuronunit.models.reduced import ReducedModel" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# The regular Izhikevich model\n", "model = ReducedModel(os.path.join(NU,'models/NeuroML2/LEMS_2007One.xml'))\n", "\n", "# Same model with only explicitInput removed. \n", "model_no_input_1 = ReducedModel(os.path.join(NU,'models/NeuroML2/fragments/LEMS_2007One-no-input-1.xml'))\n", "\n", "# Same model with only pulseGenerator removed. \n", "model_no_input_2 = ReducedModel(os.path.join(NU,'models/NeuroML2/fragments/LEMS_2007One-no-input-2.xml'))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "assert model.has_pulse_generator() # Because the regular model should have the components it needs\n", "assert not model_no_input_1.has_pulse_generator() # Because part of the implementation has been removed \n", "assert not model_no_input_2.has_pulse_generator() # Because another part of the implemntation has been removed" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from neuronunit.capabilities import ReceivesSquareCurrent, ProducesActionPotentials" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ReceivesSquareCurrent.check(model) # Should return True" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(False, False)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ReceivesSquareCurrent.check(model_no_input_1), ReceivesSquareCurrent.check(model_no_input_2) # Should return False, False" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ProducesActionPotentials.check(model) # Should return True" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(True, True)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Should return True, True because the removed components have nothing to do with action potential generating capabilities\n", "ProducesActionPotentials.check(model_no_input_1), ProducesActionPotentials.check(model_no_input_2)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([],\n", " [neuronunit.capabilities.ReceivesSquareCurrent],\n", " [neuronunit.capabilities.ReceivesSquareCurrent])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The first list should be empty because this model passes all extra capability checks. This list being empty\n", "# means that it should be safe to use. The other two models will contain ReceivesSquareCurrent, because this check failed\n", "# for each of those models. \n", "model.failed_extra_capabilities, model_no_input_1.failed_extra_capabilities, model_no_input_2.failed_extra_capabilities" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }