output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Clear the locator cache for a given login and tableName.
Can you generate a brief explanation for the following Python 3 code def clearLocatorCache(self, login, tableName): self.send_clearLocatorCache(login, tableName) self.recv_clearLocatorCache()
You are a Python code analyst, evaluating scripts for potential improvements.
This method is used to clone a table.
Can you generate the documentation for the following Python 3 function def cloneTable(self, login, tableName, newTableName, flush, propertiesToSet, propertiesToExclude): self.send_cloneTable(login, tableName, newTableName, flush, propertiesToSet, propertiesToExclude) self.recv_cloneTable()
As a python code expert, you are capable of creating scripts from specifications.
Cancels compaction of a table.
How would you explain what the following Python 3 function does def cancelCompaction(self, login, tableName): self.send_cancelCompaction(login, tableName) self.recv_cancelCompaction()
You are a Python code architect, reviewing and designing scalable and efficient code
Delete a table from the server.
Explain what the following Python 3 code does def deleteTable(self, login, tableName): self.send_deleteTable(login, tableName) self.recv_deleteTable()
As a python code expert, you are capable of creating scripts from specifications.
Delete rows from a table.
Make a summary of the following Python 3 code def deleteRows(self, login, tableName, startRow, endRow): self.send_deleteRows(login, tableName, startRow, endRow) self.recv_deleteRows()
As a Python code translator, you convert algorithms and pseudocode into Python.
This method is used to flush a table from the server.
Can you generate the documentation for the following Python 3 function def flushTable(self, login, tableName, startRow, endRow, wait): self.send_flushTable(login, tableName, startRow, endRow, wait) self.recv_flushTable()
As a Python code translator, you convert algorithms and pseudocode into Python.
def getLocalityGroups(self, login, tableName): """ Parameters: - login - tableName """ self.send_getLocalityGroups(login, tableName) return self.recv_getLocalityGroups()
Write a Python 3 script for returning a list of all locality groups for a given login and tableName.
As a Python code translator, you convert algorithms and pseudocode into Python.
This method returns the maximum row number in a table.
Here you have a function in Python 3, explain what it does def getMaxRow(self, login, tableName, auths, startRow, startInclusive, endRow, endInclusive): self.send_getMaxRow(login, tableName, auths, startRow, startInclusive, endRow, endInclusive) return self.recv_getMaxRow()
As a Python code analyst, you investigate and solve complex coding mysteries
def getTableProperties(self, login, tableName): """ Parameters: - login - tableName """ self.send_getTableProperties(login, tableName) return self.recv_getTableProperties()
How would you code a function in Python 3 to return the properties of a table.
As a Python code analyst, you investigate and solve complex coding mysteries
def getSplits(self, login, tableName, maxSplits): """ Parameters: - login - tableName - maxSplits """ self.send_getSplits(login, tableName, maxSplits) return self.recv_getSplits()
How would you implement a function in Python 3 that returns a list of splits for a given login and tableName.
As a Python code analyst, you investigate and solve complex coding mysteries
This method is used to send and receive import directory command to the server.
Can you generate a brief explanation for the following Python 3 code def importDirectory(self, login, tableName, importDir, failureDir, setTime): self.send_importDirectory(login, tableName, importDir, failureDir, setTime) self.recv_importDirectory()
As a Python code composer, you craft elegant and concise scripts.
This function is used to send and receive a table import request to the server.
Given the following Python 3 function, write the documentation def importTable(self, login, tableName, importDir): self.send_importTable(login, tableName, importDir) self.recv_importTable()
You are a Python code analyst, evaluating scripts for potential improvements.
This method is used to list the iterators for a given login and tableName.
Can you generate the documentation for the following Python 3 function def listIterators(self, login, tableName): self.send_listIterators(login, tableName) return self.recv_listIterators()
You are a Python code analyst, evaluating scripts for potential improvements.
This method is used to list the constraints of a table.
Can you tell what is the following Python 3 function doing def listConstraints(self, login, tableName): self.send_listConstraints(login, tableName) return self.recv_listConstraints()
You are a Python code analyst, evaluating scripts for potential improvements.
Sends an offline table request to the server.
Make a summary of the following Python 3 code def offlineTable(self, login, tableName): self.send_offlineTable(login, tableName) self.recv_offlineTable()
You are a Python code generator, capable of creating scripts from specifications.
This function is used to send an online table to the server.
Can you generate a brief explanation for the following Python 3 code def onlineTable(self, login, tableName): self.send_onlineTable(login, tableName) self.recv_onlineTable()
As a python code expert, you are capable of creating scripts from specifications.
Removes a constraint from the table with login login.
Given the following Python 3 function, write the documentation def removeConstraint(self, login, tableName, constraint): self.send_removeConstraint(login, tableName, constraint) self.recv_removeConstraint()
You are a Python code generator, capable of creating scripts from specifications.
Remove an iterator from the table.
Can you generate a brief explanation for the following Python 3 code def removeIterator(self, login, tableName, iterName, scopes): self.send_removeIterator(login, tableName, iterName, scopes) self.recv_removeIterator()
You are a Python code architect, reviewing and designing scalable and efficient code
def removeTableProperty(self, login, tableName, property): """ Parameters: - login - tableName - property """ self.send_removeTableProperty(login, tableName, property) self.recv_removeTableProperty()
Write a Python 3 function that can remove a property from a table
As a Python code composer, you craft elegant and concise scripts.
This function is used to rename a table in a loginspace.
Can you generate the documentation for the following Python 3 function def renameTable(self, login, oldTableName, newTableName): self.send_renameTable(login, oldTableName, newTableName) self.recv_renameTable()
You are a Python code architect, reviewing and designing scalable and efficient code
This method is used to set the locality of the table.
Explain what the following Python 3 code does def setLocalityGroups(self, login, tableName, groups): self.send_setLocalityGroups(login, tableName, groups) self.recv_setLocalityGroups()
You are a Python code architect, reviewing and designing scalable and efficient code
Sets the value of a table property.
Can you generate the documentation for the following Python 3 function def setTableProperty(self, login, tableName, property, value): self.send_setTableProperty(login, tableName, property, value) self.recv_setTableProperty()
As a Python code translator, you convert algorithms and pseudocode into Python.
def pingTabletServer(self, login, tserver): """ Parameters: - login - tserver """ self.send_pingTabletServer(login, tserver) self.recv_pingTabletServer()
Create a Python 3 function to ping a tablet server.
You are a Python code architect, reviewing and designing scalable and efficient code
Returns the active scans for the specified login and tserver.
Can you tell what is the following Python 3 function doing def getActiveScans(self, login, tserver): self.send_getActiveScans(login, tserver) return self.recv_getActiveScans()
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns the active compactions for the given login and tserver.
How would you explain what the following Python 3 function does def getActiveCompactions(self, login, tserver): self.send_getActiveCompactions(login, tserver) return self.recv_getActiveCompactions()
As a Python code composer, you craft elegant and concise scripts.
def removeProperty(self, login, property): """ Parameters: - login - property """ self.send_removeProperty(login, property) self.recv_removeProperty()
Write a Python 3 function for removing a property from the specified login.
You are a Python code analyst, evaluating scripts for potential improvements.
Set the value of a property on a node.
Can you tell what is the following Python 3 function doing def setProperty(self, login, property, value): self.send_setProperty(login, property, value) self.recv_setProperty()
You are a Python code architect, reviewing and designing scalable and efficient code
Parameters: - login - user - properties
Given the following Python 3 function, write the documentation def authenticateUser(self, login, user, properties): self.send_authenticateUser(login, user, properties) return self.recv_authenticateUser()
As a python code expert, you are capable of creating scripts from specifications.
def changeUserAuthorizations(self, login, user, authorizations): """ Parameters: - login - user - authorizations """ self.send_changeUserAuthorizations(login, user, authorizations) self.recv_changeUserAuthorizations()
How would you code a function in Python 3 to change the authorizations for a user.
As a python code expert, you are capable of creating scripts from specifications.
Change the password of a local user.
Can you generate a brief explanation for the following Python 3 code def changeLocalUserPassword(self, login, user, password): self.send_changeLocalUserPassword(login, user, password) self.recv_changeLocalUserPassword()
As a Python code translator, you convert algorithms and pseudocode into Python.
Drop a local user from the specified login.
Here you have a function in Python 3, explain what it does def dropLocalUser(self, login, user): self.send_dropLocalUser(login, user) self.recv_dropLocalUser()
As a python code expert, you are capable of creating scripts from specifications.
Returns a list of authorizations for a user.
Explain what the following Python 3 code does def getUserAuthorizations(self, login, user): self.send_getUserAuthorizations(login, user) return self.recv_getUserAuthorizations()
As a python code expert, you are capable of creating scripts from specifications.
def grantSystemPermission(self, login, user, perm): """ Parameters: - login - user - perm """ self.send_grantSystemPermission(login, user, perm) self.recv_grantSystemPermission()
Can you create a Python 3 function that grants system permission to a user
As a python code expert, you are capable of creating scripts from specifications.
def grantTablePermission(self, login, user, table, perm): """ Parameters: - login - user - table - perm """ self.send_grantTablePermission(login, user, table, perm) self.recv_grantTablePermission()
Write a Python 3 function for granting a permission to a table.
You are a Python code generator, capable of creating scripts from specifications.
def hasSystemPermission(self, login, user, perm): """ Parameters: - login - user - perm """ self.send_hasSystemPermission(login, user, perm) return self.recv_hasSystemPermission()
Create a Python 3 function to return true if the user has permission for login.
You are a Python code generator, capable of creating scripts from specifications.
Returns True if the user has permission for the table perm.
Given the following Python 3 function, write the documentation def hasTablePermission(self, login, user, table, perm): self.send_hasTablePermission(login, user, table, perm) return self.recv_hasTablePermission()
As a Python code analyst, you investigate and solve complex coding mysteries
revokes a system permission for a given login user
Can you tell what is the following Python 3 function doing def revokeSystemPermission(self, login, user, perm): self.send_revokeSystemPermission(login, user, perm) self.recv_revokeSystemPermission()
You are a Python code architect, reviewing and designing scalable and efficient code
def revokeTablePermission(self, login, user, table, perm): """ Parameters: - login - user - table - perm """ self.send_revokeTablePermission(login, user, table, perm) self.recv_revokeTablePermission()
Write a Python 3 function that can revoke a permission from a table
As a Python code translator, you convert algorithms and pseudocode into Python.
Create a batch scanner for the specified login and tableName.
Explain what the following Python 3 code does def createBatchScanner(self, login, tableName, options): self.send_createBatchScanner(login, tableName, options) return self.recv_createBatchScanner()
You are a Python code analyst, evaluating scripts for potential improvements.
def createScanner(self, login, tableName, options): """ Parameters: - login - tableName - options """ self.send_createScanner(login, tableName, options) return self.recv_createScanner()
Can you write a function in Python 3 where it creates a new scanner for the specified login and tableName.
As a Python code translator, you convert algorithms and pseudocode into Python.
This method sends the next k - element to the specified scanner and returns the k - element.
Can you generate a brief explanation for the following Python 3 code def nextK(self, scanner, k): self.send_nextK(scanner, k) return self.recv_nextK()
As a python code expert, you are capable of creating scripts from specifications.
Returns the next following element in a node.
Explain what the following Python 3 code does def getFollowing(self, key, part): self.send_getFollowing(key, part) return self.recv_getFollowing()
You are a Python code architect, reviewing and designing scalable and efficient code
def set_relay_on(self): """Turn the relay on.""" if not self.get_relay_state(): try: request = requests.get( '{}/relay'.format(self.resource), params={'state': '1'}, timeout=self.timeout) if request.status_code == 200: ...
Implement a function in Python 3 to turn the relay on.
As a Python code translator, you convert algorithms and pseudocode into Python.
def set_relay_off(self): """Turn the relay off.""" if self.get_relay_state(): try: request = requests.get( '{}/relay'.format(self.resource), params={'state': '0'}, timeout=self.timeout) if request.status_code == 200: ...
Can you implement a function in Python 3 that turns the relay off.
You are a Python code architect, reviewing and designing scalable and efficient code
Get the relay state.
Can you generate a brief explanation for the following Python 3 code def get_relay_state(self): self.get_status() try: self.state = self.data['relay'] except TypeError: self.state = False return bool(self.state)
As a Python code translator, you convert algorithms and pseudocode into Python.
Get current power consumption in mWh.
Can you generate a brief explanation for the following Python 3 code def get_consumption(self): self.get_status() try: self.consumption = self.data['power'] except TypeError: self.consumption = 0 return self.consumption
As a Python code translator, you convert algorithms and pseudocode into Python.
def get_temperature(self): """Get current temperature in celsius.""" try: request = requests.get( '{}/temp'.format(self.resource), timeout=self.timeout, allow_redirects=False) self.temperature = request.json()['compensated'] return self.temperature ...
Create a Python 3 function for getting current temperature in celsius.
As a python code expert, you are capable of creating scripts from specifications.
Convert a 1 - gene chromosome into an integer and calculate its fitness value by checking it against each required factor and checking it against each required factor.
Explain what the following Python 3 code does def eval_fitness(self, chromosome): score = 0 number = self.translator.translate_gene(chromosome.genes[0]) for factor in self.factors: if number % factor == 0: score += 1 else: score -= 1 ...
As a python code expert, you are capable of creating scripts from specifications.
Get the details from the bulb.
Make a summary of the following Python 3 code def get_status(self): try: request = requests.get( '{}/{}/'.format(self.resource, URI), timeout=self.timeout) raw_data = request.json() # Doesn't always work !!!!! #self._mac = next(iter(self.raw_data))...
As a Python code translator, you convert algorithms and pseudocode into Python.
def get_bulb_state(self): """Get the relay state.""" self.get_status() try: self.state = self.data['on'] except TypeError: self.state = False return bool(self.state)
Create a Python 3 function to get the relay state.
You are a Python code architect, reviewing and designing scalable and efficient code
Get the current firmware version.
Can you tell what is the following Python 3 function doing def get_firmware(self): self.get_status() try: self.firmware = self.data['fw_version'] except TypeError: self.firmware = 'Unknown' return self.firmware
You are a Python code generator, capable of creating scripts from specifications.
def get_transition_time(self): """Get the transition time in ms.""" self.get_status() try: self.transition_time = self.data['ramp'] except TypeError: self.transition_time = 0 return self.transition_time
Write a Python 3 script for getting the transition time in ms.
As a python code expert, you are capable of creating scripts from specifications.
Turn the bulb on with the given values as HSV.
Explain what the following Python 3 code does def set_color_hsv(self, hue, saturation, value): try: data = "action=on&color={};{};{}".format(hue, saturation, value) request = requests.post( '{}/{}/{}'.format(self.resource, URI, self._mac), data=data, timeo...
As a Python code translator, you convert algorithms and pseudocode into Python.
def set_rainbow(self, duration): """Turn the bulb on and create a rainbow.""" for i in range(0, 359): self.set_color_hsv(i, 100, 100) time.sleep(duration/359)
Write a Python 3 function for turning the bulb on and create a rainbow.
You are a Python code generator, capable of creating scripts from specifications.
def set_sunrise(self, duration): """Turn the bulb on and create a sunrise.""" self.set_transition_time(duration/100) for i in range(0, duration): try: data = "action=on&color=3;{}".format(i) request = requests.post( '{}/{}/{}'.forma...
How would you implement a function in Python 3 that turns the bulb on and create a sunrise.
You are a Python code generator, capable of creating scripts from specifications.
def set_flashing(self, duration, hsv1, hsv2): """Turn the bulb on, flashing with two colors.""" self.set_transition_time(100) for step in range(0, int(duration/2)): self.set_color_hsv(hsv1[0], hsv1[1], hsv1[2]) time.sleep(1) self.set_color_hsv(hsv2[0], hsv2[1]...
Create a Python 3 function for turning the bulb on flashing with two colors.
You are a Python code generator, capable of creating scripts from specifications.
def set_off(self): """Turn the bulb off.""" try: request = requests.post( '{}/{}/{}/'.format(self.resource, URI, self._mac), data={'action': 'off'}, timeout=self.timeout) if request.status_code == 200: pass except requests.e...
Can you create a Python 3 function that turns the bulb off.
You are a Python code analyst, evaluating scripts for potential improvements.
Translate all the genes in a chromosome into translation products
Given the following Python 3 function, write the documentation def translate_chromosome(self, chromosome): assert isinstance(chromosome, Chromosome) return [self.translate_gene(g) for g in chromosome]
As a Python code analyst, you investigate and solve complex coding mysteries
Translate a gene with binary DNA into a base - 10 floating point real number.
Given the following Python 3 function, write the documentation def translate_gene(self, gene): if self.signed: sign = 1 if gene.dna[0] == '0' else -1 base_start_idx = 1 else: sign = 1 base_start_idx = 0 base = sign * int(gene.dna[base_start_idx:ba...
You are a Python code architect, reviewing and designing scalable and efficient code
def load_clients(self, path=None, apis=[]): """Generate client libraries for the given apis, without starting an api server""" if not path: raise Exception("Missing path to api swagger files") if type(apis) is not list: raise Exception("'apis' should be a list o...
Write a Python 3 script for loading all the client libraries for the given apis.
You are a Python code architect, reviewing and designing scalable and efficient code
def load_apis(self, path, ignore=[], include_crash_api=False): """Load all swagger files found at the given path, except those whose names are in the 'ignore' list""" if not path: raise Exception("Missing path to api swagger files") if type(ignore) is not list: ...
Implement a function in Python 3 to load all apis under the given path.
As a python code expert, you are capable of creating scripts from specifications.
Publish all loaded apis on under the uri path by redirecting to petstore. swagger. io
Make a summary of the following Python 3 code def publish_apis(self, path='doc'): assert path if not self.apis: raise Exception("You must call .load_apis() before .publish_apis()") # Infer the live host url from pym-config.yaml proto = 'http' if hasattr(get_config(...
You are a Python code generator, capable of creating scripts from specifications.
def start(self, serve=[]): """Load all apis, either as local apis served by the flask app, or as remote apis to be called from whithin the app's endpoints, then start the app server""" # Check arguments if type(serve) is str: serve = [serve] elif type(serve) ...
Can you create a Python 3 function that starts the app server.
You are a Python code generator, capable of creating scripts from specifications.
def add_error(name=None, code=None, status=None): """Create a new Exception class""" if not name or not status or not code: raise Exception("Can't create Exception class %s: you must set both name, status and code" % name) myexception = type(name, (PyMacaronException, ), {"code": code, "status": sta...
Write a Python 3 script for creating a new exception class with the given name and code and status.
As a python code expert, you are capable of creating scripts from specifications.
Take an Error model and return it as a Flask response
Explain what the following Python 3 code does def responsify(error): assert str(type(error).__name__) == 'Error' if error.error in code_to_class: e = code_to_class[error.error](error.error_description) if error.error_id: e.error_id = error.error_id if error.user_message: ...
As a Python code composer, you craft elegant and concise scripts.
True if o is an error model or a flask Response
Can you generate the documentation for the following Python 3 function def is_error(o): if hasattr(o, 'error') and hasattr(o, 'error_description') and hasattr(o, 'status'): return True return False
You are a Python code analyst, evaluating scripts for potential improvements.
def format_error(e): """Take an exception caught within pymacaron_core and turn it into a bravado-core Error instance """ if isinstance(e, PyMacaronException): return e.to_model() if isinstance(e, PyMacaronCoreException) and e.__class__.__name__ == 'ValidationError': return Validat...
Can you implement a function in Python 3 that takes an exception caught within pymacaron_core and turn it into abravado - core Error instance
As a python code expert, you are capable of creating scripts from specifications.
Take a bravado - core Error model and raise it as an exception
Make a summary of the following Python 3 code def raise_error(e): code = e.error if code in code_to_class: raise code_to_class[code](e.error_description) else: raise InternalServerError(e.error_description)
You are a Python code analyst, evaluating scripts for potential improvements.
Return a Flask reply object describing this error
How would you explain what the following Python 3 function does def http_reply(self): data = { 'status': self.status, 'error': self.code.upper(), 'error_description': str(self) } if self.error_caught: data['error_caught'] = pformat(self.error_caug...
You are a Python code generator, capable of creating scripts from specifications.
Return a bravado - core Error instance
Here you have a function in Python 3, explain what it does def to_model(self): e = ApiPool().current_server_api.model.Error( status=self.status, error=self.code.upper(), error_description=str(self), ) if self.error_id: e.error_id = self.error_id ...
As a Python code analyst, you investigate and solve complex coding mysteries
Compute the fitness - weighted cumulative probabilities for a set of chromosomes.
Make a summary of the following Python 3 code def compute_fitness_cdf(chromosomes, ga): ga.sort(chromosomes) fitness = [ga.eval_fitness(c) for c in chromosomes] min_fit = min(fitness) fit_range = max(fitness) - min_fit if fit_range == 0: # all chromosomes have equal chance of being...
As a Python code composer, you craft elegant and concise scripts.
Select a random element from a sequence given a cumulative probabilities of selection.
Here you have a function in Python 3, explain what it does def weighted_choice(seq, cdf): assert len(seq) == len(cdf) rand = random.random() for i, e in enumerate(seq): cp = cdf[i] assert 0 <= cp <= 1 if rand < cp: return e
You are a Python code architect, reviewing and designing scalable and efficient code
def _list(self, path, dim_key=None, **kwargs): """Get a list of metrics.""" url_str = self.base_url + path if dim_key and dim_key in kwargs: dim_str = self.get_dimensions_url_string(kwargs[dim_key]) kwargs[dim_key] = dim_str if kwargs: url_str += '?%s...
Implement a function in Python 3 to get a list of metrics.
You are a Python code generator, capable of creating scripts from specifications.
def mapstr_to_list(mapstr): """ Convert an ASCII map string with rows to a list of strings, 1 string per row. """ maplist = [] with StringIO(mapstr) as infile: for row in infile: maplist.append(row.strip()) return maplist
Implement a function in Python 3 to convert an ASCII map string with rows to a list of strings 1 string per row.
As a python code expert, you are capable of creating scripts from specifications.
def sprinkler_reaches_cell(x, y, sx, sy, r): """ Return whether a cell is within the radius of the sprinkler. x: column index of cell y: row index of cell sx: column index of sprinkler sy: row index of sprinkler r: sprinkler radius """ dx = sx - x dy = sy - y return mat...
Create a Python 3 function for returning whether a cell is within the radius of the sprinkler.
You are a Python code analyst, evaluating scripts for potential improvements.
def eval_fitness(self, chromosome): """ Return the number of plants reached by the sprinkler. Returns a large penalty for sprinkler locations outside the map. """ # convert DNA to represented sprinkler coordinates sx, sy = self.translator.translate_chromosome(chromosome)...
Create a Python 3 function for evaluating the fitness of a sprinkler.
As a Python code translator, you convert algorithms and pseudocode into Python.
def map_sprinkler(self, sx, sy, watered_crop='^', watered_field='_', dry_field=' ', dry_crop='x'): """ Return a version of the ASCII map showing reached crop cells. """ # convert strings (rows) to lists of characters for easier map editing maplist = [list(s) for s in self.maplist...
Write a Python 3 function for returning a string of the ASCII map showing reached crop cells.
You are a Python code analyst, evaluating scripts for potential improvements.
def get_fitness(self, chromosome): """ Get the fitness score for a chromosome, using the cached value if available. """ fitness = self.fitness_cache.get(chromosome.dna) if fitness is None: fitness = self.eval_fitness(chromosome) self.fitness_cache[chromosome.dna] = fitne...
Can you create a Python 3 function that gets the fitness score for a given chromosome.
You are a Python code architect, reviewing and designing scalable and efficient code
Simulate competition and survival of the current generation.
Can you generate the documentation for the following Python 3 function def compete(self, chromosomes): # update overall fitness for this run self.sort(chromosomes) min_fit = self.get_fitness(chromosomes[0]) max_fit = self.get_fitness(chromosomes[-1]) if min_fit < self.mi...
As a Python code composer, you craft elegant and concise scripts.
def reproduce(self, survivors, p_crossover, two_point_crossover=False, target_size=None): """ Reproduces the population from a pool of surviving chromosomes until a target population size is met. Offspring are created by selecting a survivor. Survivors with higher fitness have a ...
Create a Python 3 function to reproduce the population from a pool of surviving chromosomes and a set of crossover events.
You are a Python code architect, reviewing and designing scalable and efficient code
def mutate(self, chromosomes, p_mutate): """ Call every chromosome's ``mutate`` method. p_mutate: probability of mutation in [0, 1] """ assert 0 <= p_mutate <= 1 for chromosome in chromosomes: chromosome.mutate(p_mutate)
Write a Python 3 script to call every chromosome s mutate method.
You are a Python code generator, capable of creating scripts from specifications.
Run a standard genetic algorithm simulation for a set of generations
How would you explain what the following Python 3 function does def run(self, generations, p_mutate, p_crossover, elitist=True, two_point_crossover=False, refresh_after=None, quit_after=None): """ Run a standard genetic algorithm simulation for a set number of generations (iterations...
As a Python code composer, you craft elegant and concise scripts.
def create_random(cls, gene_length, n=1, gene_class=BinaryGene): """ Create 1 or more chromosomes with randomly generated DNA. gene_length: int (or sequence of ints) describing gene DNA length n: number of chromosomes to create (default=1); returns a list if n>1, else a single chromos...
How would you implement a function in Python 3 that creates 1 or more chromosomes with randomly generated DNA.
As a Python code translator, you convert algorithms and pseudocode into Python.
def dna(self, dna): """ Replace this chromosome's DNA with new DNA of equal length, assigning the new DNA to the chromosome's genes sequentially. For example, if a chromosome contains these genes... 1. 100100 2. 011011 ...and the new DNA...
Write a Python 3 function for replacing this chromosome s DNA with new DNA of equal length and assign the new DNA to the genes sequentially.
You are a Python code generator, capable of creating scripts from specifications.
Exchange the DNA with another chromosome at one or two common points.
Can you generate a brief explanation for the following Python 3 code def crossover(self, chromosome, point1, point2=None): assert self.length == chromosome.length if point2 is None: new_dna = self.dna[:point1] + chromosome.dna[point1:] other_new_dna = chromosome.dna[:point1] + s...
You are a Python code generator, capable of creating scripts from specifications.
Mutate all genes in this chromosome for the given probability.
How would you explain what the following Python 3 function does def mutate(self, p_mutate): assert 0 <= p_mutate <= 1 for gene in self.genes: gene.mutate(p_mutate)
You are a Python code analyst, evaluating scripts for potential improvements.
def copy(self): """ Return a new instance of this chromosome by copying its genes. """ genes = [g.copy() for g in self.genes] return type(self)(genes)
Implement a Python 3 function for returning a new instance of this chromosome by copying its genes.
As a Python code composer, you craft elegant and concise scripts.
Assert that every DNA choice is represented by exactly one gene.
Given the following Python 3 function, write the documentation def check_genes(self): gene_dna_set = set([g.dna for g in self.genes]) assert gene_dna_set == self.dna_choices_set
As a Python code translator, you convert algorithms and pseudocode into Python.
Format a crash report and send it somewhere relevant.
Explain what the following Python 3 code does def report_error(title=None, data={}, caught=None, is_fatal=False): # Don't report errors if NO_ERROR_REPORTING set to 1 (set by run_acceptance_tests) if os.environ.get('DO_REPORT_ERROR', None): # Force error reporting pass elif os.environ.get('...
You are a Python code generator, capable of creating scripts from specifications.
Populate the error report with the generic stats from the request
Make a summary of the following Python 3 code def populate_error_report(data): # Did pymacaron_core set a call_id and call_path? call_id, call_path = '', '' if hasattr(stack.top, 'call_id'): call_id = stack.top.call_id if hasattr(stack.top, 'call_path'): call_path = stack.top.call_path ...
As a Python code analyst, you investigate and solve complex coding mysteries
def generate_crash_handler_decorator(error_decorator=None): """Return the crash_handler to pass to pymacaron_core, with optional error decoration""" def crash_handler(f): """Return a decorator that reports failed api calls via the error_reporter, for use on every server endpoint""" @wr...
Can you create a Python 3 function that returns a function that returns a function that will be called when a crash occurs.
As a Python code analyst, you investigate and solve complex coding mysteries
Parses the response and returns the JSON object. Handles all errors.
Here you have a function in Python 3, explain what it does def get_json_results(self, response): ''' Parses the request result and returns the JSON object. Handles all errors. ''' try: # return the proper JSON object, or error code if request didn't go through. se...
You are a Python code architect, reviewing and designing scalable and efficient code
def search_all(self, quota=50, format='json'): ''' Returns a single list containing up to 'limit' Result objects Will keep requesting until quota is met Will also truncate extra results to return exactly the given quota ''' quota_left = quota results = [] ...
Write a Python 3 function that can search all the available resource types for all available resources.
You are a Python code architect, reviewing and designing scalable and efficient code
Reformat parameters into dict of format expected by the API.
Make a summary of the following Python 3 code def format_parameters(params): '''Reformat parameters into dict of format expected by the API.''' if not params: return {} # expect multiple invocations of --parameters but fall back # to ; delimited if only one --parameters is specified if len...
As a Python code analyst, you investigate and solve complex coding mysteries
def delete(self, **kwargs): """Delete a specific alarm.""" url_str = self.base_url + '/%s' % kwargs['alarm_id'] resp = self.client.delete(url_str) return resp
How would you implement a function in Python 3 that deletes a specific alarm.
You are a Python code architect, reviewing and designing scalable and efficient code
def do_version(): """Return version details of the running server api""" v = ApiPool.ping.model.Version( name=ApiPool().current_server_name, version=ApiPool().current_server_api.get_version(), container=get_container_version(), ) log.info("/version: " + pprint.pformat(v)) ret...
Write a Python 3 function for returning version details of the running server api
You are a Python code analyst, evaluating scripts for potential improvements.
Create metric from raw json body.
Given the following Python 3 function, write the documentation def do_metric_create_raw(mc, args): '''Create metric from raw json body.''' try: mc.metrics.create(**args.jsonbody) except (osc_exc.ClientException, k_exc.HttpError) as he: raise osc_exc.CommandError('%s\n%s' % (he.message, he.de...
You are a Python code analyst, evaluating scripts for potential improvements.
def do_metric_name_list(mc, args): '''List names of metrics.''' fields = {} if args.dimensions: fields['dimensions'] = utils.format_dimensions_query(args.dimensions) if args.limit: fields['limit'] = args.limit if args.offset: fields['offset'] = args.offset if args.tenant_...
How would you code a function in Python 3 to list names of metrics.
As a Python code composer, you craft elegant and concise scripts.
def do_metric_list(mc, args): '''List metrics for this tenant.''' fields = {} if args.name: fields['name'] = args.name if args.dimensions: fields['dimensions'] = utils.format_dimensions_query(args.dimensions) if args.limit: fields['limit'] = args.limit if args.offset: ...
How would you code a function in Python 3 to list metrics for this tenant.
You are a Python code architect, reviewing and designing scalable and efficient code
def do_dimension_name_list(mc, args): '''List names of metric dimensions.''' fields = {} if args.metric_name: fields['metric_name'] = args.metric_name if args.limit: fields['limit'] = args.limit if args.offset: fields['offset'] = args.offset if args.tenant_id: fie...
Implement a function in Python 3 to list names of metric dimensions.
As a Python code composer, you craft elegant and concise scripts.