index ModelManager::copy_synapse_model_( index old_id, Name new_name ) { size_t new_id = prototypes_[ 0 ].size(); if ( new_id == invalid_synindex ) // we wrapped around (=255), maximal id of // synapse_model = 254 { LOG( M_ERROR, "ModelManager::copy_synapse_model_", "CopyModel cannot generate another synapse. Maximal synapse model count " "of 255 exceeded." ); throw KernelException( "Synapse model count exceeded" ); } assert( new_id != invalid_synindex ); // if the copied synapse is a secondary connector model the synid of the copy // has to be mapped to the corresponding secondary event type if ( not get_synapse_prototype( old_id ).is_primary() ) { ( get_synapse_prototype( old_id ).get_event() )->add_syn_id( new_id ); } for ( thread t = 0; t < static_cast< thread >( kernel().vp_manager.get_num_threads() ); ++t ) { prototypes_[ t ].push_back( get_synapse_prototype( old_id ).clone( new_name.toString() ) ); prototypes_[ t ][ new_id ]->set_syn_id( new_id ); } synapsedict_->insert( new_name, new_id ); return new_id; }
void nest::cg_connect( nest::ConnectionGeneratorDatum& cg, IntVectorDatum& sources, IntVectorDatum& targets, const DictionaryDatum& params_map, const Name& synmodel_name ) { const Token synmodel = kernel().model_manager.get_synapsedict()->lookup( synmodel_name ); if ( synmodel.empty() ) throw UnknownSynapseType( synmodel_name.toString() ); const index synmodel_id = static_cast< index >( synmodel ); RangeSet source_ranges; cg_get_ranges( source_ranges, ( *sources ) ); RangeSet target_ranges; cg_get_ranges( target_ranges, ( *targets ) ); cg_connect( cg, source_ranges, ( *sources ), target_ranges, ( *targets ), params_map, synmodel_id ); }
DictionaryDatum get_model_defaults( const Name& modelname ) { const Token nodemodel = kernel().model_manager.get_modeldict()->lookup( modelname ); const Token synmodel = kernel().model_manager.get_synapsedict()->lookup( modelname ); DictionaryDatum dict; if ( !nodemodel.empty() ) { const long model_id = static_cast< long >( nodemodel ); Model* m = kernel().model_manager.get_model( model_id ); dict = m->get_status(); } else if ( !synmodel.empty() ) { const long synapse_id = static_cast< long >( synmodel ); dict = kernel().model_manager.get_connector_defaults( synapse_id ); } else { throw UnknownModelName( modelname.toString() ); } return dict; }
/** * This function is not thread save and has to be called inside a omp critical * region. */ int nest::sli_neuron::execute_sli_protected( DictionaryDatum state, Name cmd ) { SLIInterpreter& i = get_engine(); i.DStack->push( state ); // push state dictionary as top namespace size_t exitlevel = i.EStack.load(); i.EStack.push( new NameDatum( cmd ) ); int result = i.execute_( exitlevel ); i.DStack->pop(); // pop neuron's namespace if ( state->known( "error" ) ) { assert( state->known( names::global_id ) ); index g_id = ( *state )[ names::global_id ]; std::string model = getValue< std::string >( ( *state )[ names::model ] ); std::string msg = String::compose( "Error in %1 with global id %2.", model, g_id ); LOG( M_ERROR, cmd.toString().c_str(), msg.c_str() ); LOG( M_ERROR, "execute_sli_protected", "Terminating." ); kernel().simulation_manager.terminate(); } return result; }
index ModelManager::copy_node_model_( index old_id, Name new_name ) { Model* new_model = get_model( old_id )->clone( new_name.toString() ); models_.push_back( new_model ); index new_id = models_.size() - 1; modeldict_->insert( new_name, new_id ); for ( thread t = 0; t < static_cast< thread >( kernel().vp_manager.get_num_threads() ); ++t ) { Node* newnode = proxynode_model_->allocate( t ); newnode->set_model_id( new_id ); proxy_nodes_[ t ].push_back( newnode ); } return new_id; }
void nest::cg_connect( nest::ConnectionGeneratorDatum& cg, const index source_id, const index target_id, const DictionaryDatum& params_map, const Name& synmodel_name ) { Subnet* sources = dynamic_cast< Subnet* >( kernel().node_manager.get_node( source_id ) ); if ( sources == NULL ) { LOG( M_ERROR, "CGConnect_cg_i_i_D_l", "sources must be a subnet." ); throw SubnetExpected(); } if ( !sources->is_homogeneous() ) { LOG( M_ERROR, "CGConnect_cg_i_i_D_l", "sources must be a homogeneous subnet." ); throw BadProperty(); } if ( dynamic_cast< Subnet* >( *sources->local_begin() ) ) { LOG( M_ERROR, "CGConnect_cg_i_i_D_l", "Only 1-dim subnets are supported as sources." ); throw BadProperty(); } Subnet* targets = dynamic_cast< Subnet* >( kernel().node_manager.get_node( target_id ) ); if ( targets == NULL ) { LOG( M_ERROR, "CGConnect_cg_i_i_D_l", "targets must be a subnet." ); throw SubnetExpected(); } if ( !targets->is_homogeneous() ) { LOG( M_ERROR, "CGConnect_cg_i_i_D_l", "targets must be a homogeneous subnet." ); throw BadProperty(); } if ( dynamic_cast< Subnet* >( *targets->local_begin() ) ) { LOG( M_ERROR, "CGConnect_cg_i_i_D_l", "Only 1-dim subnets are supported as targets." ); throw BadProperty(); } const Token synmodel = kernel().model_manager.get_synapsedict()->lookup( synmodel_name ); if ( synmodel.empty() ) throw UnknownSynapseType( synmodel_name.toString() ); const index synmodel_id = static_cast< index >( synmodel ); const modelrange source_range = kernel().modelrange_manager.get_contiguous_gid_range( ( *sources->local_begin() )->get_gid() ); index source_offset = source_range.get_first_gid(); RangeSet source_ranges; source_ranges.push_back( Range( source_range.get_first_gid(), source_range.get_last_gid() ) ); const modelrange target_range = kernel().modelrange_manager.get_contiguous_gid_range( ( *targets->local_begin() )->get_gid() ); index target_offset = target_range.get_first_gid(); RangeSet target_ranges; target_ranges.push_back( Range( target_range.get_first_gid(), target_range.get_last_gid() ) ); cg_connect( cg, source_ranges, source_offset, target_ranges, target_offset, params_map, synmodel_id ); }
Diag AliasDependsOnItselfDiag(Name name) { return Error("alias '%s' depends on itself via a cycle", name.toString(/*addPrefix=*/false).c_str()); }
SEM::TypeInstance* AddTypeInstance(Context& context, const AST::Node<AST::TypeInstance>& astTypeInstanceNode, const SEM::ModuleScope& moduleScope) { const auto parentNamespace = context.scopeStack().back().nameSpace(); const auto& typeInstanceName = astTypeInstanceNode->name; const Name fullTypeName = parentNamespace->name() + typeInstanceName; // Check if there's anything with the same name. const auto iterator = parentNamespace->items().find(typeInstanceName); if (iterator != parentNamespace->items().end()) { const auto& existingTypeInstance = iterator->second.typeInstance(); const auto& debugInfo = *(existingTypeInstance.debugInfo()); throw ErrorException(makeString("Type instance name '%s', at position %s, clashes with existing name, at position %s.", fullTypeName.toString().c_str(), astTypeInstanceNode.location().toString().c_str(), debugInfo.location.toString().c_str())); } const auto typeInstanceKind = ConvertTypeInstanceKind(astTypeInstanceNode->kind); // Create a placeholder type instance. std::unique_ptr<SEM::TypeInstance> semTypeInstance(new SEM::TypeInstance(context.semContext(), fullTypeName.copy(), typeInstanceKind, moduleScope.copy())); if (semTypeInstance->isPrimitive()) { semTypeInstance->setPrimitiveID(context.sharedMaps().primitiveIDMap().getPrimitiveID(typeInstanceName)); } switch (moduleScope.kind()) { case SEM::ModuleScope::INTERNAL: { if (semTypeInstance->isClassDecl()) { throw ErrorException(makeString("Definition required for internal class '%s', at location %s.", fullTypeName.toString().c_str(), astTypeInstanceNode.location().toString().c_str())); } break; } case SEM::ModuleScope::IMPORT: { if (semTypeInstance->isClassDef()) { throw ErrorException(makeString("Implementation not allowed of imported class '%s', at location %s.", fullTypeName.toString().c_str(), astTypeInstanceNode.location().toString().c_str())); } break; } case SEM::ModuleScope::EXPORT: { if (semTypeInstance->isClassDecl()) { throw ErrorException(makeString("Definition required for exported class '%s', at location %s.", fullTypeName.toString().c_str(), astTypeInstanceNode.location().toString().c_str())); } break; } } semTypeInstance->setDebugInfo(Debug::TypeInstanceInfo(astTypeInstanceNode.location())); // Add template variables. size_t templateVarIndex = 0; for (const auto& astTemplateVarNode: *(astTypeInstanceNode->templateVariables)) { const auto& templateVarName = astTemplateVarNode->name; // TODO! const bool isVirtual = (typeInstanceName == "__ref"); const auto semTemplateVar = new SEM::TemplateVar(context.semContext(), fullTypeName + templateVarName, templateVarIndex++, isVirtual); const auto templateVarIterator = semTypeInstance->namedTemplateVariables().find(templateVarName); if (templateVarIterator != semTypeInstance->namedTemplateVariables().end()) { throw ErrorException(makeString("More than one template variable shares name '%s' in type '%s', at location %s.", templateVarName.c_str(), fullTypeName.toString().c_str(), astTemplateVarNode.location().toString().c_str())); } semTemplateVar->setDebugInfo(makeTemplateVarInfo(astTemplateVarNode)); semTypeInstance->templateVariables().push_back(semTemplateVar); semTypeInstance->namedTemplateVariables().insert(std::make_pair(templateVarName, semTemplateVar)); } if (semTypeInstance->isUnionDatatype()) { for (auto& astVariantNode: *(astTypeInstanceNode->variants)) { const auto variantTypeInstance = AddTypeInstance(context, astVariantNode, moduleScope); variantTypeInstance->setParent(semTypeInstance.get()); variantTypeInstance->templateVariables() = semTypeInstance->templateVariables().copy(); variantTypeInstance->namedTemplateVariables() = semTypeInstance->namedTemplateVariables().copy(); semTypeInstance->variants().push_back(variantTypeInstance); } } if (!astTypeInstanceNode->noTagSet.isNull()) { SEM::TemplateVarArray noTagSet; for (const auto& astNoTagName: *(astTypeInstanceNode->noTagSet)) { const auto templateVarIterator = semTypeInstance->namedTemplateVariables().find(astNoTagName); if (templateVarIterator == semTypeInstance->namedTemplateVariables().end()) { throw ErrorException(makeString("Can't find template variable '%s' in notag() set in type '%s', at location %s.", astNoTagName.c_str(), fullTypeName.toString().c_str(), astTypeInstanceNode->noTagSet.location().toString().c_str())); } noTagSet.push_back(templateVarIterator->second); } semTypeInstance->setNoTagSet(std::move(noTagSet)); } const auto typeInstancePtr = semTypeInstance.get(); parentNamespace->items().insert(std::make_pair(typeInstanceName, SEM::NamespaceItem::TypeInstance(std::move(semTypeInstance)))); return typeInstancePtr; }