output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def send_scp(self, *args, **kwargs):
"""Transmit an SCP Packet and return the response.
This function is a thin wrapper around
:py:meth:`rig.machine_control.scp_connection.SCPConnection.send_scp`.
This function will attempt to use the SCP connection nearest the
destination of t... | Write a Python 3 function for
transmitting an SCP Packet and return the response. | You are a Python code generator, capable of creating scripts from specifications. |
def _get_connection(self, x, y):
"""Get the appropriate connection for a chip."""
if (self._width is None or self._height is None or
self._root_chip is None):
return self.connections[None]
else:
# If possible, use the local Ethernet connected chip
... | Can you create a Python 3 function that
gets the appropriate connection for a chip. | As a Python code analyst, you investigate and solve complex coding mysteries |
Internal method to send an SCP packet. | How would you explain what the following Python 3 function does
def _send_scp(self, x, y, p, *args, **kwargs):
# Determine the size of packet we expect in return, this is usually the
# size that we are informed we should expect by SCAMP/SARK or else is
# the default.
if self._scp_data_le... | As a Python code analyst, you investigate and solve complex coding mysteries |
Boot a SpiNNaker machine from the Ethernet connected chip. | Can you generate a brief explanation for the following Python 3 code
def boot(self, width=None, height=None,
only_if_needed=True, check_booted=True, **boot_kwargs):
"""Boot a SpiNNaker machine.
The system will be booted from the Ethernet connected chip whose
hostname was given as t... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Discover all available Ethernet connections to a machine. | Can you generate a brief explanation for the following Python 3 code
def discover_connections(self, x=255, y=255):
working_chips = set(
(x, y)
for (x, y), route in iteritems(self.get_p2p_routing_table(x, y))
if route != consts.P2PTableEntry.none)
self._width = max(x f... | You are a Python code analyst, evaluating scripts for potential improvements. |
def application(self, app_id):
"""Update the context to use the given application ID and stop the
application when done.
For example::
with cn.application(54):
# All commands in this block will use app_id=54.
# On leaving the block `cn.send_signal("s... | Create a Python 3 function for
updating the context to use the given application ID and stop the application when done. | As a python code expert, you are capable of creating scripts from specifications. |
def get_software_version(self, x=255, y=255, processor=0):
"""Get the software version for a given SpiNNaker core.
Returns
-------
:py:class:`.CoreInfo`
Information about the software running on a core.
"""
sver = self._send_scp(x, y, processor, SCPCommands.s... | Write a Python 3 script to
get the software version for a given SpiNNaker core. | As a Python code composer, you craft elegant and concise scripts. |
def get_ip_address(self, x, y):
"""Get the IP address of a particular SpiNNaker chip's Ethernet link.
Returns
-------
str or None
The IPv4 address (as a string) of the chip's Ethernet link or None
if the chip does not have an Ethernet connection or the link is
... | How would you implement a function in Python 3 that
gets the IPv4 address of a particular SpiNNaker chip s Ethernet link. | You are a Python code generator, capable of creating scripts from specifications. |
Write a bytestring to an address in memory. | How would you explain what the following Python 3 function does
def write(self, address, data, x, y, p=0):
# Call the SCPConnection to perform the write on our behalf
connection = self._get_connection(x, y)
return connection.write(self.scp_data_length, self.scp_window_size,
... | As a Python code composer, you craft elegant and concise scripts. |
Read a bytestring from an address in memory. | Make a summary of the following Python 3 code
def read(self, address, length_bytes, x, y, p=0):
# Call the SCPConnection to perform the read on our behalf
connection = self._get_connection(x, y)
return connection.read(self.scp_data_length, self.scp_window_size,
x, ... | You are a Python code analyst, evaluating scripts for potential improvements. |
Write a bytestring to an address in memory on a neigbouring chip. | How would you explain what the following Python 3 function does
def write_across_link(self, address, data, x, y, link):
if address % 4:
raise ValueError("Addresses must be word-aligned.")
if len(data) % 4:
raise ValueError("Data must be a whole number of words.")
length_... | You are a Python code generator, capable of creating scripts from specifications. |
def read_across_link(self, address, length_bytes, x, y, link):
"""Read a bytestring from an address in memory on a neigbouring chip.
.. warning::
This function is intended for low-level debug use only and is not
optimised for performance nor intended for more general use.
... | Can you create a Python 3 function that
reads a bytestring from an address in memory on a neigbouring chip. | You are a Python code generator, capable of creating scripts from specifications. |
Read the value out of a struct field. | Given the following Python 3 function, write the documentation
def read_struct_field(self, struct_name, field_name, x, y, p=0):
# Look up the struct and field
field, address, pack_chars = \
self._get_struct_field_and_address(struct_name, field_name)
length = struct.calcsize(pack_char... | You are a Python code generator, capable of creating scripts from specifications. |
def write_struct_field(self, struct_name, field_name, values, x, y, p=0):
"""Write a value into a struct.
This method is particularly useful for writing values into the ``sv``
struct which contains some configuration data. See ``sark.h`` for
details.
Parameters
-------... | Write a Python 3 function for
writing a value into a struct field. | You are a Python code generator, capable of creating scripts from specifications. |
Get the field and address for a VCPU struct field. | How would you explain what the following Python 3 function does
def _get_vcpu_field_and_address(self, field_name, x, y, p):
vcpu_struct = self.structs[b"vcpu"]
field = vcpu_struct[six.b(field_name)]
address = (self.read_struct_field("sv", "vcpu_base", x, y) +
vcpu_struct.size ... | As a Python code composer, you craft elegant and concise scripts. |
Reads a value out of the VCPU struct for a specific core. | Given the following Python 3 function, write the documentation
def read_vcpu_struct_field(self, field_name, x, y, p):
# Get the base address of the VCPU struct for this chip, then advance
# to get the correct VCPU struct for the requested core.
field, address, pack_chars = \
self._ge... | You are a Python code generator, capable of creating scripts from specifications. |
Writes a value to the VCPU struct for a specific core. | How would you explain what the following Python 3 function does
def write_vcpu_struct_field(self, field_name, value, x, y, p):
field, address, pack_chars = \
self._get_vcpu_field_and_address(field_name, x, y, p)
# Pack the data
if b"s" in pack_chars:
data = struct.pack(p... | You are a Python code architect, reviewing and designing scalable and efficient code |
Get the status of a given core and the application executing on it. | Explain what the following Python 3 code does
def get_processor_status(self, p, x, y):
# Get the VCPU base
address = (self.read_struct_field("sv", "vcpu_base", x, y) +
self.structs[b"vcpu"].size * p)
# Get the VCPU data
data = self.read(address, self.structs[b"vcpu"].... | You are a Python code architect, reviewing and designing scalable and efficient code |
Read the messages from the IOBUF buffer on a specific core. | Here you have a function in Python 3, explain what it does
def get_iobuf(self, p, x, y):
return self.get_iobuf_bytes(p, x, y).decode("utf-8") | As a Python code analyst, you investigate and solve complex coding mysteries |
Read raw bytes into the IOBUF buffer on a specific core. | Explain what the following Python 3 code does
def get_iobuf_bytes(self, p, x, y):
# The IOBUF data is stored in a linked-list of blocks of memory in
# SDRAM. The size of each block is given in SV
iobuf_size = self.read_struct_field("sv", "iobuf_size", x, y)
# The first block in the list... | As a Python code composer, you craft elegant and concise scripts. |
def get_router_diagnostics(self, x, y):
"""Get the values of the router diagnostic counters.
Returns
-------
:py:class:`~.RouterDiagnostics`
Description of the state of the counters.
"""
# Read the block of memory
data = self.read(0xe1000300, 64, x=x,... | Write a Python 3 script to
return the values of the router diagnostic counters. | As a Python code composer, you craft elegant and concise scripts. |
Set the value of an IPTag. | Can you generate a brief explanation for the following Python 3 code
def iptag_set(self, iptag, addr, port, x, y):
# Format the IP address
ip_addr = struct.pack('!4B',
*map(int, socket.gethostbyname(addr).split('.')))
self._send_scp(x, y, 0, SCPCommands.iptag,
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Get the value of an IPTag. | Can you tell what is the following Python 3 function doing
def iptag_get(self, iptag, x, y):
ack = self._send_scp(x, y, 0, SCPCommands.iptag,
int(consts.IPTagCommands.get) << 16 | iptag, 1,
expected_args=0)
return IPTag.from_bytestring(ack.data) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def iptag_clear(self, iptag, x, y):
"""Clear an IPTag.
Parameters
----------
iptag : int
Index of the IPTag to clear.
"""
self._send_scp(x, y, 0, SCPCommands.iptag,
int(consts.IPTagCommands.clear) << 16 | iptag) | Write a Python 3 script for
clearing an IPTag. Parameters ---------- iptag : int Index of the IPTag to clear. | You are a Python code architect, reviewing and designing scalable and efficient code |
Set or toggle the state of an LED. | Given the following Python 3 function, write the documentation
def set_led(self, led, action=None, x=Required, y=Required):
if isinstance(led, int):
leds = [led]
else:
leds = led
arg1 = sum(LEDAction.from_bool(action) << (led * 2) for led in leds)
self._send_scp(x... | As a python code expert, you are capable of creating scripts from specifications. |
def fill(self, address, data, size, x, y, p):
"""Fill a region of memory with the specified byte.
Parameters
----------
data : int
Data with which to fill memory. If `address` and `size` are word
aligned then `data` is assumed to be a word; otherwise it is
... | Implement a Python 3 function for
filling a region of memory with the specified byte. | You are a Python code analyst, evaluating scripts for potential improvements. |
Allocate a block of SDRAM for an application. | Explain what the following Python 3 code does
def sdram_alloc(self, size, tag=0, x=Required, y=Required,
app_id=Required, clear=False):
"""Allocate a region of SDRAM for an application.
Requests SARK to allocate a block of SDRAM for an application and
raises a :py:exc:`.SpiN... | You are a Python code generator, capable of creating scripts from specifications. |
def sdram_alloc_as_filelike(self, size, tag=0, x=Required, y=Required,
app_id=Required, clear=False):
"""Like :py:meth:`.sdram_alloc` but returns a :py:class:`file-like
object <.MemoryIO>` which allows safe reading and writing to the block
that is allocated.
... | Write a Python 3 script to
like sdram_alloc but returns a File - like object which allows safe reading and writing to the block holding the memory. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Free an allocated block of memory in SDRAM. | How would you explain what the following Python 3 function does
def sdram_free(self, ptr, x=Required, y=Required):
self._send_scp(x, y, 0, SCPCommands.alloc_free,
consts.AllocOperations.free_sdram_by_ptr, ptr) | You are a Python code analyst, evaluating scripts for potential improvements. |
Get the next nearest neighbour ID. | Explain what the following Python 3 code does
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 | As a Python code translator, you convert algorithms and pseudocode into Python. |
Send a flood - fill start packet. | Can you tell what is the following Python 3 function doing
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
... | As a Python code composer, you craft elegant and concise scripts. |
def _send_ffcs(self, region, core_mask, fr):
"""Send a flood-fill core select packet.
This packet was added in a patched SC&MP 1.34*. Each packet includes a
region and a core mask; every core that is in the region ORs the core
mask with a mask it stores locally. On receiving a flood-fil... | Write a Python 3 script for
sending a flood - fill core select packet. | You are a Python code architect, reviewing and designing scalable and efficient code |
Send flood - fill data packets. | Make a summary of the following Python 3 code
def _send_ffd(self, pid, aplx_data, address):
block = 0
pos = 0
aplx_size = len(aplx_data)
while pos < aplx_size:
# Get the next block of data, send and progress the block
# counter and the address
data = ... | You are a Python code analyst, evaluating scripts for potential improvements. |
def _send_ffe(self, pid, app_id, app_flags, fr):
"""Send a flood-fill end packet.
The cores and regions that the application should be loaded to will
have been specified by a stream of flood-fill core select packets
(FFCS).
"""
arg1 = (NNCommands.flood_fill_end << 24) | ... | Implement a function in Python 3 to
send a flood - fill end packet. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def load_application(self, *args, **kwargs):
"""Load an application to a set of application cores.
This method guarantees that once it returns, all required cores will
have been loaded. If this is not possible after a small number of
attempts, a :py:exc:`.SpiNNakerLoadingError` will be ... | Can you write a function in Python 3 where it
loads an application into a set of cores. | You are a Python code architect, reviewing and designing scalable and efficient code |
def send_signal(self, signal, app_id):
"""Transmit a signal to applications.
.. warning::
In current implementations of SARK, signals are highly likely to
arrive but this is not guaranteed (especially when the system's
network is heavily utilised). Users should treat... | Create a Python 3 function for
transmitting a signal to applications. | As a Python code analyst, you investigate and solve complex coding mysteries |
def count_cores_in_state(self, state, app_id):
"""Count the number of cores in a given state.
.. warning::
In current implementations of SARK, signals (which are used to
determine the state of cores) are highly likely to arrive but this
is not guaranteed (especially ... | Implement a Python 3 function for
counting the number of cores in a given state. | You are a Python code architect, reviewing and designing scalable and efficient code |
def wait_for_cores_to_reach_state(self, state, count, app_id,
poll_interval=0.1, timeout=None):
"""Block until the specified number of cores reach the specified state.
This is a simple utility-wrapper around the
:py:meth:`.count_cores_in_state` method which... | How would you code a function in Python 3 to
block until the specified number of cores reach the specified state. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Allocate space for an load multicast routing tables. | How would you explain what the following Python 3 function does
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) | As a Python code analyst, you investigate and solve complex coding mysteries |
Load routing table entries into memory. | How would you explain what the following Python 3 function does
def load_routing_table_entries(self, entries, x, y, app_id):
count = len(entries)
# Try to allocate room for the entries
rv = self._send_scp(
x, y, 0, SCPCommands.alloc_free,
(app_id << 8) | consts.AllocOper... | As a python code expert, you are capable of creating scripts from specifications. |
def get_routing_table_entries(self, x, y):
"""Dump the multicast routing table of a given chip.
Returns
-------
[(:py:class:`~rig.routing_table.RoutingTableEntry`, app_id, core) \
or None, ...]
Ordered list of routing table entries with app_ids and
core... | Can you write a function in Python 3 where it
dumps the multicast routing table of a given chip. | As a Python code analyst, you investigate and solve complex coding mysteries |
Clears the routing table entries associated with a given application. | Given the following Python 3 function, write the documentation
def clear_routing_table_entries(self, x, y, app_id):
# Construct the arguments
arg1 = (app_id << 8) | consts.AllocOperations.free_rtr_by_app
self._send_scp(x, y, 0, SCPCommands.alloc_free, arg1, 0x1) | You are a Python code generator, capable of creating scripts from specifications. |
Dump the contents of a chip s P2P routing table. | Can you generate the documentation for the following Python 3 function
def get_p2p_routing_table(self, x, y):
table = {}
# Get the dimensions of the system
p2p_dims = self.read_struct_field("sv", "p2p_dims", x, y)
width = (p2p_dims >> 8) & 0xFF
height = (p2p_dims >> 0) & 0xFF
... | As a python code expert, you are capable of creating scripts from specifications. |
Get general information about the resources available on a chip. | Given the following Python 3 function, write the documentation
def get_chip_info(self, x, y):
info = self._send_scp(x, y, 0, SCPCommands.info, expected_args=3)
# Unpack values encoded in the argument fields
num_cores = info.arg1 & 0x1F
working_links = set(link for link in Links
... | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_system_info(self, x=255, y=255):
"""Discover the integrity and resource availability of a whole
SpiNNaker system.
This command performs :py:meth:`.get_chip_info` on all working chips in
the system returning an enhanced :py:class:`dict`
(:py:class:`.SystemInfo`) containin... | Create a Python 3 function to
discover the integrity and resource availability of a whole SpiNNaker system. This command performs :py:meth:`.get_chip_info` on all working chips in the system returning an enhanced :py:class:`dict` (:py:class:`.SystemInfo`) containing a look-up from chip coordinate to :py:class:`.ChipInf... | You are a Python code analyst, evaluating scripts for potential improvements. |
def ethernet_connected_chips(self):
"""Iterate over the coordinates of Ethernet connected chips.
Yields
------
((x, y), str)
The coordinate and IP address of each Ethernet connected chip in
the system.
"""
for xy, chip_info in six.iteritems(self):... | Can you implement a function in Python 3 that
iterates over the coordinates of Ethernet connected chips in the system. | You are a Python code generator, capable of creating scripts from specifications. |
Yields the coordinates of all dead chips. | Explain what the following Python 3 code does
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) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def links(self):
"""Generate the coordinates of all working links.
Yields
------
(x, y, :py:class:`rig.links.Links`)
A working link leaving a chip from the perspective of the chip. For
example ``(0, 0, Links.north)`` would be the link going north from
... | Can you write a function in Python 3 where it
generates the coordinates of all working links. | You are a Python code analyst, evaluating scripts for potential improvements. |
def dead_links(self):
"""Generate the coordinates of all dead links leaving working chips.
Any link leading to a dead chip will also be included in the list of
dead links. In non-torroidal SpiNNaker sysmtes (e.g. single SpiNN-5
boards), links on the periphery of the system will be marke... | Can you write a function in Python 3 where it
generates the coordinates of all dead links leaving working chips. | As a Python code analyst, you investigate and solve complex coding mysteries |
Yields the set of all cores in the system. | Can you tell what is the following Python 3 function doing
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) | As a Python code composer, you craft elegant and concise scripts. |
def read(self, n_bytes=-1):
"""Read a number of bytes from the memory.
.. note::
Reads beyond the specified memory range will be truncated.
.. note::
Produces a :py:exc:`.TruncationWarning` if fewer bytes are read
than requested. These warnings can be conver... | Can you create a Python 3 function that
reads a number of bytes from the SpiNNaker memory region. | As a Python code composer, you craft elegant and concise scripts. |
Writes the specified bytes to the memory. | Can you generate a brief explanation for the following Python 3 code
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), Tru... | You are a Python code analyst, evaluating scripts for potential improvements. |
def seek(self, n_bytes, from_what=os.SEEK_SET):
"""Seek to a new position in the memory region.
Parameters
----------
n_bytes : int
Number of bytes to seek.
from_what : int
As in the Python standard: `0` seeks from the start of the memory
regi... | Write a Python 3 script for
seeking to a new position in the memory region. | As a Python code analyst, you investigate and solve complex coding mysteries |
def free(self):
"""Free the memory referred to by the file-like, any subsequent
operations on this file-like or slices of it will fail.
"""
# Free the memory
self._machine_controller.sdram_free(self._start_address,
self._x, self._y)
... | How would you implement a function in Python 3 that
frees the memory referred to by the file - like. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _perform_read(self, addr, size):
"""Perform a read using the machine controller."""
return self._machine_controller.read(addr, size, self._x, self._y, 0) | Write a Python 3 script for
performing a read using the machine controller. | You are a Python code analyst, evaluating scripts for potential improvements. |
def _perform_write(self, addr, data):
"""Perform a write using the machine controller."""
return self._machine_controller.write(addr, data, self._x, self._y, 0) | Create a Python 3 function to
perform a write using the machine controller. | You are a Python code generator, capable of creating scripts from specifications. |
def _unpack_sdp_into_packet(packet, bytestring):
"""Unpack the SDP header from a bytestring into a packet.
Parameters
----------
packet : :py:class:`.SDPPacket`
Packet into which to store the unpacked header.
bytestring : bytes
Bytes from which to unpack the header data.
"""
... | Write a Python 3 script for
unpacking the SDP header from a bytestring into a packet. | You are a Python code architect, reviewing and designing scalable and efficient code |
Pack the data for the SCP packet. | Can you generate the documentation for the following Python 3 function
def packed_data(self):
# Pack the header
scp_header = struct.pack("<2H", self.cmd_rc, self.seq)
# Potential loop intentionally unrolled
if self.arg1 is not None:
scp_header += struct.pack('<I', self.arg1)... | As a Python code composer, you craft elegant and concise scripts. |
def hash64(key, seed):
"""
Wrapper around mmh3.hash64 to get us single 64-bit value.
This also does the extra work of ensuring that we always treat the
returned values as big-endian unsigned long, like smhasher used to
do.
"""
hash_val = mmh3.hash64(key, seed)[0]
return struct.unpack('>... | Write a Python 3 script for
wrapping around mmh3. hash64 to get us single 64 - bit value. | You are a Python code architect, reviewing and designing scalable and efficient code |
def generate_hashfunctions(nbr_bits, nbr_slices):
"""Generate a set of hash functions.
The core method is a 64-bit murmur3 hash which has a good distribution.
Multiple hashes can be generate using the previous hash value as a seed.
"""
def _make_hashfuncs(key):
if isinstance(key, text_type)... | Can you write a function in Python 3 where it
generates a set of hash functions. | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_context_arguments(self):
"""Return a dictionary containing the current context arguments."""
cargs = {}
for context in self.__context_stack:
cargs.update(context.context_arguments)
return cargs | Write a Python 3 script to
return a dictionary containing the current context arguments. | As a python code expert, you are capable of creating scripts from specifications. |
def minimise(routing_table, target_length):
"""Reduce the size of a routing table by merging together entries where
possible and by removing any remaining default routes.
.. warning::
The input routing table *must* also include entries which could be
removed and replaced by default routing... | Write a Python 3 function for
reducing the size of a routing table by merging together entries where possible and removing any remaining default routes. | You are a Python code architect, reviewing and designing scalable and efficient code |
Reduce the size of a routing table by merging together entries where possible. | Given the following Python 3 function, write the documentation
def ordered_covering(routing_table, target_length, aliases=dict(),
no_raise=False):
"""Reduce the size of a routing table by merging together entries where
possible.
.. warning::
The input routing table *must* also... | You are a Python code architect, reviewing and designing scalable and efficient code |
def _get_generality(key, mask):
"""Count the number of Xs in the key-mask pair.
For example, there are 32 Xs in ``0x00000000/0x00000000``::
>>> _get_generality(0x0, 0x0)
32
And no Xs in ``0xffffffff/0xffffffff``::
>>> _get_generality(0xffffffff, 0xffffffff)
0
"""
... | Can you create a Python 3 function that
counts the number of Xs in the key - mask pair. | You are a Python code generator, capable of creating scripts from specifications. |
def _get_best_merge(routing_table, aliases):
"""Inspect all possible merges for the routing table and return the merge
which would combine the greatest number of entries.
Returns
-------
:py:class:`~.Merge`
"""
# Create an empty merge to start with
best_merge = _Merge(routing_table)
... | Implement a function in Python 3 to
inspect all possible merges and return the best merge and the best goodness for the calling method. | As a Python code analyst, you investigate and solve complex coding mysteries |
def _get_all_merges(routing_table):
"""Get possible sets of entries to merge.
Yields
------
:py:class:`~.Merge`
"""
# Memorise entries that have been considered as part of a merge
considered_entries = set()
for i, entry in enumerate(routing_table):
# If we've already considered... | How would you code a function in Python 3 to
get all possible sets of entries to merge. | You are a Python code generator, capable of creating scripts from specifications. |
def _get_insertion_index(routing_table, generality):
"""Determine the index in the routing table where a new entry should be
inserted.
"""
# We insert before blocks of equivalent generality, so decrement the given
# generality.
generality -= 1
# Wrapper for _get_generality which accepts a r... | Implement a Python 3 function for
determining the index in the routing table where a new entry should be inserted. | As a Python code analyst, you investigate and solve complex coding mysteries |
Remove entries from a merge to generate a valid merge which may be
| Can you tell what is the following Python 3 function doing
def _refine_merge(merge, aliases, min_goodness):
# Perform the down-check
merge = _refine_downcheck(merge, aliases, min_goodness)
# If the merge is still sufficiently good then continue to refine it.
if merge.goodness > min_goodness:
# ... | As a Python code composer, you craft elegant and concise scripts. |
Remove any entries which would be covered by the merge and return a new merge. | Explain what the following Python 3 code does
def _refine_upcheck(merge, min_goodness):
# Remove any entries which would be covered by entries above the merge
# position.
changed = False
for i in sorted(merge.entries, reverse=True):
# Get all the entries that are between the entry we're looking ... | As a python code expert, you are capable of creating scripts from specifications. |
Return a new merge that can be used to reconstruct the merge. | Make a summary of the following Python 3 code
def _refine_downcheck(merge, aliases, min_goodness):
# Operation
# ---------
# While the merge is still better than `min_goodness` we determine which
# entries below it in the table it covers. For each of these covered
# entries we find which bits are Xs... | You are a Python code architect, reviewing and designing scalable and efficient code |
Get the keys and masks that would be covered by the given merge. | How would you explain what the following Python 3 function does
def _get_covered_keys_and_masks(merge, aliases):
# For every entry in the table below the insertion index see which keys
# and masks would overlap with the key and mask of the merged entry.
for entry in merge.routing_table[merge.insertion_index... | As a Python code composer, you craft elegant and concise scripts. |
def apply(self, aliases):
"""Apply the merge to the routing table it is defined against and get a
new routing table and alias dictionary.
Returns
-------
[:py:class:`~rig.routing_table.RoutingTableEntry`, ...]
A new routing table which may be minimised further.
... | Write a Python 3 script to
apply the merge to the routing table it is defined against and get a new routing table and aliases dictionary. | You are a Python code architect, reviewing and designing scalable and efficient code |
def find_packages(name, pkg_dir):
"""Locate pre-built packages in the _packages directory"""
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, pack... | Create a Python 3 function for
finding pre - built packages in the _packages directory. | As a Python code analyst, you investigate and solve complex coding mysteries |
Command line options for the new command | Given the following Python 3 function, write the documentation
def new_args(subparsers):
parser = subparsers.add_parser(
'new',
help='Create new Metatab packages',
description=new_args.__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.set_defaults(run_c... | You are a Python code analyst, evaluating scripts for potential improvements. |
def initialize_bitarray(self):
"""Initialize both bitarray.
This BF contain two bit arrays instead of single one like a plain BF. bitarray
is the main bit array where all the historical items are stored. It's the one
used for the membership query. The second one, current_day_bitarray is... | Write a Python 3 script for
initializing both bitarray and current_day_bitarray | As a Python code translator, you convert algorithms and pseudocode into Python. |
def initialize_period(self, period=None):
"""Initialize the period of BF.
:period: datetime.datetime for setting the period explicity.
"""
if not period:
self.current_period = dt.datetime.now()
else:
self.current_period = period
self.current_perio... | How would you code a function in Python 3 to
initialize the period of the current BF. | You are a Python code architect, reviewing and designing scalable and efficient code |
def warm(self, jittering_ratio=0.2):
"""Progressively load the previous snapshot during the day.
Loading all the snapshots at once can takes a substantial amount of time. This method, if called
periodically during the day will progressively load those snapshots one by one. Because many workers ... | How would you implement a function in Python 3 that
warms the previous snapshot during the day. | You are a Python code architect, reviewing and designing scalable and efficient code |
def restore_from_disk(self, clean_old_snapshot=False):
"""Restore the state of the BF using previous snapshots.
:clean_old_snapshot: Delete the old snapshot on the disk (period < current - expiration)
"""
base_filename = "%s/%s_%s_*.dat" % (self.snapshot_path, self.name, self.expiration... | Implement a function in Python 3 to
restore the state of the BF using previous snapshots. | As a python code expert, you are capable of creating scripts from specifications. |
def save_snaphot(self):
"""Save the current state of the current day bitarray on disk.
Save the internal representation (bitarray) into a binary file using this format:
filename : name_expiration_2013-01-01.dat
"""
filename = "%s/%s_%s_%s.dat" % (self.snapshot_path, self.nam... | Write a Python 3 script for
saving the current state of the current day bitarray on disk. | You are a Python code generator, capable of creating scripts from specifications. |
This function places vertices onto chips in the order specified by the argument. | Can you generate the documentation for the following Python 3 function
def place(vertices_resources, nets, machine, constraints,
vertex_order=None, chip_order=None):
"""Blindly places vertices in sequential order onto chips in the machine.
This algorithm sequentially places vertices onto chips in the... | As a Python code composer, you craft elegant and concise scripts. |
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={},
... | Can you implement a function in Python 3 that
wraps for core place - and - route tasks for common case. | As a Python code analyst, you investigate and solve complex coding mysteries |
A function that creates a common case with the common case. | Can you generate the documentation for the following Python 3 function
def wrapper(vertices_resources, vertices_applications,
nets, net_keys,
machine, constraints=[],
reserve_monitor=True, align_sdram=True,
place=default_place, place_kwargs={},
allocate=defaul... | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns the region word for the given chip co -ordinates. | Make a summary of the following Python 3 code
def get_region_for_chip(x, y, level=3):
shift = 6 - 2*level
bit = ((x >> shift) & 3) + 4*((y >> shift) & 3) # bit in bits 15:0 to set
mask = 0xffff ^ ((4 << shift) - 1) # in {0xfffc, 0xfff0, 0xffc0, 0xff00}
nx = x & mask # The mask guarantees that bits ... | As a python code expert, you are capable of creating scripts from specifications. |
def compress_flood_fill_regions(targets):
"""Generate a reduced set of flood fill parameters.
Parameters
----------
targets : {(x, y) : set([c, ...]), ...}
For each used chip a set of core numbers onto which an application
should be loaded. E.g., the output of
:py:func:`~rig.pl... | Write a Python 3 script for
generating a reduced set of flood fill parameters. | As a python code expert, you are capable of creating scripts from specifications. |
Generate a set of ordered paired region and core masks. | Can you generate the documentation for the following Python 3 function
def get_regions_and_coremasks(self):
region_code = ((self.base_x << 24) | (self.base_y << 16) |
(self.level << 16))
# Generate core masks for any regions which are selected at this level
# Create a map... | As a Python code composer, you craft elegant and concise scripts. |
Add a new core to the region tree. | Given the following Python 3 function, write the documentation
def add_core(self, x, y, p):
# Check that the co-ordinate is contained in this region
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.... | As a python code expert, you are capable of creating scripts from specifications. |
Transmit an SCP Packet to a specific board. | How would you explain what the following Python 3 function does
def send_scp(self, *args, **kwargs):
# Retrieve contextual arguments from the keyword arguments. The
# context system ensures that these values are present.
cabinet = kwargs.pop("cabinet")
frame = kwargs.pop("frame")
... | As a Python code analyst, you investigate and solve complex coding mysteries |
Send an SCP packet to the specified board. | Make a summary of the following Python 3 code
def _send_scp(self, cabinet, frame, board, *args, **kwargs):
# Find the connection which best matches the specified coordinates,
# preferring direct connections to a board when available.
connection = self.connections.get((cabinet, frame, board), Non... | As a python code expert, you are capable of creating scripts from specifications. |
Get the software version for a given BMP. | Given the following Python 3 function, write the documentation
def get_software_version(self, cabinet, frame, board):
sver = self._send_scp(cabinet, frame, board, SCPCommands.sver)
# Format the result
# arg1
code_block = (sver.arg1 >> 24) & 0xff
frame_id = (sver.arg1 >> 16) & 0x... | You are a Python code analyst, evaluating scripts for potential improvements. |
def set_power(self, state, cabinet, frame, board,
delay=0.0, post_power_on_delay=5.0):
"""Control power to the SpiNNaker chips and FPGAs on a board.
Returns
-------
state : bool
True for power on, False for power off.
board : int or iterable
... | Can you implement a function in Python 3 that
sets the power of the specified Chip. | As a python code expert, you are capable of creating scripts from specifications. |
def set_led(self, led, action=None,
cabinet=Required, frame=Required, board=Required):
"""Set or toggle the state of an LED.
.. note::
At the time of writing, LED 7 is only set by the BMP on start-up to
indicate that the watchdog timer reset the board. After this... | Implement a Python 3 function for
setting or toggle the state of an LED. | As a python code expert, you are capable of creating scripts from specifications. |
def read_fpga_reg(self, fpga_num, addr, cabinet, frame, board):
"""Read the value of an FPGA (SPI) register.
See the SpI/O project's spinnaker_fpga design's `README`_ for a listing
of FPGA registers. The SpI/O project can be found on GitHub at:
https://github.com/SpiNNakerManchester/spi... | How would you implement a function in Python 3 that
reads the value of an FPGA register. | You are a Python code analyst, evaluating scripts for potential improvements. |
Write the value to a 32 - bit register in the specified board. | Here you have a function in Python 3, explain what it does
def write_fpga_reg(self, fpga_num, addr, value, cabinet, frame, board):
arg1 = addr & (~0x3)
arg2 = 4 # Write a 32-bit value
arg3 = fpga_num
self._send_scp(cabinet, frame, board, SCPCommands.link_write,
ar... | As a python code expert, you are capable of creating scripts from specifications. |
def read_adc(self, cabinet, frame, board):
"""Read ADC data from the BMP including voltages and temperature.
Returns
-------
:py:class:`.ADCInfo`
"""
response = self._send_scp(cabinet, frame, board, SCPCommands.bmp_info,
arg1=BMPInfoType... | Implement a Python 3 function for
reading the ADC data from the BMP including voltages and temperature. | You are a Python code analyst, evaluating scripts for potential improvements. |
Return the resources after adding res_b s resources to res_a. | Can you generate a brief explanation for the following Python 3 code
def add_resources(res_a, res_b):
return {resource: value + res_b.get(resource, 0)
for resource, value in iteritems(res_a)} | You are a Python code analyst, evaluating scripts for potential improvements. |
def subtract_resources(res_a, res_b):
"""Return the resources remaining after subtracting res_b's resources from
res_a.
Parameters
----------
res_a : dict
Dictionary `{resource: value, ...}`.
res_b : dict
Dictionary `{resource: value, ...}`. Must be a (non-strict) subset of
... | Write a Python 3 script for
returning the resources remaining after subtracting res_b s resources from res_a. | As a Python code analyst, you investigate and solve complex coding mysteries |
def resources_after_reservation(res, constraint):
"""Return the resources available after a specified
ReserveResourceConstraint has been applied.
Note: the caller is responsible for testing that the constraint is
applicable to the core whose resources are being constrained.
Note: this function doe... | Write a Python 3 script for
returning the resources available after a specified reserve resource constraint has been applied. | As a python code expert, you are capable of creating scripts from specifications. |
def apply_reserve_resource_constraint(machine, constraint):
"""Apply the changes implied by a reserve resource constraint to a
machine model."""
if constraint.location is None:
# Compensate for globally reserved resources
machine.chip_resources \
= resources_after_reservation(
... | How would you implement a function in Python 3 that
applies the changes implied by a reserve resource constraint to a single resource in the specified machine model. | You are a Python code analyst, evaluating scripts for potential improvements. |
Modify a set of vertices_resources nets and constraints to account for all SameChipConstraints. | How would you explain what the following Python 3 function does
def apply_same_chip_constraints(vertices_resources, nets, constraints):
# Make a copy of the basic structures to be modified by this function
vertices_resources = vertices_resources.copy()
nets = nets[:]
constraints = constraints[:]
su... | As a Python code analyst, you investigate and solve complex coding mysteries |
def finalise_same_chip_constraints(substitutions, placements):
"""Given a set of placements containing the supplied
:py:class:`MergedVertex`, remove the merged vertices replacing them with
their constituent vertices (changing the placements inplace).
"""
for merged_vertex in reversed(substitutions):... | Write a Python 3 function for
giving a set of merged vertices remove them and add them to the supplied placements. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.