output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Stop working on the queue and die if there is no pending request.
Can you generate the documentation for the following Python 3 function def finish_and_die(self): self.logstate('finish_and_die') self.stop_working_on_queue() if self.jobphase != 'pending_request': self.stopFactory()
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns a numeric value that determines this node s score for adding a new connection to a node.
Can you tell what is the following Python 3 function doing def add_connection_score(self, node): # TODO: this should ideally take node history into account conntime = node.seconds_until_connect_ok() if conntime > 0: self.log("not considering %r for new connection; has %r left on " ...
You are a Python code generator, capable of creating scripts from specifications.
def adjustPoolSize(self, newsize): """ Change the target pool size. If we have too many connections already, ask some to finish what they're doing and die (preferring to kill connections to the node that already has the most connections). If we have too few, create more. ...
Write a Python 3 function that can adjust the target pool size.
You are a Python code analyst, evaluating scripts for potential improvements.
Fill the pool with connections as necessary to meet the target pool size.
Explain what the following Python 3 code does def fill_pool(self): time_since_last_called = self.fill_pool_throttle if self.fill_pool_last_called is not None: time_since_last_called = time() - self.fill_pool_last_called need = self.target_pool_size - self.num_connectors() if...
As a python code expert, you are capable of creating scripts from specifications.
Push a request to the front of the queue and add it to the pending list.
Make a summary of the following Python 3 code def resubmit(self, req, keyspace, req_d, retries): self.log('resubmitting %s request' % (req.method,)) self.pushRequest_really(req, keyspace, req_d, retries) try: self.request_queue.pending.remove((req, keyspace, req_d, retries)) ...
As a Python code translator, you convert algorithms and pseudocode into Python.
Set the keyspace for this cluster and return a Deferred that will fire once the connection is made to that keyspace.
Can you tell what is the following Python 3 function doing def set_keyspace(self, keyspace): # push a real set_keyspace on some (any) connection; the idea is that # if it succeeds there, it is likely to succeed everywhere, and vice # versa. don't bother waiting for all connections to change- s...
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns a CassandraClient instance which uses this CassandraClusterPool by way of a CassandraKeyspaceConnection.
How would you explain what the following Python 3 function does def keyspaceConnection(self, keyspace, consistency=ConsistencyLevel.ONE): conn = CassandraKeyspaceConnection(self, keyspace) return CassandraClient(conn, consistency=consistency)
You are a Python code analyst, evaluating scripts for potential improvements.
def split_by_commas(maybe_s: str) -> Tuple[str, ...]: """Split a string by commas, but allow escaped commas. - If maybe_s is falsey, returns an empty tuple - Ignore backslashed commas """ if not maybe_s: return () parts: List[str] = [] split_by_backslash = maybe_s.split(r'\,') fo...
How would you code a function in Python 3 to split a string by commas but allow escaped commas.
You are a Python code analyst, evaluating scripts for potential improvements.
Send login request and return a Deferred that resolves with the sequence id.
Can you generate a brief explanation for the following Python 3 code def login(self, auth_request): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_login(auth_request) return d
As a Python code analyst, you investigate and solve complex coding mysteries
def set_keyspace(self, keyspace): """ Parameters: - keyspace """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_set_keyspace(keyspace) return d
Can you implement a function in Python 3 that sets the keyspace for the next iteration
As a Python code translator, you convert algorithms and pseudocode into Python.
Get the Column or SuperColumn at the given column_path.
Explain what the following Python 3 code does def get(self, key, column_path, consistency_level): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_get(key, column_path, consistency_level) return d
You are a Python code architect, reviewing and designing scalable and efficient code
Get the list of columns contained by column_parent that match the given SlicePredicate.
Explain what the following Python 3 code does def get_slice(self, key, column_parent, predicate, consistency_level): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_get_slice(key, column_parent, predicate, consistency_level) return d
You are a Python code analyst, evaluating scripts for potential improvements.
returns the number of columns matching predicate for a particular key column_parent and optionally supercolumn
Given the following Python 3 function, write the documentation def get_count(self, key, column_parent, predicate, consistency_level): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_get_count(key, column_parent, predicate, consistency_level) return d
You are a Python code architect, reviewing and designing scalable and efficient code
def multiget_slice(self, keys, column_parent, predicate, consistency_level): """ Performs a get_slice for column_parent and predicate for the given keys in parallel. Parameters: - keys - column_parent - predicate - consistency_level """ self._seqid += 1 d = self._reqs[self._...
Can you create a Python 3 function that performs a get_slice for column_parent and predicate for the given keys in parallel. Parameters: - keys - column_parent - predicate - consistency_level
You are a Python code generator, capable of creating scripts from specifications.
This method is used to get the count of the given list of keys in a given column parent and predicate.
Can you tell what is the following Python 3 function doing def multiget_count(self, keys, column_parent, predicate, consistency_level): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_multiget_count(keys, column_parent, predicate, consistency_level) return d
As a Python code translator, you convert algorithms and pseudocode into Python.
def get_range_slices(self, column_parent, predicate, range, consistency_level): """ returns a subset of columns for a contiguous range of keys. Parameters: - column_parent - predicate - range - consistency_level """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferr...
How would you code a function in Python 3 to return a subset of columns for a contiguous range of keys
You are a Python code analyst, evaluating scripts for potential improvements.
def get_paged_slice(self, column_family, range, start_column, consistency_level): """ returns a range of columns, wrapping to the next rows if necessary to collect max_results. Parameters: - column_family - range - start_column - consistency_level """ self._seqid += 1 d = se...
Implement a function in Python 3 to return a range of columns wrapping to the next rows if necessary to collect max_results
As a Python code analyst, you investigate and solve complex coding mysteries
def get_indexed_slices(self, column_parent, index_clause, column_predicate, consistency_level): """ Returns the subset of columns specified in SlicePredicate for the rows matching the IndexClause @deprecated use get_range_slices instead with range.row_filter specified Parameters: - column_parent ...
How would you code a function in Python 3 to return the subset of columns specified in SlicePredicate for the rows matching the IndexClause
You are a Python code analyst, evaluating scripts for potential improvements.
Insert a Column at the given column_parent. column_family and optional column_parent. super_column. Returns a Deferred that fires when the insert completes.
Can you generate a brief explanation for the following Python 3 code def insert(self, key, column_parent, column, consistency_level): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_insert(key, column_parent, column, consistency_level) return d
As a Python code translator, you convert algorithms and pseudocode into Python.
def add(self, key, column_parent, column, consistency_level): """ Increment or decrement a counter. Parameters: - key - column_parent - column - consistency_level """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_add(key, column_parent, column...
Write a Python 3 script for adding a new value to the sequence number.
As a Python code composer, you craft elegant and concise scripts.
Remove data from the specified key at the given timestamp.
Make a summary of the following Python 3 code def remove(self, key, column_path, timestamp, consistency_level): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_remove(key, column_path, timestamp, consistency_level) return d
You are a Python code analyst, evaluating scripts for potential improvements.
def remove_counter(self, key, path, consistency_level): """ Remove a counter at the specified location. Note that counters have limited support for deletes: if you remove a counter, you must wait to issue any following update until the delete has reached all the nodes and all of them have been fully com...
Implement a Python 3 function for removing a counter at the specified location.
As a Python code composer, you craft elegant and concise scripts.
def batch_mutate(self, mutation_map, consistency_level): """ Mutate many columns or super columns for many row keys. See also: Mutation. mutation_map maps key to column family to a list of Mutation objects to take place at that scope. * Parameters: - mutation_map - consistency_level ...
Can you create a Python 3 function that mutates many columns or super columns for many row keys.
You are a Python code generator, capable of creating scripts from specifications.
def truncate(self, cfname): """ Truncate will mark and entire column family as deleted. From the user's perspective a successful call to truncate will result complete data deletion from cfname. Internally, however, disk space will not be immediatily released, as with all deletes in cassandra, this one ...
How would you code a function in Python 3 to truncate the column family with the given name.
You are a Python code architect, reviewing and designing scalable and efficient code
returns a list of hosts that are connected to each schema version present in the cluster
Can you generate the documentation for the following Python 3 function def describe_schema_versions(self, ): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_schema_versions() return d
You are a Python code architect, reviewing and designing scalable and efficient code
returns a list of the defined keyspaces in this cluster
Given the following Python 3 function, write the documentation def describe_keyspaces(self, ): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_keyspaces() return d
You are a Python code architect, reviewing and designing scalable and efficient code
get the cluster name
Can you generate a brief explanation for the following Python 3 code def describe_cluster_name(self, ): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_cluster_name() return d
You are a Python code analyst, evaluating scripts for potential improvements.
def describe_version(self, ): """ get the thrift api version """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_version() return d
Create a Python 3 function to get the thrift api version
As a Python code composer, you craft elegant and concise scripts.
def describe_ring(self, keyspace): """ get the token ring: a map of ranges to host addresses, represented as a set of TokenRange instead of a map from range to list of endpoints, because you can't use Thrift structs as map keys: https://issues.apache.org/jira/browse/THRIFT-162 for the same ...
Can you create a Python 3 function that gets the token ring
As a Python code analyst, you investigate and solve complex coding mysteries
get the mapping between token and node
Explain what the following Python 3 code does def describe_token_map(self, ): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_token_map() return d
You are a Python code analyst, evaluating scripts for potential improvements.
returns the partitioner used by this cluster
Given the following Python 3 function, write the documentation def describe_partitioner(self, ): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_partitioner() return d
As a Python code analyst, you investigate and solve complex coding mysteries
def describe_snitch(self, ): """ returns the snitch used by this cluster """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_snitch() return d
Can you implement a function in Python 3 that returns the snitch used by this cluster
You are a Python code analyst, evaluating scripts for potential improvements.
describe specified keyspace Parameters: - keyspace
Can you generate a brief explanation for the following Python 3 code def describe_keyspace(self, keyspace): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_keyspace(keyspace) return d
You are a Python code generator, capable of creating scripts from specifications.
describe splits of a CF
How would you explain what the following Python 3 function does def describe_splits(self, cfName, start_token, end_token, keys_per_split): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_splits(cfName, start_token, end_token, keys_per_split) return d
As a Python code translator, you convert algorithms and pseudocode into Python.
def trace_next_query(self, ): """ Enables tracing for the next query in this connection and returns the UUID for that trace session The next query will be traced idependently of trace probability and the returned UUID can be used to query the trace keyspace """ self._seqid += 1 d = self._reqs[se...
Create a Python 3 function to return the UUID for the next trace query in this connection
As a python code expert, you are capable of creating scripts from specifications.
This method returns a Deferred that fires when the list of keys_per_split tokens are found in the split list.
Can you generate a brief explanation for the following Python 3 code def describe_splits_ex(self, cfName, start_token, end_token, keys_per_split): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_describe_splits_ex(cfName, start_token, end_token, keys_per_split) return d
You are a Python code architect, reviewing and designing scalable and efficient code
def system_add_column_family(self, cf_def): """ adds a column family. returns the new schema id. Parameters: - cf_def """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_system_add_column_family(cf_def) return d
Implement a function in Python 3 to add a column family to the current schema id. Returns the new schema id.
As a Python code translator, you convert algorithms and pseudocode into Python.
def system_drop_column_family(self, column_family): """ drops a column family. returns the new schema id. Parameters: - column_family """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_system_drop_column_family(column_family) return d
Can you create a Python 3 function that drops a column family. Returns the new schema id.
You are a Python code generator, capable of creating scripts from specifications.
def system_add_keyspace(self, ks_def): """ adds a keyspace and any column families that are part of it. returns the new schema id. Parameters: - ks_def """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_system_add_keyspace(ks_def) return d
Write a Python 3 script to add a keyspace and any column families that are part of it. returns the new schema id.
As a Python code composer, you craft elegant and concise scripts.
def system_drop_keyspace(self, keyspace): """ drops a keyspace and any column families that are part of it. returns the new schema id. Parameters: - keyspace """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_system_drop_keyspace(keyspace) return d
Write a Python 3 script to drop a keyspace and any column families that are part of it
You are a Python code generator, capable of creating scripts from specifications.
def system_update_keyspace(self, ks_def): """ updates properties of a keyspace. returns the new schema id. Parameters: - ks_def """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_system_update_keyspace(ks_def) return d
Can you write a function in Python 3 where it updates properties of a keyspace returns the new schema id
As a python code expert, you are capable of creating scripts from specifications.
updates properties of a column family returns the new schema id.
Here you have a function in Python 3, explain what it does def system_update_column_family(self, cf_def): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_system_update_column_family(cf_def) return d
You are a Python code analyst, evaluating scripts for potential improvements.
def execute_cql_query(self, query, compression): """ Executes a CQL (Cassandra Query Language) statement and returns a CqlResult containing the results. Parameters: - query - compression """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_execute_cql_...
Write a Python 3 script for executing a CQL query and returns a Deferred that resolves with the result.
You are a Python code generator, capable of creating scripts from specifications.
Execute a CQL query and return a Deferred that resolves when the result is received.
Here you have a function in Python 3, explain what it does def execute_cql3_query(self, query, compression, consistency): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_execute_cql3_query(query, compression, consistency) return d
As a python code expert, you are capable of creating scripts from specifications.
def prepare_cql_query(self, query, compression): """ Prepare a CQL (Cassandra Query Language) statement by compiling and returning - the type of CQL statement - an id token of the compiled CQL stored on the server side. - a count of the discovered bound markers in the statement Parameters: ...
Implement a function in Python 3 to prepare a CQL query by compiling and returning a CQL statement
As a Python code composer, you craft elegant and concise scripts.
Prepares a CQL query and returns a Deferred that resolves when the query completes.
Can you tell what is the following Python 3 function doing def prepare_cql3_query(self, query, compression): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_prepare_cql3_query(query, compression) return d
As a python code expert, you are capable of creating scripts from specifications.
def execute_prepared_cql_query(self, itemId, values): """ Executes a prepared CQL (Cassandra Query Language) statement by passing an id token and a list of variables to bind and returns a CqlResult containing the results. Parameters: - itemId - values """ self._seqid += 1 d = sel...
How would you code a function in Python 3 to execute a prepared CQL query by passing an id token and a list of variables to bind and returns a CqlResult containing the results.
As a Python code translator, you convert algorithms and pseudocode into Python.
Execute a prepared CQL query.
Here you have a function in Python 3, explain what it does def execute_prepared_cql3_query(self, itemId, values, consistency): self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_execute_prepared_cql3_query(itemId, values, consistency) return d
You are a Python code architect, reviewing and designing scalable and efficient code
def set_cql_version(self, version): """ @deprecated This is now a no-op. Please use the CQL3 specific methods instead. Parameters: - version """ self._seqid += 1 d = self._reqs[self._seqid] = defer.Deferred() self.send_set_cql_version(version) return d
Can you write a function in Python 3 where it sets the CQL version of the current node.
As a Python code analyst, you investigate and solve complex coding mysteries
Returns a new linear solver.
Explain what the following Python 3 code does def new_linsolver(name,prop): if name == 'mumps': return LinSolverMUMPS(prop) elif name == 'superlu': return LinSolverSUPERLU(prop) elif name == 'umfpack': return LinSolverUMFPACK(prop) elif name == 'default': try: ...
You are a Python code analyst, evaluating scripts for potential improvements.
def cast_problem(problem): """ Casts problem object with known interface as OptProblem. Parameters ---------- problem : Object """ # Optproblem if isinstance(problem,OptProblem): return problem # Other else: # Type Base if (not hasattr(...
Write a Python 3 script to cast a problem object with known interface as OptProblem.
You are a Python code analyst, evaluating scripts for potential improvements.
def create_problem_from_type_base(problem): """ Creates OptProblem from type-base problem. Parameters ---------- problem : Object """ p = OptProblem() # Init attributes p.phi = problem.phi p.gphi = problem.gphi p.Hphi = problem.Hphi p.A = problem.A p.b = problem....
Can you implement a function in Python 3 that creates OptProblem from type - base problem.
As a python code expert, you are capable of creating scripts from specifications.
Creates OptProblem from type - A problem.
Explain what the following Python 3 code does def create_problem_from_type_A(problem): p = OptProblem() nx = problem.get_num_primal_variables() nz = problem.G.shape[0] p.phi = problem.phi p.gphi = np.hstack((problem.gphi,np.zeros(nz))) p.Hphi = coo_matrix((problem.Hphi.data,(problem.H...
As a Python code composer, you craft elegant and concise scripts.
def recover_dual_variables(self,lam,nu,mu,pi): """ Recovers dual variables for original problem. Parameters ---------- lam : ndarray nu : ndarray mu : ndarray pi : ndarray """ return lam,nu,mu,pi
Can you write a function in Python 3 where it recovers dual variables for original problem.
You are a Python code analyst, evaluating scripts for potential improvements.
Gets the number of primal variables in the current object.
Can you generate a brief explanation for the following Python 3 code def get_num_primal_variables(self): if self.x is not None: return self.x.size if self.gphi is not None: return self.gphi.size if self.Hphi is not None: return self.Hphi.shape[0] if s...
As a Python code composer, you craft elegant and concise scripts.
def get_results(self): """ Gets results. Returns ------- results : dictionary """ return {'status': self.status, 'error_msg': self.error_msg, 'k': self.k, 'x': self.x, 'lam': self.lam*self.obj_sca, ...
Create a Python 3 function for getting the results of the .
You are a Python code analyst, evaluating scripts for potential improvements.
def line_search(self,x,p,F,GradF,func,smax=np.inf,maxiter=40): """ Finds steplength along search direction p that satisfies the strong Wolfe conditions. Parameters ---------- x : current point (ndarray) p : search direction (ndarray) F : function...
Write a Python 3 script for finding steplength along search direction p that satisfies the strong Wolfe conditions. Parameters ---------- x : current point (ndarray) p : search direction (ndarray) F : function value at `x` (float) GradF : gradient of function at `x` (ndarray) func : function of `x` that returns functio...
You are a Python code architect, reviewing and designing scalable and efficient code
Resets the internal state of the object to its initial state.
Can you generate a brief explanation for the following Python 3 code def reset(self): self.k = 0. self.x = np.zeros(0) self.lam = np.zeros(0) self.nu = np.zeros(0) self.mu = np.zeros(0) self.pi = np.zeros(0) self.status = self.STATUS_UNKNOWN self....
You are a Python code generator, capable of creating scripts from specifications.
def set_parameters(self,parameters): """ Sets solver parameters. Parameters ---------- parameters : dict """ for key,value in list(parameters.items()): if key in self.parameters: self.parameters[key] = value
How would you code a function in Python 3 to set solver parameters. Parameters ---------- parameters : dict
You are a Python code architect, reviewing and designing scalable and efficient code
Factorizes A and solves Ax = b.
Make a summary of the following Python 3 code def factorize_and_solve(self, A, b): self.factorize(A) return self.solve(b)
As a Python code translator, you convert algorithms and pseudocode into Python.
def solve(self,problem): """ Solves optimization problem. Parameters ---------- problem : Object """ # Local vars norm2 = self.norm2 norminf = self.norminf parameters = self.parameters # Parameters fea...
Can you create a Python 3 function that solves the objective of the object in the specified problem.
As a Python code analyst, you investigate and solve complex coding mysteries
def format_files(src: str, dest: str, **fmt_vars: str) -> None: """Copies all files inside src into dest while formatting the contents of the files into the output. For example, a file with the following contents: {foo} bar {baz} and the vars {'foo': 'herp', 'baz': 'derp'} will end up in the...
How would you implement a function in Python 3 that copies all files inside src into dest while formatting the contents of the files into the output.
As a Python code analyst, you investigate and solve complex coding mysteries
def analyze(self,A): """ Analyzes structure of A. Parameters ---------- A : matrix For symmetric systems, should contain only lower diagonal part. """ A = coo_matrix(A) self.mumps.set_shape(A.shape[0]) self.mumps.set...
Implement a function in Python 3 to analyze the structure of A and runs the analysis process.
As a Python code composer, you craft elegant and concise scripts.
def factorize(self,A): """ Factorizes A. Parameters ---------- A : matrix For symmetric systems, should contain only lower diagonal part. """ A = coo_matrix(A) self.mumps.set_centralized_assembled_values(A.data) self.mumps.run(job=2)
Implement a function in Python 3 to factorize A. Parameters ---------- A : matrix For symmetric systems, should contain only lower diagonal part.
You are a Python code generator, capable of creating scripts from specifications.
def solve(self,b): """ Solves system Ax=b. Parameters ---------- b : ndarray Returns ------- x : ndarray """ x = b.copy() self.mumps.set_rhs(x) self.mumps.run(job=3) return x
Write a Python 3 function for solving system Ax = b. getLogicalEntryPoint
As a Python code analyst, you investigate and solve complex coding mysteries
def factorize_and_solve(self,A,b): """ Factorizes A and sovles Ax=b. Parameters ---------- A : matrix b : ndarray Returns ------- x : ndarray """ A = coo_matrix(A) x = b.copy() self.mumps.set_centralized_assemble...
Implement a function in Python 3 to factorize A and sovles Ax = b.
You are a Python code generator, capable of creating scripts from specifications.
Set the assembled matrix on processor 0.
Can you tell what is the following Python 3 function doing def set_centralized_sparse(self, A): if self.myid != 0: return A = A.tocoo() n = A.shape[0] assert A.shape == (n, n), "Expected a square matrix." self.set_shape(n) self.set_centralized_assembled(A.row...
As a python code expert, you are capable of creating scripts from specifications.
Set the assembled matrix on processor 0.
Can you generate the documentation for the following Python 3 function def set_centralized_assembled(self, irn, jcn, a): self.set_centralized_assembled_rows_cols(irn, jcn) self.set_centralized_assembled_values(a)
As a Python code analyst, you investigate and solve complex coding mysteries
def set_centralized_assembled_rows_cols(self, irn, jcn): """Set assembled matrix indices on processor 0. The row and column indices (irn & jcn) should be one based. """ if self.myid != 0: return assert irn.size == jcn.size self._refs.update(irn=irn, jcn=jcn) ...
Can you implement a function in Python 3 that sets the assembled rows and columns on processor 0.
You are a Python code generator, capable of creating scripts from specifications.
def set_centralized_assembled_values(self, a): """Set assembled matrix values on processor 0.""" if self.myid != 0: return assert a.size == self.id.nz self._refs.update(a=a) self.id.a = self.cast_array(a)
Write a Python 3 function for setting the assembled matrix values on processor 0.
You are a Python code analyst, evaluating scripts for potential improvements.
def set_distributed_assembled(self, irn_loc, jcn_loc, a_loc): """Set the distributed assembled matrix. Distributed assembled matrices require setting icntl(18) != 0. """ self.set_distributed_assembled_rows_cols(irn_loc, jcn_loc) self.set_distributed_assembled_values(a_loc)
Write a Python 3 function for setting the distributed assembled matrix.
As a Python code translator, you convert algorithms and pseudocode into Python.
Set the distributed assembled matrix row & column numbers.
Explain what the following Python 3 code does def set_distributed_assembled_rows_cols(self, irn_loc, jcn_loc): assert irn_loc.size == jcn_loc.size self._refs.update(irn_loc=irn_loc, jcn_loc=jcn_loc) self.id.nz_loc = irn_loc.size self.id.irn_loc = self.cast_array(irn_loc) self.id...
You are a Python code analyst, evaluating scripts for potential improvements.
def set_distributed_assembled_values(self, a_loc): """Set the distributed assembled matrix values. Distributed assembled matrices require setting icntl(18) != 0. """ assert a_loc.size == self._refs['irn_loc'].size self._refs.update(a_loc=a_loc) self.id.a_loc = self.cast_...
Write a Python 3 function that can set the distributed assembled matrix values.
As a Python code analyst, you investigate and solve complex coding mysteries
def set_rhs(self, rhs): """Set the right hand side. This matrix will be modified in place.""" assert rhs.size == self.id.n self._refs.update(rhs=rhs) self.id.rhs = self.cast_array(rhs)
Write a Python 3 script to set the right hand side. This matrix will be modified in place.
As a Python code analyst, you investigate and solve complex coding mysteries
def destroy(self): """Delete the MUMPS context and release all array references.""" if self.id is not None and self._mumps_c is not None: self.id.job = -2 # JOB_END self._mumps_c(self.id) self.id = None self._refs = None
Create a Python 3 function for deleting the MUMPS context and release all array references.
You are a Python code generator, capable of creating scripts from specifications.
def mumps(self): """Call MUMPS, checking for errors in the return code. The desired job should have already been set using `ctx.set_job(...)`. As a convenience, you may wish to call `ctx.run(job=...)` which sets the job and calls MUMPS. """ self._mumps_c(self.id) ...
Create a Python 3 function to call MUMPS checking for errors in the return code.
As a python code expert, you are capable of creating scripts from specifications.
def modify_origin(self, from_state, from_key): """Set both from_state and from_key at the same time to modify data flow origin :param str from_state: State id of the origin state :param int from_key: Data port id of the origin port :raises exceptions.ValueError: If parameters have wrong...
How would you code a function in Python 3 to modify the data flow origin state and key at the same time to modify data flow origin state and key.
You are a Python code analyst, evaluating scripts for potential improvements.
Modify the state id and key of the data flow target.
Explain what the following Python 3 code does def modify_target(self, to_state, to_key): if not isinstance(to_state, string_types): raise ValueError("Invalid data flow target port: from_state must be a string") if not isinstance(to_key, int): raise ValueError("Invalid data flow t...
As a python code expert, you are capable of creating scripts from specifications.
def register_actions(self, shortcut_manager): """Register callback methods for triggered actions :param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings between shortcuts and actions. """ shortcut_manager.add_callback_for...
How would you implement a function in Python 3 that registers callback methods for triggered actions
As a Python code analyst, you investigate and solve complex coding mysteries
def code_changed(self, source): """ Apply checks and adjustments of the TextBuffer and TextView after every change in buffer. The method re-apply the tag (style) for the buffer. It avoids changes while editable-property set to False which are caused by a bug in the GtkSourceView2. GtkSourceVi...
How would you code a function in Python 3 to apply checks and adjustments of the TextBuffer and TextView after every change in buffer. The method re-apply the tag (style) for the buffer. It avoids changes while editable-property set to False which are caused by a bug in the GtkSourceView2. GtkSourceView2 is the default...
As a Python code composer, you craft elegant and concise scripts.
def apply_clicked(self, button): """Triggered when the Apply-Shortcut in the editor is triggered. """ if isinstance(self.model.state, LibraryState): return self.set_script_text(self.view.get_text())
Can you create a Python 3 function that triggers when the Apply - Shortcut is clicked.
You are a Python code architect, reviewing and designing scalable and efficient code
Set the default input or deactivated style scheme by set text workaround.
Explain what the following Python 3 code does def set_enabled(self, on, text=None): self.while_in_set_enabled = True # Apply color scheme by set text 'workaround' (with current buffer source) self.set_text(self.get_text()) if text is None else self.set_text(text) if on: sel...
You are a Python code architect, reviewing and designing scalable and efficient code
This function is called by the plugin after the plugin is initialized.
Make a summary of the following Python 3 code def post_init(setup_config): logger.info("Run post-initiation hook of {} plugin.".format(__file__.split(os.path.sep)[-2])) from . import core_template_observer # Example 1: initiate observer some elements of the execution engine core_template_observer.Execu...
You are a Python code architect, reviewing and designing scalable and efficient code
def reduce_to_parent_states(models): """Remove all models of states that have a state model with parent relation in the list The function filters the list of models, so that for no model in the list, one of it (grand-)parents is also in the list. E.g. if the input models consists of a hierarchy state with ...
Can you write a function in Python 3 where it removes all models of states that have a state model with parent relation in the list The function filters the list of models, so that for no model in the list, one of it (grand-)parents is also in the list. E.g. if the input models consists of a hierarchy state with two of...
As a python code expert, you are capable of creating scripts from specifications.
Checks if the selection is to be extended
How would you explain what the following Python 3 function does def extend_selection(): from rafcon.gui.singleton import main_window_controller currently_pressed_keys = main_window_controller.currently_pressed_keys if main_window_controller else set() if any(key in currently_pressed_keys for key in [constan...
As a Python code translator, you convert algorithms and pseudocode into Python.
def _check_model_types(self, models): """ Check types of passed models for correctness and in case raise exception :rtype: set :returns: set of models that are valid for the class""" if not hasattr(models, "__iter__"): models = {models} if not all([isinstance(model, ...
Write a Python 3 function for checking types of passed models for correctness and in case raise exception
As a Python code translator, you convert algorithms and pseudocode into Python.
def add(self, models): """ Adds the passed model(s) to the selection""" if models is None: return models = self._check_model_types(models) self._selected.update(models) self._selected = reduce_to_parent_states(self._selected)
Write a Python 3 script to add the passed models to the selection
You are a Python code architect, reviewing and designing scalable and efficient code
def remove(self, models): """ Removed the passed model(s) from the selection""" models = self._check_model_types(models) for model in models: if model in self._selected: self._selected.remove(model)
How would you implement a function in Python 3 that removes the passed model from the selection
As a python code expert, you are capable of creating scripts from specifications.
def set(self, models): """ Sets the selection to the passed model(s) """ # Do not add None values to selection if models is None: models = set() models = self._check_model_types(models) if len(models) > 1: models = reduce_to_parent_states(models) ...
Write a Python 3 function for setting the selection to the passed model s
As a python code expert, you are capable of creating scripts from specifications.
def handle_prepared_selection_of_core_class_elements(self, core_class, models): """Handles the selection for TreeStore widgets maintaining lists of a specific `core_class` elements If widgets hold a TreeStore with elements of a specific `core_class`, the local selection of that element type is ...
Write a Python 3 function that can handle the selection for a specific core_class elements of a specific TreeStore.
You are a Python code analyst, evaluating scripts for potential improvements.
def handle_new_selection(self, models): """Handles the selection for generic widgets This is a helper method for generic widgets that want to modify the selection. These widgets can pass a list of newly selected (or clicked on) models. The method looks at the previous selection, the pa...
How would you implement a function in Python 3 that handles the new selection for generic widgets.
As a Python code analyst, you investigate and solve complex coding mysteries
Sets the passed model as focused element
Here you have a function in Python 3, explain what it does def focus(self, model): if model is None: del self.focus return self._check_model_types(model) self.add(model) focus_msg = FocusSignalMsg(model, self._focus) self._focus = model self._sele...
As a Python code composer, you craft elegant and concise scripts.
Maintains inner lists of selected elements with a specific core element class
Can you tell what is the following Python 3 function doing def update_core_element_lists(self): def get_selected_elements_of_core_class(core_class): return set(element for element in self._selected if isinstance(element.core_element, core_class)) self._states = get_selected_elements_of_core_...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns all selected elements of the specified core element type as state element class
Here you have a function in Python 3, explain what it does def get_selected_elements_of_core_class(self, core_element_type): if core_element_type is Outcome: return self.outcomes elif core_element_type is InputDataPort: return self.input_data_ports elif core_element_type ...
You are a Python code analyst, evaluating scripts for potential improvements.
def is_selected(self, model): """Checks whether the given model is selected :param model: :return: True if the model is within the selection, False else :rtype: bool """ if model is None: return len(self._selected) == 0 return model in self._selected
Write a Python 3 function that can check whether the given model is selected by the user.
You are a Python code generator, capable of creating scripts from specifications.
Executes a specific command in a separate process with a path as argument.
How would you explain what the following Python 3 function does def execute_command_with_path_in_process(command, path, shell=False, cwd=None, logger=None): if logger is None: logger = _logger logger.debug("Opening path with command: {0} {1}".format(command, path)) # This splits the command in a mat...
As a Python code analyst, you investigate and solve complex coding mysteries
def execute_command_in_process(command, shell=False, cwd=None, logger=None): """ Executes a specific command in a separate process :param command: the command to be executed :param bool shell: Whether to use a shell :param str cwd: The working directory of the command :param logger: optional logger...
Can you implement a function in Python 3 that executes a specific command in a separate process
You are a Python code architect, reviewing and designing scalable and efficient code
def _load_child_state_models(self, load_meta_data): """Adds models for each child state of the state :param bool load_meta_data: Whether to load the meta data of the child state """ self.states = {} # Create model for each child class child_states = self.state.states ...
Create a Python 3 function for adding models for each child state of the state
You are a Python code generator, capable of creating scripts from specifications.
Adds models for each scoped variable in the state
How would you explain what the following Python 3 function does def _load_scoped_variable_models(self): self.scoped_variables = [] for scoped_variable in self.state.scoped_variables.values(): self._add_model(self.scoped_variables, scoped_variable, ScopedVariableModel)
As a Python code translator, you convert algorithms and pseudocode into Python.
def _load_data_flow_models(self): """ Adds models for each data flow of the state """ self.data_flows = [] for data_flow in self.state.data_flows.values(): self._add_model(self.data_flows, data_flow, DataFlowModel)
Write a Python 3 function for adding models for each data flow in the state
You are a Python code generator, capable of creating scripts from specifications.