from pacman103.core.utilities import packet_conversions
from pacman103.front.common import enums
import copy
from math import ceil

import logging
logger = logging.getLogger(__name__)

SETUP_SIZE = 16 # Single word of info with flags, etc.
                # plus the lengths of each of the output buffer
                # regions in bytes

REGIONS = enums.enum1(
    'SYSTEM',
    'DELAY_PARAMS',
    'SPIKE_HISTORY'
)

RECORD_SPIKE_BIT = 1<<0
RECORD_STATE_BIT = 1<<1
RECORD_GSYN_BIT  = 1<<2

SETUP_SZ = 16
BITS_PER_WORD = 32.0
BLOCK_INDEX_HEADER_WORDS = 3
BLOCK_INDEX_ROW_WORDS = 2

# Version string for this DSG:
DsgVersionMaj = 0
DsgVersionMin = 1
from pacman103.lib import graph
from pacman103.lib import lib_dsg
from pacman103.lib import lib_map
from pacman103.front.common import enums
import os
from pacman103.lib import parameters
import struct
import numpy as np

REGIONS = enums.enum1(
    'SYSTEM',
    'BIAS',
    'ENCODERS',
    'DECODERS',
    'DECODER_KEYS'
    )


class EnsembleVertex( graph.Vertex ):
    def __init__(self, data, constraints=None):
        super(EnsembleVertex, self).__init__(data.N, constraints=constraints, 
                            label=data.label)
        self.data = data                    
    
    def model_name(self):
        return 'nengo-ensemble'
    
    def get_requirements_per_atom(self):
        chip_memory = 4 + self.data.D_in*4 + self.data.D_out*4
        data_memory = chip_memory
        cycles = 1
from pacman103.lib import graph
from pacman103.lib import lib_dsg
from pacman103.lib import lib_map
from pacman103.front.common import enums
import os
from pacman103.lib import parameters
import struct
import numpy as np

REGIONS = enums.enum1('SYSTEM', 'BIAS', 'ENCODERS', 'DECODERS', 'DECODER_KEYS')


class EnsembleVertex(graph.Vertex):
    def __init__(self, data, constraints=None):
        super(EnsembleVertex, self).__init__(data.N,
                                             constraints=constraints,
                                             label=data.label)
        self.data = data

    def model_name(self):
        return 'nengo-ensemble'

    def get_requirements_per_atom(self):
        chip_memory = 4 + self.data.D_in * 4 + self.data.D_out * 4
        data_memory = chip_memory
        cycles = 1

        return lib_map.Resources(cycles, data_memory, chip_memory)

    def generateDataSpec(self, processor, subvertex, dao):
        IDENTIFIER = 0xABCD
from pacman103.lib import lib_map, data_spec_gen, data_spec_constants

import numpy
import struct
import os
import math
import ctypes
import logging
logger = logging.getLogger(__name__)

REGIONS = enums.enum1(
    'SYSTEM',
    'NEURON_PARAMS',
    'SYNAPSE_PARAMS',
    'ROW_LEN_TRANSLATION',
    'MASTER_POP_TABLE',
    'SYNAPTIC_MATRIX',
    'STDP_PARAMS',
    'SPIKE_HISTORY',
    'POTENTIAL_HISTORY',
    'GSYN_HISTORY',
)

# Some constants
SETUP_SIZE = 16 # Single word of info with flags, etc.
                # plus the lengths of each of the output buffer
                # regions in bytes

NO_PARAMS = 10  
PARAMS_HEADER_SIZE = 3 # Number of 32-bit words in header of params block
PARAMS_BASE_SIZE = 4 * (PARAMS_HEADER_SIZE + NO_PARAMS)