idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
50,600 | def _get_next_nn_id ( self ) : self . _nn_id = self . _nn_id + 1 if self . _nn_id < 126 else 1 return self . _nn_id * 2 | Get the next nearest neighbour ID . |
50,601 | def _send_ffs ( self , pid , n_blocks , fr ) : sfr = fr | ( 1 << 31 ) self . _send_scp ( 255 , 255 , 0 , SCPCommands . nearest_neighbour_packet , ( NNCommands . flood_fill_start << 24 ) | ( pid << 16 ) | ( n_blocks << 8 ) , 0x0 , sfr ) | Send a flood - fill start packet . |
50,602 | def _send_ffcs ( self , region , core_mask , fr ) : arg1 = ( NNCommands . flood_fill_core_select << 24 ) | core_mask arg2 = region self . _send_scp ( 255 , 255 , 0 , SCPCommands . nearest_neighbour_packet , arg1 , arg2 , fr ) | Send a flood - fill core select packet . |
50,603 | def _send_ffd ( self , pid , aplx_data , address ) : block = 0 pos = 0 aplx_size = len ( aplx_data ) while pos < aplx_size : data = aplx_data [ pos : pos + self . scp_data_length ] data_size = len ( data ) size = data_size // 4 - 1 arg1 = ( NNConstants . forward << 24 | NNConstants . retry << 16 | pid ) arg2 = ( block ... | Send flood - fill data packets . |
50,604 | def _send_ffe ( self , pid , app_id , app_flags , fr ) : arg1 = ( NNCommands . flood_fill_end << 24 ) | pid arg2 = ( app_id << 24 ) | ( app_flags << 18 ) self . _send_scp ( 255 , 255 , 0 , SCPCommands . nearest_neighbour_packet , arg1 , arg2 , fr ) | Send a flood - fill end packet . |
50,605 | def flood_fill_aplx ( self , * args , ** kwargs ) : application_map = { } if len ( args ) == 1 : application_map = args [ 0 ] elif len ( args ) == 2 : application_map = { args [ 0 ] : args [ 1 ] } else : raise TypeError ( "flood_fill_aplx: accepts either 1 or 2 positional arguments: " "a map of filenames to targets OR ... | Unreliably flood - fill APLX to a set of application cores . |
50,606 | def load_application ( self , * args , ** kwargs ) : app_id = kwargs . pop ( "app_id" ) wait = kwargs . pop ( "wait" ) n_tries = kwargs . pop ( "n_tries" ) app_start_delay = kwargs . pop ( "app_start_delay" ) use_count = kwargs . pop ( "use_count" , True ) application_map = { } if len ( args ) == 1 : application_map = ... | Load an application to a set of application cores . |
50,607 | def send_signal ( self , signal , app_id ) : if isinstance ( signal , str ) : try : signal = getattr ( consts . AppSignal , signal ) except AttributeError : pass if signal not in consts . AppSignal : raise ValueError ( "send_signal: Cannot transmit signal of type {}" . format ( repr ( signal ) ) ) arg1 = consts . signa... | Transmit a signal to applications . |
50,608 | def count_cores_in_state ( self , state , app_id ) : if ( isinstance ( state , collections . Iterable ) and not isinstance ( state , str ) ) : return sum ( self . count_cores_in_state ( s , app_id ) for s in state ) if isinstance ( state , str ) : try : state = getattr ( consts . AppState , state ) except AttributeErro... | Count the number of cores in a given state . |
50,609 | def wait_for_cores_to_reach_state ( self , state , count , app_id , poll_interval = 0.1 , timeout = None ) : if timeout is not None : timeout_time = time . time ( ) + timeout while True : cur_count = self . count_cores_in_state ( state , app_id ) if cur_count >= count : break if timeout is not None and time . time ( ) ... | Block until the specified number of cores reach the specified state . |
50,610 | def load_routing_tables ( self , routing_tables , app_id ) : for ( x , y ) , table in iteritems ( routing_tables ) : self . load_routing_table_entries ( table , x = x , y = y , app_id = app_id ) | Allocate space for an load multicast routing tables . |
50,611 | def load_routing_table_entries ( self , entries , x , y , app_id ) : count = len ( entries ) rv = self . _send_scp ( x , y , 0 , SCPCommands . alloc_free , ( app_id << 8 ) | consts . AllocOperations . alloc_rtr , count ) rtr_base = rv . arg1 if rtr_base == 0 : raise SpiNNakerRouterError ( count , x , y ) buf = self . r... | Allocate space for and load multicast routing table entries into the router of a SpiNNaker chip . |
50,612 | def get_routing_table_entries ( self , x , y ) : rtr_addr = self . read_struct_field ( "sv" , "rtr_copy" , x , y ) read_size = struct . calcsize ( consts . RTE_PACK_STRING ) rtr_data = self . read ( rtr_addr , consts . RTR_ENTRIES * read_size , x , y ) table = list ( ) while len ( rtr_data ) > 0 : entry , rtr_data = rt... | Dump the multicast routing table of a given chip . |
50,613 | def clear_routing_table_entries ( self , x , y , app_id ) : arg1 = ( app_id << 8 ) | consts . AllocOperations . free_rtr_by_app self . _send_scp ( x , y , 0 , SCPCommands . alloc_free , arg1 , 0x1 ) | Clear the routing table entries associated with a given application . |
50,614 | def get_p2p_routing_table ( self , x , y ) : table = { } p2p_dims = self . read_struct_field ( "sv" , "p2p_dims" , x , y ) width = ( p2p_dims >> 8 ) & 0xFF height = ( p2p_dims >> 0 ) & 0xFF col_words = ( ( ( height + 7 ) // 8 ) * 4 ) for col in range ( width ) : raw_table_col = self . read ( consts . SPINNAKER_RTR_P2P ... | Dump the contents of a chip s P2P routing table . |
50,615 | def get_chip_info ( self , x , y ) : info = self . _send_scp ( x , y , 0 , SCPCommands . info , expected_args = 3 ) num_cores = info . arg1 & 0x1F working_links = set ( link for link in Links if ( info . arg1 >> ( 8 + link ) ) & 1 ) largest_free_rtr_mc_block = ( info . arg1 >> 14 ) & 0x7FF ethernet_up = bool ( info . a... | Get general information about the resources available on a chip . |
50,616 | def get_system_info ( self , x = 255 , y = 255 ) : p2p_tables = self . get_p2p_routing_table ( x , y ) max_x = max ( x_ for ( x_ , y_ ) , r in iteritems ( p2p_tables ) if r != consts . P2PTableEntry . none ) max_y = max ( y_ for ( x_ , y_ ) , r in iteritems ( p2p_tables ) if r != consts . P2PTableEntry . none ) sys_inf... | Discover the integrity and resource availability of a whole SpiNNaker system . |
50,617 | def ethernet_connected_chips ( self ) : for xy , chip_info in six . iteritems ( self ) : if chip_info . ethernet_up : yield ( xy , chip_info . ip_address ) | Iterate over the coordinates of Ethernet connected chips . |
50,618 | def dead_chips ( self ) : for x in range ( self . width ) : for y in range ( self . height ) : if ( x , y ) not in self : yield ( x , y ) | Generate the coordinates of all dead chips . |
50,619 | def links ( self ) : for ( x , y ) , chip_info in iteritems ( self ) : for link in chip_info . working_links : yield ( x , y , link ) | Generate the coordinates of all working links . |
50,620 | def dead_links ( self ) : for ( x , y ) , chip_info in iteritems ( self ) : for link in Links : if link not in chip_info . working_links : yield ( x , y , link ) | Generate the coordinates of all dead links leaving working chips . |
50,621 | def cores ( self ) : for ( x , y ) , chip_info in iteritems ( self ) : for p , state in enumerate ( chip_info . core_states ) : yield ( x , y , p , state ) | Generate the set of all cores in the system . |
50,622 | def read ( self , n_bytes = - 1 ) : if n_bytes < 0 : n_bytes = self . _end_address - self . address if self . address + n_bytes > self . _end_address : new_n_bytes = self . _end_address - self . address warnings . warn ( "read truncated from {} to {} bytes" . format ( n_bytes , new_n_bytes ) , TruncationWarning , stack... | Read a number of bytes from the memory . |
50,623 | def write ( self , bytes ) : if self . address + len ( bytes ) > self . _end_address : n_bytes = self . _end_address - self . address warnings . warn ( "write truncated from {} to {} bytes" . format ( len ( bytes ) , n_bytes ) , TruncationWarning , stacklevel = 3 ) bytes = bytes [ : n_bytes ] if len ( bytes ) == 0 : re... | Write data to the memory . |
50,624 | def seek ( self , n_bytes , from_what = os . SEEK_SET ) : if from_what == 0 : self . _offset = n_bytes elif from_what == 1 : self . _offset += n_bytes elif from_what == 2 : self . _offset = ( self . _end_address - self . _start_address ) - n_bytes else : raise ValueError ( "from_what: can only take values 0 (from start... | Seek to a new position in the memory region . |
50,625 | def free ( self ) : self . _machine_controller . sdram_free ( self . _start_address , self . _x , self . _y ) self . _freed = True | Free the memory referred to by the file - like any subsequent operations on this file - like or slices of it will fail . |
50,626 | def _perform_read ( self , addr , size ) : return self . _machine_controller . read ( addr , size , self . _x , self . _y , 0 ) | Perform a read using the machine controller . |
50,627 | def _perform_write ( self , addr , data ) : return self . _machine_controller . write ( addr , data , self . _x , self . _y , 0 ) | Perform a write using the machine controller . |
50,628 | def _unpack_sdp_into_packet ( packet , bytestring ) : packet . data = bytestring [ 10 : ] ( flags , packet . tag , dest_cpu_port , src_cpu_port , packet . dest_y , packet . dest_x , packet . src_y , packet . src_x ) = struct . unpack_from ( '<2x8B' , bytestring ) packet . reply_expected = flags == FLAG_REPLY packet . d... | Unpack the SDP header from a bytestring into a packet . |
50,629 | def packed_data ( self ) : scp_header = struct . pack ( "<2H" , self . cmd_rc , self . seq ) if self . arg1 is not None : scp_header += struct . pack ( '<I' , self . arg1 ) if self . arg2 is not None : scp_header += struct . pack ( '<I' , self . arg2 ) if self . arg3 is not None : scp_header += struct . pack ( '<I' , s... | Pack the data for the SCP packet . |
50,630 | def hash64 ( key , seed ) : hash_val = mmh3 . hash64 ( key , seed ) [ 0 ] return struct . unpack ( '>Q' , struct . pack ( 'q' , hash_val ) ) [ 0 ] | Wrapper around mmh3 . hash64 to get us single 64 - bit value . |
50,631 | def generate_hashfunctions ( nbr_bits , nbr_slices ) : def _make_hashfuncs ( key ) : if isinstance ( key , text_type ) : key = key . encode ( 'utf-8' ) else : key = str ( key ) rval = [ ] current_hash = 0 for i in range ( nbr_slices ) : seed = current_hash current_hash = hash64 ( key , seed ) rval . append ( current_ha... | Generate a set of hash functions . |
50,632 | def get_context_arguments ( self ) : cargs = { } for context in self . __context_stack : cargs . update ( context . context_arguments ) return cargs | Return a dictionary containing the current context arguments . |
50,633 | def use_contextual_arguments ( ** kw_only_args_defaults ) : def decorator ( f ) : arg_names , varargs , keywords , defaults = inspect . getargspec ( f ) assert set ( keywords or { } ) . isdisjoint ( set ( kw_only_args_defaults ) ) if defaults is None : defaults = [ ] defaults = ( ( [ Required ] * ( len ( arg_names ) - ... | Decorator function which allows the wrapped function to accept arguments not specified in the call from the context . |
50,634 | def minimise ( routing_table , target_length ) : table , _ = ordered_covering ( routing_table , target_length , no_raise = True ) return remove_default_routes ( table , target_length ) | Reduce the size of a routing table by merging together entries where possible and by removing any remaining default routes . |
50,635 | def ordered_covering ( routing_table , target_length , aliases = dict ( ) , no_raise = False ) : aliases = dict ( aliases ) routing_table = sorted ( routing_table , key = lambda entry : _get_generality ( entry . key , entry . mask ) ) while target_length is None or len ( routing_table ) > target_length : merge = _get_b... | Reduce the size of a routing table by merging together entries where possible . |
50,636 | def _get_generality ( key , mask ) : xs = ( ~ key ) & ( ~ mask ) return sum ( 1 for i in range ( 32 ) if xs & ( 1 << i ) ) | Count the number of Xs in the key - mask pair . |
50,637 | def _get_best_merge ( routing_table , aliases ) : best_merge = _Merge ( routing_table ) best_goodness = 0 for merge in _get_all_merges ( routing_table ) : if merge . goodness <= best_goodness : continue merge = _refine_merge ( merge , aliases , min_goodness = best_goodness ) if merge . goodness > best_goodness : best_m... | Inspect all possible merges for the routing table and return the merge which would combine the greatest number of entries . |
50,638 | def _get_all_merges ( routing_table ) : considered_entries = set ( ) for i , entry in enumerate ( routing_table ) : if i in considered_entries : continue merge = set ( [ i ] ) merge . update ( j for j , other_entry in enumerate ( routing_table [ i + 1 : ] , start = i + 1 ) if entry . route == other_entry . route ) cons... | Get possible sets of entries to merge . |
50,639 | def _get_insertion_index ( routing_table , generality ) : generality -= 1 def gg ( entry ) : return _get_generality ( entry . key , entry . mask ) bottom = 0 top = len ( routing_table ) pos = ( top - bottom ) // 2 pg = gg ( routing_table [ pos ] ) while pg != generality and bottom < pos < top : if pg < generality : bot... | Determine the index in the routing table where a new entry should be inserted . |
50,640 | def _refine_merge ( merge , aliases , min_goodness ) : merge = _refine_downcheck ( merge , aliases , min_goodness ) if merge . goodness > min_goodness : merge , changed = _refine_upcheck ( merge , min_goodness ) if changed and merge . goodness > min_goodness : merge = _refine_downcheck ( merge , aliases , min_goodness ... | Remove entries from a merge to generate a valid merge which may be applied to the routing table . |
50,641 | def _refine_upcheck ( merge , min_goodness ) : changed = False for i in sorted ( merge . entries , reverse = True ) : entry = merge . routing_table [ i ] key , mask = entry . key , entry . mask if any ( intersect ( key , mask , other . key , other . mask ) for other in merge . routing_table [ i + 1 : merge . insertion_... | Remove from the merge any entries which would be covered by entries between their current position and the merge insertion position . |
50,642 | def _refine_downcheck ( merge , aliases , min_goodness ) : all_bits = tuple ( 1 << i for i in range ( 32 ) ) while merge . goodness > min_goodness : covered = list ( _get_covered_keys_and_masks ( merge , aliases ) ) if not covered : break most_stringent = 33 bits_and_vals = set ( ) for key , mask in covered : settable ... | Prune the merge to avoid it covering up any entries which are below the merge insertion position . |
50,643 | def _get_covered_keys_and_masks ( merge , aliases ) : for entry in merge . routing_table [ merge . insertion_index : ] : key_mask = ( entry . key , entry . mask ) keys_masks = aliases . get ( key_mask , [ key_mask ] ) for key , mask in keys_masks : if intersect ( merge . key , merge . mask , key , mask ) : yield key , ... | Get keys and masks which would be covered by the entry resulting from the merge . |
50,644 | def apply ( self , aliases ) : new_size = len ( self . routing_table ) - len ( self . entries ) + 1 new_table = [ None for _ in range ( new_size ) ] aliases = dict ( aliases ) new_entry = RoutingTableEntry ( route = self . routing_table [ next ( iter ( self . entries ) ) ] . route , key = self . key , mask = self . mas... | Apply the merge to the routing table it is defined against and get a new routing table and alias dictionary . |
50,645 | def find_packages ( name , pkg_dir ) : for c in ( FileSystemPackageBuilder , ZipPackageBuilder , ExcelPackageBuilder ) : package_path , cache_path = c . make_package_path ( pkg_dir , name ) if package_path . exists ( ) : yield c . type_code , package_path , cache_path | Locate pre - built packages in the _packages directory |
50,646 | def initialize_bitarray ( self ) : self . bitarray = bitarray . bitarray ( self . nbr_bits ) self . current_day_bitarray = bitarray . bitarray ( self . nbr_bits ) self . bitarray . setall ( False ) self . current_day_bitarray . setall ( False ) | Initialize both bitarray . |
50,647 | def initialize_period ( self , period = None ) : if not period : self . current_period = dt . datetime . now ( ) else : self . current_period = period self . current_period = dt . datetime ( self . current_period . year , self . current_period . month , self . current_period . day ) self . date = self . current_period ... | Initialize the period of BF . |
50,648 | def warm ( self , jittering_ratio = 0.2 ) : if self . snapshot_to_load == None : last_period = self . current_period - dt . timedelta ( days = self . expiration - 1 ) self . compute_refresh_period ( ) self . snapshot_to_load = [ ] base_filename = "%s/%s_%s_*.dat" % ( self . snapshot_path , self . name , self . expirati... | Progressively load the previous snapshot during the day . |
50,649 | def restore_from_disk ( self , clean_old_snapshot = False ) : base_filename = "%s/%s_%s_*.dat" % ( self . snapshot_path , self . name , self . expiration ) availables_snapshots = glob . glob ( base_filename ) last_period = self . current_period - dt . timedelta ( days = self . expiration - 1 ) for filename in available... | Restore the state of the BF using previous snapshots . |
50,650 | def save_snaphot ( self ) : filename = "%s/%s_%s_%s.dat" % ( self . snapshot_path , self . name , self . expiration , self . date ) with open ( filename , 'w' ) as f : f . write ( zlib . compress ( pickle . dumps ( self . current_day_bitarray , protocol = pickle . HIGHEST_PROTOCOL ) ) ) | Save the current state of the current day bitarray on disk . |
50,651 | def place ( vertices_resources , nets , machine , constraints , vertex_order = None , chip_order = None ) : if len ( vertices_resources ) == 0 : return { } machine = machine . copy ( ) placements = { } vertices_resources , nets , constraints , substitutions = apply_same_chip_constraints ( vertices_resources , nets , co... | Blindly places vertices in sequential order onto chips in the machine . |
50,652 | def place_and_route_wrapper ( vertices_resources , vertices_applications , nets , net_keys , system_info , constraints = [ ] , place = default_place , place_kwargs = { } , allocate = default_allocate , allocate_kwargs = { } , route = default_route , route_kwargs = { } , minimise_tables_methods = ( remove_default_entrie... | Wrapper for core place - and - route tasks for the common case . |
50,653 | def wrapper ( vertices_resources , vertices_applications , nets , net_keys , machine , constraints = [ ] , reserve_monitor = True , align_sdram = True , place = default_place , place_kwargs = { } , allocate = default_allocate , allocate_kwargs = { } , route = default_route , route_kwargs = { } , core_resource = Cores ,... | Wrapper for core place - and - route tasks for the common case . At a high level this function essentially takes a set of vertices and nets and produces placements memory allocations routing tables and application loading information . |
50,654 | def get_region_for_chip ( x , y , level = 3 ) : shift = 6 - 2 * level bit = ( ( x >> shift ) & 3 ) + 4 * ( ( y >> shift ) & 3 ) mask = 0xffff ^ ( ( 4 << shift ) - 1 ) nx = x & mask ny = y & mask region = ( nx << 24 ) | ( ny << 16 ) | ( level << 16 ) | ( 1 << bit ) return region | Get the region word for the given chip co - ordinates . |
50,655 | def compress_flood_fill_regions ( targets ) : t = RegionCoreTree ( ) for ( x , y ) , cores in iteritems ( targets ) : for p in cores : t . add_core ( x , y , p ) return sorted ( t . get_regions_and_coremasks ( ) ) | Generate a reduced set of flood fill parameters . |
50,656 | def get_regions_and_coremasks ( self ) : region_code = ( ( self . base_x << 24 ) | ( self . base_y << 16 ) | ( self . level << 16 ) ) subregions_cores = collections . defaultdict ( lambda : 0x0 ) for core , subregions in enumerate ( self . locally_selected ) : if subregions : subregions_cores [ subregions ] |= 1 << cor... | Generate a set of ordered paired region and core mask representations . |
50,657 | def add_core ( self , x , y , p ) : if ( ( p < 0 or p > 17 ) or ( x < self . base_x or x >= self . base_x + self . scale ) or ( y < self . base_y or y >= self . base_y + self . scale ) ) : raise ValueError ( ( x , y , p ) ) subregion = ( ( x >> self . shift ) & 0x3 ) + 4 * ( ( y >> self . shift ) & 0x3 ) if self . leve... | Add a new core to the region tree . |
50,658 | def send_scp ( self , * args , ** kwargs ) : cabinet = kwargs . pop ( "cabinet" ) frame = kwargs . pop ( "frame" ) board = kwargs . pop ( "board" ) return self . _send_scp ( cabinet , frame , board , * args , ** kwargs ) | Transmit an SCP Packet to a specific board . |
50,659 | def get_software_version ( self , cabinet , frame , board ) : sver = self . _send_scp ( cabinet , frame , board , SCPCommands . sver ) code_block = ( sver . arg1 >> 24 ) & 0xff frame_id = ( sver . arg1 >> 16 ) & 0xff can_id = ( sver . arg1 >> 8 ) & 0xff board_id = sver . arg1 & 0xff buffer_size = ( sver . arg2 & 0xffff... | Get the software version for a given BMP . |
50,660 | def set_power ( self , state , cabinet , frame , board , delay = 0.0 , post_power_on_delay = 5.0 ) : if isinstance ( board , int ) : boards = [ board ] else : boards = list ( board ) arg1 = int ( delay * 1000 ) << 16 | ( 1 if state else 0 ) arg2 = sum ( 1 << b for b in boards ) self . _send_scp ( cabinet , frame , 0 , ... | Control power to the SpiNNaker chips and FPGAs on a board . |
50,661 | def read_adc ( self , cabinet , frame , board ) : response = self . _send_scp ( cabinet , frame , board , SCPCommands . bmp_info , arg1 = BMPInfoType . adc , expected_args = 0 ) data = struct . unpack ( "<" "8H" "4h" "4h" "4h" "I" "I" , response . data ) return ADCInfo ( voltage_1_2c = data [ 1 ] * BMP_V_SCALE_2_5 , vo... | Read ADC data from the BMP including voltages and temperature . |
50,662 | def add_resources ( res_a , res_b ) : return { resource : value + res_b . get ( resource , 0 ) for resource , value in iteritems ( res_a ) } | Return the resources after adding res_b s resources to res_a . |
50,663 | def subtract_resources ( res_a , res_b ) : return { resource : value - res_b . get ( resource , 0 ) for resource , value in iteritems ( res_a ) } | Return the resources remaining after subtracting res_b s resources from res_a . |
50,664 | def resources_after_reservation ( res , constraint ) : res = res . copy ( ) res [ constraint . resource ] -= ( constraint . reservation . stop - constraint . reservation . start ) return res | Return the resources available after a specified ReserveResourceConstraint has been applied . |
50,665 | def apply_reserve_resource_constraint ( machine , constraint ) : if constraint . location is None : machine . chip_resources = resources_after_reservation ( machine . chip_resources , constraint ) if overallocated ( machine . chip_resources ) : raise InsufficientResourceError ( "Cannot meet {}" . format ( constraint ) ... | Apply the changes implied by a reserve resource constraint to a machine model . |
50,666 | def apply_same_chip_constraints ( vertices_resources , nets , constraints ) : vertices_resources = vertices_resources . copy ( ) nets = nets [ : ] constraints = constraints [ : ] substitutions = [ ] for same_chip_constraint in constraints : if not isinstance ( same_chip_constraint , SameChipConstraint ) : continue if l... | Modify a set of vertices_resources nets and constraints to account for all SameChipConstraints . |
50,667 | def join_resource_name ( self , v ) : d = self . dict d [ 'fragment' ] = [ v , None ] return MetapackResourceUrl ( downloader = self . _downloader , ** d ) | Return a MetapackResourceUrl that includes a reference to the resource . Returns a MetapackResourceUrl which will have a fragment |
50,668 | def search_json_indexed_directory ( directory ) : from metapack . index import SearchIndex , search_index_file idx = SearchIndex ( search_index_file ( ) ) def _search_function ( url ) : packages = idx . search ( url , format = 'issued' ) if not packages : return None package = packages . pop ( 0 ) try : resource_str = ... | Return a search function for searching a directory of packages which has an index . json file created by the mp install file command . |
50,669 | def search ( self ) : for cb in SearchUrl . search_callbacks : try : v = cb ( self ) if v is not None : return v except Exception as e : raise | Search for a url by returning the value from the first callback that returns a non - None value |
50,670 | def ensure_source_package_dir ( nb_path , pkg_name ) : pkg_path = join ( dirname ( nb_path ) , pkg_name ) makedirs ( join ( pkg_path , 'notebooks' ) , exist_ok = True ) makedirs ( join ( pkg_path , 'docs' ) , exist_ok = True ) return pkg_path | Ensure all of the important directories in a source package exist |
50,671 | def get_metatab_doc ( nb_path ) : from metatab . generate import CsvDataRowGenerator from metatab . rowgenerators import TextRowGenerator from metatab import MetatabDoc with open ( nb_path ) as f : nb = nbformat . reads ( f . read ( ) , as_version = 4 ) for cell in nb . cells : source = '' . join ( cell [ 'source' ] ) ... | Read a notebook and extract the metatab document . Only returns the first document |
50,672 | def process_schema ( doc , resource , df ) : from rowgenerators import SourceError from requests . exceptions import ConnectionError from metapack . cli . core import extract_path_name , alt_col_name , type_map from tableintuit import TypeIntuiter from rowgenerators . generator . python import PandasDataframeSource fro... | Add schema entiries to a metatab doc from a dataframe |
50,673 | def boot ( hostname , boot_port = consts . BOOT_PORT , scamp_binary = None , sark_struct = None , boot_delay = 0.05 , post_boot_delay = 2.0 , sv_overrides = dict ( ) , ** kwargs ) : scamp_binary = ( scamp_binary if scamp_binary is not None else pkg_resources . resource_filename ( "rig" , "boot/scamp.boot" ) ) sark_stru... | Boot a SpiNNaker machine of the given size . |
50,674 | def boot_packet ( sock , cmd , arg1 = 0 , arg2 = 0 , arg3 = 0 , data = b"" ) : PROTOCOL_VERSION = 1 header = struct . pack ( "!H4I" , PROTOCOL_VERSION , cmd , arg1 , arg2 , arg3 ) assert len ( data ) % 4 == 0 fdata = b"" while len ( data ) > 0 : word , data = ( data [ : 4 ] , data [ 4 : ] ) fdata += struct . pack ( "!I... | Create and transmit a packet to boot the machine . |
50,675 | def copy ( self ) : return Machine ( self . width , self . height , self . chip_resources , self . chip_resource_exceptions , self . dead_chips , self . dead_links ) | Produce a copy of this datastructure . |
50,676 | def iter_links ( self ) : for x in range ( self . width ) : for y in range ( self . height ) : for link in Links : if ( x , y , link ) in self : yield ( x , y , link ) | An iterator over the working links in the machine . |
50,677 | def has_wrap_around_links ( self , minimum_working = 0.9 ) : working = 0 for x in range ( self . width ) : if ( x , 0 , Links . south ) in self : working += 1 if ( x , self . height - 1 , Links . north ) in self : working += 1 if ( x , 0 , Links . south_west ) in self : working += 1 if ( x , self . height - 1 , Links .... | Test if a machine has wrap - around connections installed . |
50,678 | def update_resource_properties ( r , orig_columns = { } , force = False ) : added = [ ] schema_term = r . schema_term if not schema_term : warn ( "No schema term for " , r . name ) return rg = r . raw_row_generator upstream_columns = { e [ 'name' ] . lower ( ) if e [ 'name' ] else '' : e for e in r . columns ( ) or { }... | Get descriptions and other properties from this or upstream packages and add them to the schema . |
50,679 | def get_config ( ) : from os import environ from os . path import expanduser from pathlib import Path import yaml def pexp ( p ) : try : return Path ( p ) . expanduser ( ) except AttributeError : return Path ( expanduser ( p ) ) paths = [ environ . get ( "METAPACK_CONFIG" ) , '~/.metapack.yaml' , '/etc/metapack.yaml' ]... | Return a configuration dict |
50,680 | def find_csv_packages ( m , downloader ) : from metapack . package import CsvPackageBuilder pkg_dir = m . package_root name = m . doc . get_value ( 'Root.Name' ) package_path , cache_path = CsvPackageBuilder . make_package_path ( pkg_dir , name ) if package_path . exists ( ) : return open_package ( package_path , downl... | Locate the build CSV package which will have distributions if it was generated as and S3 package |
50,681 | def serialize_email_messages ( messages : List [ EmailMessage ] ) : return [ base64 . b64encode ( zlib . compress ( pickle . dumps ( m , protocol = 4 ) ) ) . decode ( ) for m in messages ] | Serialize EmailMessages to be passed as task argument . |
50,682 | def deserialize_email_messages ( messages : List [ str ] ) : return [ pickle . loads ( zlib . decompress ( base64 . b64decode ( m ) ) ) for m in messages ] | Deserialize EmailMessages passed as task argument . |
50,683 | def _estimate_count ( self ) : if self . estimate_z == 0 : self . estimate_z = ( 1.0 / self . nbr_bits ) self . estimate_z = min ( self . estimate_z , 0.999999 ) self . count = int ( - ( self . nbr_bits / self . nbr_slices ) * np . log ( 1 - self . estimate_z ) ) | Update the count number using the estimation of the unset ratio |
50,684 | def compute_refresh_time ( self ) : if self . z == 0 : self . z = 1E-10 s = float ( self . expiration ) * ( 1.0 / ( self . nbr_bits ) ) * ( 1.0 / ( self . counter_init - 1 + ( 1.0 / ( self . z * ( self . nbr_slices + 1 ) ) ) ) ) return s | Compute the refresh period for the given expiration delay |
50,685 | def allocate ( vertices_resources , nets , machine , constraints , placements ) : allocation = { } globally_reserved = defaultdict ( list ) locally_reserved = defaultdict ( lambda : defaultdict ( list ) ) alignments = defaultdict ( lambda : 1 ) for constraint in constraints : if isinstance ( constraint , ReserveResourc... | Allocate resources to vertices on cores arbitrarily using a simple greedy algorithm . |
50,686 | def create ( self , port , qos_policy ) : LOG . info ( "Setting QoS policy %(qos_policy)s on port %(port)s" , dict ( qos_policy = qos_policy , port = port ) ) policy_data = self . _get_policy_values ( qos_policy ) self . _utils . set_port_qos_rule ( port [ "port_id" ] , policy_data ) | Apply QoS rules on port for the first time . |
50,687 | def delete ( self , port , qos_policy = None ) : LOG . info ( "Deleting QoS policy %(qos_policy)s on port %(port)s" , dict ( qos_policy = qos_policy , port = port ) ) self . _utils . remove_port_qos_rule ( port [ "port_id" ] ) | Remove QoS rules from port . |
50,688 | def task ( self , func : Optional [ Callable ] = None , name : Optional [ str ] = None , queue : Optional [ str ] = None , max_retries : Optional [ Number ] = None , periodicity : Optional [ timedelta ] = None ) : if func is None : return functools . partial ( self . task , name = name , queue = queue , max_retries = m... | Decorator to register a task function . |
50,689 | def add ( self , func : Callable , name : Optional [ str ] = None , queue : Optional [ str ] = None , max_retries : Optional [ Number ] = None , periodicity : Optional [ timedelta ] = None ) : if not name : raise ValueError ( 'Each Spinach task needs a name' ) if name in self . _tasks : raise ValueError ( 'A task named... | Register a task function . |
50,690 | def schedule ( self , task : Schedulable , * args , ** kwargs ) : self . _require_attached_tasks ( ) self . _spin . schedule ( task , * args , ** kwargs ) | Schedule a job to be executed as soon as possible . |
50,691 | def schedule ( self , task : Schedulable , * args , ** kwargs ) : at = datetime . now ( timezone . utc ) self . schedule_at ( task , at , * args , ** kwargs ) | Add a job to be executed ASAP to the batch . |
50,692 | def schedule_at ( self , task : Schedulable , at : datetime , * args , ** kwargs ) : self . jobs_to_create . append ( ( task , at , args , kwargs ) ) | Add a job to be executed in the future to the batch . |
50,693 | def _locate_file ( f , base_dir ) : if base_dir == None : return f file_name = os . path . join ( base_dir , f ) real = os . path . realpath ( file_name ) return real | Utility method for finding full path to a filename as string |
50,694 | def check_to_generate_or_run ( argv , sim ) : print_v ( "Checking arguments: %s to see whether anything should be run in simulation %s (net: %s)..." % ( argv , sim . id , sim . network ) ) if len ( argv ) == 1 : print_v ( "No arguments found. Currently supported export formats:" ) print_v ( " -nml | -nmlh5 | -jnml |... | Useful method for calling in main method after network and simulation are generated to handle some standard export options like - jnml - graph etc . |
50,695 | def connect_input ( self , name , wire ) : self . _inputs [ name ] = wire wire . sinks . append ( self ) | Connect the specified input to a wire . |
50,696 | def _write_config ( self , memory ) : memory . seek ( 0 ) memory . write ( struct . pack ( "<5I" , self . _simulator . length , self . _inputs [ "a" ] . routing_key if self . _inputs [ "a" ] is not None else 0xFFFFFFFF , self . _inputs [ "b" ] . routing_key if self . _inputs [ "b" ] is not None else 0xFFFFFFFF , self .... | Write the configuration for this gate to memory . |
50,697 | def connect_input ( self , wire ) : self . _input = wire wire . sinks . append ( self ) | Probe the specified wire . |
50,698 | def _write_config ( self , memory ) : memory . seek ( 0 ) memory . write ( struct . pack ( "<II" , self . _simulator . length , self . _input . routing_key if self . _input is not None else 0xFFFFFFFF ) ) | Write the configuration for this probe to memory . |
50,699 | def _read_results ( self , memory ) : memory . seek ( 8 ) bits = bitarray ( endian = "little" ) bits . frombytes ( memory . read ( ) ) self . recorded_data = bits . to01 ( ) | Read back the probed results . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.