idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
53,500 | def subgraph_from ( self , targets : sos_targets ) : if 'DAG' in env . config [ 'SOS_DEBUG' ] or 'ALL' in env . config [ 'SOS_DEBUG' ] : env . log_to_file ( 'DAG' , 'create subgraph' ) subnodes = [ ] for node in self . nodes ( ) : if node . _output_targets . valid ( ) and any ( x in node . _output_targets for x in targ... | Trim DAG to keep only nodes that produce targets |
53,501 | def build ( self ) : if 'DAG' in env . config [ 'SOS_DEBUG' ] or 'ALL' in env . config [ 'SOS_DEBUG' ] : env . log_to_file ( 'DAG' , 'build DAG' ) for wf in range ( self . _forward_workflow_id + 1 ) : indexed = [ x for x in self . nodes ( ) if x . _wf_index == wf ] indexed . sort ( key = lambda x : x . _node_index ) fo... | Connect nodes according to status of targets |
53,502 | def monitor_tasks ( self , tasks = None , status = None , age = None ) : self . engine_ready . wait ( ) if not tasks : tasks = self . task_status . keys ( ) else : tasks = [ x for x in tasks if x in self . task_status ] with threading . Lock ( ) : for task in tasks : if self . task_status [ task ] in ( 'submitted' , 'r... | Start monitoring specified or all tasks |
53,503 | def _submit_task_with_template ( self , task_ids ) : runtime = self . config runtime . update ( { 'workdir' : os . getcwd ( ) , 'cur_dir' : os . getcwd ( ) , 'verbosity' : env . verbosity , 'sig_mode' : env . config . get ( 'sig_mode' , 'default' ) , 'run_mode' : env . config . get ( 'run_mode' , 'run' ) , 'home_dir' :... | Submit tasks by interpolating a shell script defined in job_template |
53,504 | def is_type_hint ( stmt : str ) -> bool : if stmt . count ( '=' ) > 1 : return False if ':' not in stmt : return False if not stmt . split ( ':' ) [ 1 ] . strip ( ) : return False if '=' not in stmt : action , par = [ x . strip ( ) for x in stmt . split ( ':' , 1 ) ] else : action , par = [ x . strip ( ) for x in stmt ... | Try to differentiate |
53,505 | def indented_script ( self ) -> bool : leading = INDENTED . match ( self . _script ) return 0 if leading is None else len ( leading . group ( 2 ) ) | check self . _script and see if it is indented |
53,506 | def category ( self ) -> Optional [ str ] : if self . statements : if self . statements [ - 1 ] [ 0 ] == ':' : def validDirective ( ) : if not self . values : return True if self . values [ - 1 ] . strip ( ) . endswith ( ',' ) : return False try : compile ( 'func(' + '' . join ( self . values ) + ')' , filename = '<str... | Determine the category of existing statement |
53,507 | def isValid ( self ) -> bool : if not self . values : return True try : if self . category ( ) == 'directive' : if self . values [ - 1 ] . strip ( ) . endswith ( ',' ) : self . error_msg = 'Trailing ,' return False try : compile ( 'func(' + '' . join ( self . values ) + ')' , filename = '<string>' , mode = 'eval' ) exc... | Determine if the statement expression or directive is valid . Otherwise the parser will continue until a valid multi - line expression or statement can be found . |
53,508 | def extend ( self , line : str ) -> None : if self . category ( ) == 'directive' : self . add_directive ( None , line ) elif self . category ( ) == 'script' : self . _script += line else : self . add_statement ( line ) | Extend the current directive expression or script |
53,509 | def add_statement ( self , line : str , lineno : Optional [ int ] = None ) -> None : if self . category ( ) != 'statements' : self . values = [ line ] else : self . values . append ( line ) if self . statements and self . statements [ - 1 ] [ 0 ] == '!' : self . statements [ - 1 ] [ - 1 ] += line else : self . statemen... | statements are regular python statements |
53,510 | def get_tokens ( self ) -> str : def _get_tokens ( statement ) : return [ x [ 1 ] for x in generate_tokens ( StringIO ( statement ) . readline ) if x [ 1 ] not in ( '' , '\n' ) ] tokens : List = [ ] for statement in self . statements : tokens . extend ( _get_tokens ( statement [ 2 ] if statement [ 0 ] == ':' else state... | Get tokens after input statement |
53,511 | def show ( self ) : textWidth = max ( 60 , shutil . get_terminal_size ( ( 80 , 20 ) ) . columns ) text = f' {self.step_name() + ":":<21} ' + self . comment print ( '\n' . join ( textwrap . wrap ( text , width = textWidth , initial_indent = '' , subsequent_indent = ' ' * 24 ) ) ) local_parameters = { x : y for x , y in... | Output for command sos show |
53,512 | def extend ( self , workflow : 'SoS_Workflow' ) -> None : if not workflow . sections : return if not self . sections : self . sections = workflow . sections return section = workflow . sections [ 0 ] depends_idx = [ idx for idx , stmt in enumerate ( section . statements ) if stmt [ 0 ] == ':' and stmt [ 1 ] == 'depends... | Append another workflow to existing one to created a combined workflow |
53,513 | def add_comment ( self , line : str ) -> None : self . _last_comment += ( ' ' if self . _last_comment else '' ) + line . lstrip ( '#' ) . strip ( ) | Keeping track of last comment for section and parameter |
53,514 | def workflow ( self , workflow_name : Optional [ str ] = None , use_default : bool = True ) -> SoS_Workflow : if workflow_name is None and not use_default : return SoS_Workflow ( self . content , '' , '' , self . sections , self . global_stmts ) allowed_steps = None if not workflow_name : wf_name = '' else : if '+' in ... | Return a workflow with name_step + name_step specified in wf_name This function might be called recursively because of nested workflow . |
53,515 | def print_help ( self , script_name : str ) : textWidth = max ( 60 , shutil . get_terminal_size ( ( 80 , 20 ) ) . columns ) if len ( script_name ) > 20 : print ( f'usage: sos run {script_name}' ) print ( ' [workflow_name | -t targets] [options] [workflow_options]' ) else : print ( f'usage: sos run {script... | print a help message from the script |
53,516 | def glob_wildcards ( pattern : str , files : Optional [ List [ str ] ] = None ) -> Dict [ str , Union [ List [ Any ] , List [ str ] ] ] : pattern = os . path . normpath ( pattern ) if sys . platform == 'win32' : pattern = pattern . replace ( '\\' , '/' ) first_wildcard = re . search ( "{[^{]" , pattern ) dirname = os .... | Glob the values of the wildcards by matching the given pattern to the filesystem . Returns a named tuple with a list of values for each wildcard . |
53,517 | def extract_pattern ( pattern : str , ifiles : List [ str ] ) -> Dict [ str , any ] : res = glob_wildcards ( pattern , [ ] ) for ifile in ifiles : matched = glob_wildcards ( pattern , [ ifile ] ) for key in matched . keys ( ) : if not matched [ key ] : res [ key ] . append ( None ) else : res [ key ] . extend ( matched... | This function match pattern to a list of input files extract and return pieces of filenames as a list of variables with keys defined by pattern . |
53,518 | def expand_pattern ( pattern : str ) -> List [ str ] : ofiles = [ ] sz = None res = glob_wildcards ( pattern , [ ] ) sz = None wildcard = [ { } ] for key in res . keys ( ) : if key not in env . sos_dict : raise ValueError ( f'Undefined variable {key} in pattern {pattern}' ) if not isinstance ( env . sos_dict [ key ] , ... | This function expand patterns against the current namespace and return a list of filenames |
53,519 | def interpolate ( text , global_dict = None , local_dict = None ) : try : return eval ( as_fstring ( text ) , global_dict , local_dict ) except Exception as e : raise ValueError ( f'Failed to interpolate {text}: {e}' ) | Evaluate expressions in text |
53,520 | def SoS_eval ( expr : str , extra_dict : dict = { } ) -> Any : return eval ( expr , env . sos_dict . dict ( ) , extra_dict ) | Evaluate an expression with sos dict . |
53,521 | def SoS_exec ( script : str , _dict : dict = None , return_result : bool = True ) -> None : if _dict is None : _dict = env . sos_dict . dict ( ) if not return_result : exec ( compile ( script , filename = stmtHash . hash ( script ) , mode = 'exec' ) , _dict ) return None try : stmts = list ( ast . iter_child_nodes ( as... | Execute a statement . |
53,522 | def expand_depends_files ( * args , ** kwargs ) : args = [ x . resolve ( ) if isinstance ( x , dynamic ) else x for x in args ] kwargs = { x : ( y . resolve ( ) if isinstance ( y , dynamic ) else y ) for x , y in kwargs . items ( ) } return sos_targets ( * args , ** kwargs , _verify_existence = True , _undetermined = F... | handle directive depends |
53,523 | def wait_for_subworkflows ( self , workflow_results ) : wf_ids = sum ( [ x [ 'pending_workflows' ] for x in workflow_results ] , [ ] ) for wf_id in wf_ids : yield self . socket res = self . socket . recv_pyobj ( ) if res is None : sys . exit ( 0 ) elif isinstance ( res , Exception ) : raise res | Wait for results from subworkflows |
53,524 | def Rmarkdown ( script = None , input = None , output = None , args = '{input:r}, output_file={output:ar}' , ** kwargs ) : if not R_library ( 'rmarkdown' ) . target_exists ( ) : raise RuntimeError ( 'Library rmarkdown does not exist' ) input = sos_targets ( collect_input ( script , input ) ) output = sos_targets ( outp... | Convert input file to output using Rmarkdown |
53,525 | def total_memory ( self , image = 'ubuntu' ) : try : ret = subprocess . check_output ( f , shell = True , stdin = subprocess . DEVNULL ) self . tot_mem = int ( ret . split ( ) [ 1 ] ) except Exception : self . tot_mem = None return self . tot_mem | Get the available ram fo the docker machine in Kb |
53,526 | def script ( script , interpreter = '' , suffix = '' , args = '' , ** kwargs ) : return SoS_ExecuteScript ( script , interpreter , suffix , args ) . run ( ** kwargs ) | Execute specified script using specified interpreter . This action accepts common action arguments such as input active workdir docker_image and args . In particular content of one or more files specified by option input would be prepended before the specified script . |
53,527 | def stop_if ( expr , msg = '' , no_output = False ) : if expr : raise StopInputGroup ( msg = msg , keep_output = not no_output ) return 0 | Abort the execution of the current step or loop and yield an warning message msg if expr is False |
53,528 | def download ( URLs , dest_dir = '.' , dest_file = None , decompress = False , max_jobs = 5 ) : if env . config [ 'run_mode' ] == 'dryrun' : print ( f'HINT: download\n{URLs}\n' ) return None if isinstance ( URLs , str ) : urls = [ x . strip ( ) for x in URLs . split ( ) if x . strip ( ) ] else : urls = list ( URLs ) if... | Download files from specified URL which should be space tab or newline separated URLs . The files will be downloaded to specified destination . If filename . md5 files are downloaded they are used to validate downloaded filename . Unless otherwise specified compressed files are decompressed . If max_jobs is given a max... |
53,529 | def run ( script , args = '' , ** kwargs ) : if sys . platform == 'win32' : interpreter = '' else : if not script . startswith ( '#!' ) : interpreter = '/bin/bash' if not args : args = '-ev {filename:q}' else : interpreter = '' return SoS_ExecuteScript ( script , interpreter , '' , args ) . run ( ** kwargs ) | Execute specified script using bash . This action accepts common action arguments such as input active workdir docker_image and args . In particular content of one or more files specified by option input would be prepended before the specified script . |
53,530 | def pandoc ( script = None , input = None , output = None , args = '{input:q} --output {output:q}' , ** kwargs ) : if not executable ( 'pandoc' ) . target_exists ( ) : raise RuntimeError ( 'pandoc not found' ) input = sos_targets ( collect_input ( script , input ) ) output = sos_targets ( output ) if len ( output ) == ... | Convert input file to output using pandoc |
53,531 | def get_changed_vars ( section : SoS_Step ) : if 'shared' not in section . options : return set ( ) changed_vars = set ( ) svars = section . options [ 'shared' ] if isinstance ( svars , str ) : changed_vars . add ( svars ) svars = { svars : svars } elif isinstance ( svars , Sequence ) : for item in svars : if isinstanc... | changed vars are variables that are shared and therefore provides to others |
53,532 | def get_all_used_vars ( section ) : all_used_vars = set ( ) for statement in section . statements : if statement [ 0 ] == '=' : all_used_vars |= accessed_vars ( '=' . join ( statement [ 1 : 3 ] ) ) elif statement [ 0 ] == '!' : all_used_vars |= accessed_vars ( statement [ 1 ] ) elif statement [ 0 ] == ':' : all_used_va... | Get variables which are variables used by input statement and statements before it |
53,533 | def get_signature_vars ( section ) : signature_vars = set ( section . parameters . keys ( ) & accessed_vars ( strip_param_defs ( section . global_stmts ) ) ) input_idx = find_statement ( section , 'input' ) after_input_idx = 0 if input_idx is None else input_idx + 1 for statement in section . statements [ after_input_i... | Get signature variables which are variables that will be saved with step signatures |
53,534 | def get_step_input ( section , default_input ) : step_input : sos_targets = sos_targets ( ) dynamic_input = True input_idx = find_statement ( section , 'input' ) if input_idx is None : return step_input , dynamic_input stmt = section . statements [ input_idx ] [ 2 ] try : svars = [ 'output_from' , 'named_output' , 'sos... | Find step input |
53,535 | def get_step_output ( section , default_output ) : step_output : sos_targets = sos_targets ( ) if 'provides' in section . options and default_output : step_output = default_output output_idx = find_statement ( section , 'output' ) if output_idx is None : return step_output value = section . statements [ output_idx ] [ ... | determine step output |
53,536 | def analyze_section ( section : SoS_Step , default_input : Optional [ sos_targets ] = None , default_output : Optional [ sos_targets ] = None , context = { } , vars_and_output_only : bool = False ) -> Dict [ str , Any ] : new_env , old_env = env . request_new ( ) try : prepare_env ( section . global_def , section . glo... | Analyze a section for how it uses input and output what variables it uses and input output etc . |
53,537 | def extract_workflow ( notebook ) : if isinstance ( notebook , str ) : nb = nbformat . read ( notebook , nbformat . NO_CONVERT ) else : nb = notebook cells = nb . cells content = '#!/usr/bin/env sos-runner\n#fileformat=SOS1.0\n\n' for cell in cells : if cell . cell_type != "code" : continue if 'kernel' in cell . metada... | Extract workflow from a notebook file or notebook JSON instance |
53,538 | def vim_ipython_is_open ( ) : for w in vim . windows : if w . buffer . name is not None and w . buffer . name . endswith ( "vim-ipython" ) : return True return False | Helper function to let us know if the vim - ipython shell is currently visible |
53,539 | def with_subchannel ( f , * args ) : "conditionally monitor subchannel" def f_with_update ( * args ) : try : f ( * args ) if monitor_subchannel : update_subchannel_msgs ( force = True ) except AttributeError : echo ( "not connected to IPython" , 'Error' ) return f_with_update | conditionally monitor subchannel |
53,540 | def set_pid ( ) : global pid lines = '\n' . join ( [ 'import os' , '_pid = os.getpid()' ] ) try : msg_id = send ( lines , silent = True , user_variables = [ '_pid' ] ) except TypeError : msg_id = send ( lines , silent = True , user_expressions = { '_pid' : '_pid' } ) try : child = get_child_msg ( msg_id ) except Empty ... | Explicitly ask the ipython kernel for its pid |
53,541 | def fetchmany ( self , size = - 1 ) : self . _cursorLock . acquire ( ) if size < 0 or size > self . MAX_BLOCK_SIZE : size = self . arraysize recs = [ ] for i in range ( 0 , size ) : recs . append ( self . fetchone ( ) ) self . _cursorLock . release ( ) return recs | return a sequential set of records . This is guaranteed by locking so that no other thread can grab a few records while a set is fetched . this has the side effect that other threads may have to wait for an arbitrary long time for the completion of the current request . |
53,542 | def on_number ( self , ctx , value ) : value = int ( value ) if value . isdigit ( ) else float ( value ) top = self . _stack [ - 1 ] if top is JSONCompositeType . OBJECT : self . fire ( JSONStreamer . VALUE_EVENT , value ) elif top is JSONCompositeType . ARRAY : self . fire ( JSONStreamer . ELEMENT_EVENT , value ) else... | Since this is defined both integer and double callbacks are useless |
53,543 | def close ( self ) : self . fire ( JSONStreamer . DOC_END_EVENT ) self . _stack = None self . _parser . close ( ) | Closes the streamer which causes a DOC_END_EVENT to be fired and frees up memory used by yajl |
53,544 | async def minizinc ( mzn , * dzn_files , args = None , data = None , include = None , stdlib_dir = None , globals_dir = None , declare_enums = True , allow_multiple_assignments = False , keep = False , output_vars = None , output_base = None , output_mode = 'dict' , solver = None , timeout = None , two_pass = None , pr... | Coroutine version of the pymzn . minizinc function . |
53,545 | def parse_value ( val , var_type = None , enums = None , rebase_arrays = True ) : if not var_type : p_val = _parse_array ( val , rebase_arrays = rebase_arrays , enums = enums , raise_errors = False ) if p_val is not None : return p_val return _parse_val ( val , enums = enums ) if 'dims' in var_type : return _parse_arra... | Parses the value of a dzn statement . |
53,546 | def dzn2dict ( dzn , * , rebase_arrays = True , types = None , return_enums = False ) : dzn_ext = os . path . splitext ( dzn ) [ 1 ] if dzn_ext == '.dzn' : with open ( dzn ) as f : dzn = f . read ( ) var_types = None if types : var_types = { } for var , var_type in types . items ( ) : if isinstance ( var_type , str ) :... | Parses a dzn string or file into a dictionary of variable assignments . |
53,547 | def args ( self , all_solutions = False , num_solutions = None , free_search = False , parallel = None , seed = None , ** kwargs ) : args = [ '-s' , '-v' ] if all_solutions : args . append ( '-a' ) if num_solutions is not None : args += [ '-n' , num_solutions ] if free_search : args . append ( '-f' ) if parallel is not... | Returns a list of command line arguments for the specified options . |
53,548 | def debug ( dbg = True ) : global _debug_handler if dbg and _debug_handler is None : _debug_handler = logging . StreamHandler ( ) logger . addHandler ( _debug_handler ) logger . setLevel ( logging . DEBUG ) elif not dbg and _debug_handler is not None : logger . removeHandler ( _debug_handler ) _debug_handler = None log... | Enables or disables debugging messages on the standard output . |
53,549 | def minizinc_version ( ) : vs = _run_minizinc ( '--version' ) m = re . findall ( 'version ([\d\.]+)' , vs ) if not m : raise RuntimeError ( 'MiniZinc executable not found.' ) return m [ 0 ] | Returns the version of the found minizinc executable . |
53,550 | def preprocess_model ( model , rewrap = True , ** kwargs ) : args = { ** kwargs , ** config . get ( 'args' , { } ) } model = _process_template ( model , ** args ) if rewrap : model = rewrap_model ( model ) return model | Preprocess a MiniZinc model . |
53,551 | def save_model ( model , output_file = None , output_dir = None , output_prefix = 'pymzn' ) : if output_file : mzn_file = output_file output_file = open ( output_file , 'w+' , buffering = 1 ) else : output_prefix += '_' output_file = NamedTemporaryFile ( dir = output_dir , prefix = output_prefix , suffix = '.mzn' , del... | Save a model to file . |
53,552 | def check_instance ( mzn , * dzn_files , data = None , include = None , stdlib_dir = None , globals_dir = None , allow_multiple_assignments = False ) : args = [ '--instance-check-only' ] args += _flattening_args ( mzn , * dzn_files , data = data , include = include , stdlib_dir = stdlib_dir , globals_dir = globals_dir ... | Perform instance checking on a model + data . |
53,553 | def check_model ( mzn , * , include = None , stdlib_dir = None , globals_dir = None ) : args = [ '--model-check-only' ] args += _flattening_args ( mzn , include = include , stdlib_dir = stdlib_dir , globals_dir = globals_dir ) input = mzn if args [ - 1 ] == '-' else None proc = _run_minizinc_proc ( * args , input = inp... | Perform model checking on a given model . |
53,554 | def minizinc ( mzn , * dzn_files , args = None , data = None , include = None , stdlib_dir = None , globals_dir = None , declare_enums = True , allow_multiple_assignments = False , keep = False , output_vars = None , output_base = None , output_mode = 'dict' , solver = None , timeout = None , two_pass = None , pre_pass... | Implements the workflow for solving a CSP problem encoded with MiniZinc . |
53,555 | def solve ( solver , mzn , * dzn_files , data = None , include = None , stdlib_dir = None , globals_dir = None , allow_multiple_assignments = False , output_mode = 'item' , timeout = None , two_pass = None , pre_passes = None , output_objective = False , non_unique = False , all_solutions = False , num_solutions = None... | Flatten and solve a MiniZinc program . |
53,556 | def mzn2fzn ( mzn , * dzn_files , args = None , data = None , include = None , stdlib_dir = None , globals_dir = None , declare_enums = True , allow_multiple_assignments = False , keep = False , output_vars = None , output_base = None , output_mode = 'item' , no_ozn = False ) : mzn_file , dzn_files , data_file , data ,... | Flatten a MiniZinc model into a FlatZinc one . |
53,557 | def print ( self , output_file = sys . stdout , log = False ) : for soln in iter ( self ) : print ( soln , file = output_file ) print ( SOLN_SEP , file = output_file ) if self . status == 0 : print ( SEARCH_COMPLETE , file = output_file ) if ( self . status == 1 and self . _n_solns == 0 ) or self . status >= 2 : print ... | Print the solution stream |
53,558 | def dump ( self ) : try : import yaml cfg_file = self . _cfg_file ( ) cfg_dir , __ = os . path . split ( cfg_file ) os . makedirs ( cfg_dir , exist_ok = True ) with open ( cfg_file , 'w' ) as f : yaml . dump ( self , f ) except ImportError as err : raise RuntimeError ( 'Cannot dump the configuration settings to file. Y... | Writes the changes to the configuration file . |
53,559 | def discretize ( value , factor = 100 ) : if not isinstance ( value , Iterable ) : return int ( value * factor ) int_value = list ( deepcopy ( value ) ) for i in range ( len ( int_value ) ) : int_value [ i ] = int ( int_value [ i ] * factor ) return int_value | Discretize the given value pre - multiplying by the given factor |
53,560 | def from_string ( source , args = None ) : if _has_jinja : logger . info ( 'Precompiling model with arguments: {}' . format ( args ) ) return _jenv . from_string ( source ) . render ( args or { } ) if args : raise RuntimeError ( _except_text ) return source | Renders a template string |
53,561 | def add_package ( package_name , package_path = 'templates' , encoding = 'utf-8' ) : if not _has_jinja : raise RuntimeError ( _except_text ) _jload . add_loader ( PackageLoader ( package_name , package_path , encoding ) ) | Adds the given package to the template search routine |
53,562 | def add_path ( searchpath , encoding = 'utf-8' , followlinks = False ) : if not _has_jinja : raise RuntimeError ( _except_text ) _jload . add_loader ( FileSystemLoader ( searchpath , encoding , followlinks ) ) | Adds the given path to the template search routine |
53,563 | def val2dzn ( val , wrap = True ) : if _is_value ( val ) : dzn_val = _dzn_val ( val ) elif _is_set ( val ) : dzn_val = _dzn_set ( val ) elif _is_array_type ( val ) : dzn_val = _dzn_array_nd ( val ) else : raise TypeError ( 'Unsupported serialization of value: {}' . format ( repr ( val ) ) ) if wrap : wrapper = _get_wra... | Serializes a value into its dzn representation . |
53,564 | def stmt2dzn ( name , val , declare = True , assign = True , wrap = True ) : if not ( declare or assign ) : raise ValueError ( 'The statement must be a declaration or an assignment.' ) stmt = [ ] if declare : val_type = _dzn_type ( val ) stmt . append ( '{}: ' . format ( val_type ) ) stmt . append ( name ) if assign : ... | Returns a dzn statement declaring and assigning the given value . |
53,565 | def stmt2enum ( enum_type , declare = True , assign = True , wrap = True ) : if not ( declare or assign ) : raise ValueError ( 'The statement must be a declaration or an assignment.' ) stmt = [ ] if declare : stmt . append ( 'enum ' ) stmt . append ( enum_type . __name__ ) if assign : val_str = [ ] for v in list ( enum... | Returns a dzn enum declaration from an enum type . |
53,566 | def dict2dzn ( objs , declare = False , assign = True , declare_enums = True , wrap = True , fout = None ) : log = logging . getLogger ( __name__ ) vals = [ ] enums = set ( ) for key , val in objs . items ( ) : if _is_enum ( val ) and declare_enums : enum_type = type ( val ) enum_name = enum_type . __name__ if enum_nam... | Serializes the objects in input and produces a list of strings encoding them into dzn format . Optionally the produced dzn is written on a file . |
53,567 | def async_or_eager ( self , ** options ) : args = options . pop ( "args" , None ) kwargs = options . pop ( "kwargs" , None ) possible_broker_errors = self . _get_possible_broker_errors_tuple ( ) try : return self . apply_async ( args , kwargs , ** options ) except possible_broker_errors : return self . apply ( args , k... | Attempt to call self . apply_async or if that fails because of a problem with the broker run the task eagerly and return an EagerResult . |
53,568 | def async_or_fail ( self , ** options ) : args = options . pop ( "args" , None ) kwargs = options . pop ( "kwargs" , None ) possible_broker_errors = self . _get_possible_broker_errors_tuple ( ) try : return self . apply_async ( args , kwargs , ** options ) except possible_broker_errors as e : return self . simulate_asy... | Attempt to call self . apply_async but if that fails with an exception we fake the task completion using the exception as the result . This allows us to seamlessly handle errors on task creation the same way we handle errors when a task runs simplifying the user interface . |
53,569 | def delay_or_eager ( self , * args , ** kwargs ) : return self . async_or_eager ( args = args , kwargs = kwargs ) | Wrap async_or_eager with a convenience signiture like delay |
53,570 | def delay_or_run ( self , * args , ** kwargs ) : warnings . warn ( "delay_or_run is deprecated. Please use delay_or_eager" , DeprecationWarning , ) possible_broker_errors = self . _get_possible_broker_errors_tuple ( ) try : result = self . apply_async ( args = args , kwargs = kwargs ) required_fallback = False except p... | Attempt to call self . delay or if that fails call self . run . |
53,571 | def delay_or_fail ( self , * args , ** kwargs ) : return self . async_or_fail ( args = args , kwargs = kwargs ) | Wrap async_or_fail with a convenience signiture like delay |
53,572 | def simulate_async_error ( self , exception ) : task_id = gen_unique_id ( ) async_result = self . AsyncResult ( task_id ) einfo = ExceptionInfo ( sys . exc_info ( ) ) async_result . backend . mark_as_failure ( task_id , exception , traceback = einfo . traceback , ) return async_result | Take this exception and store it as an error in the result backend . This unifies the handling of broker - connection errors with any other type of error that might occur when running the task . So the same error - handling that might retry a task or display a useful message to the user can also handle this error . |
53,573 | def calc_progress ( self , completed_count , total_count ) : self . logger . debug ( "calc_progress(%s, %s)" , completed_count , total_count , ) current_time = time . time ( ) time_spent = current_time - self . start_time self . logger . debug ( "Progress time spent: %s" , time_spent ) if total_count == 0 : return 100 ... | Calculate the percentage progress and estimated remaining time based on the current number of items completed of the total . |
53,574 | def update_progress ( self , completed_count , total_count , update_frequency = 1 , ) : if completed_count - self . _last_update_count < update_frequency : return progress_percent , time_remaining = self . calc_progress ( completed_count , total_count ) self . logger . debug ( "Updating progress: %s percent, %s remaini... | Update the task backend with both an estimated percentage complete and number of seconds remaining until completion . |
53,575 | def _validate_required_class_vars ( self ) : required_members = ( 'significant_kwargs' , 'herd_avoidance_timeout' , ) for required_member in required_members : if not hasattr ( self , required_member ) : raise Exception ( "JobtasticTask's must define a %s" % required_member ) | Ensure that this subclass has defined all of the required class variables . |
53,576 | def on_success ( self , retval , task_id , args , kwargs ) : if self . request . is_eager : self . update_state ( task_id , SUCCESS , retval ) | Store results in the backend even if we re always eager . This ensures the delay_or_run calls always at least have results . |
53,577 | def _get_cache ( self ) : if not self . _cache : self . _cache = get_cache ( self . app ) return self . _cache | Return the cache to use for thundering herd protection etc . |
53,578 | def _get_cache_key ( self , ** kwargs ) : m = md5 ( ) for significant_kwarg in self . significant_kwargs : key , to_str = significant_kwarg try : m . update ( to_str ( kwargs [ key ] ) ) except ( TypeError , UnicodeEncodeError ) : m . update ( to_str ( kwargs [ key ] ) . encode ( 'utf-8' ) ) if hasattr ( self , 'cache_... | Take this task s configured significant_kwargs and build a hash that all equivalent task calls will match . |
53,579 | def get_cache ( app ) : jobtastic_cache_setting = app . conf . get ( 'JOBTASTIC_CACHE' ) if isinstance ( jobtastic_cache_setting , BaseCache ) : return jobtastic_cache_setting if 'Django' in CACHES : if jobtastic_cache_setting : try : return WrappedCache ( get_django_cache ( jobtastic_cache_setting ) ) except InvalidCa... | Attempt to find a valid cache from the Celery configuration |
53,580 | def select ( * args ) : def select_columns ( df , args ) : columns = [ column . _name for column in args ] if df . _grouped_on : for col in df . _grouped_on [ : : - 1 ] : if col not in columns : columns . insert ( 0 , col ) return columns return lambda df : df [ select_columns ( df , args ) ] | Select specific columns from DataFrame . |
53,581 | def arrange ( * args ) : names = [ column . _name for column in args ] def f ( df ) : sortby_df = df >> mutate ( * args ) index = sortby_df . sort_values ( [ str ( arg ) for arg in args ] ) . index return df . loc [ index ] return f | Sort DataFrame by the input column arguments . |
53,582 | def rename ( ** kwargs ) : def rename_columns ( df ) : column_assignments = { old_name_later . _name : new_name for new_name , old_name_later in kwargs . items ( ) } return df . rename ( columns = column_assignments ) return rename_columns | Rename one or more columns leaving other columns unchanged |
53,583 | def transmute ( * args , ** kwargs ) : mutate_dateframe_fn = mutate ( * args , ** dict ( kwargs ) ) column_names_args = [ str ( arg ) for arg in args ] column_names_kwargs = [ name for name , _ in _dict_to_possibly_ordered_tuples ( kwargs ) ] column_names = column_names_args + column_names_kwargs return lambda df : mut... | Similar to select but allows mutation in column definitions . |
53,584 | def get_join_cols ( by_entry ) : left_cols = [ ] right_cols = [ ] for col in by_entry : if isinstance ( col , str ) : left_cols . append ( col ) right_cols . append ( col ) else : left_cols . append ( col [ 0 ] ) right_cols . append ( col [ 1 ] ) return left_cols , right_cols | helper function used for joins builds left and right join list for join function |
53,585 | def mutating_join ( * args , ** kwargs ) : left = args [ 0 ] right = args [ 1 ] if 'by' in kwargs : left_cols , right_cols = get_join_cols ( kwargs [ 'by' ] ) else : left_cols , right_cols = None , None if 'suffixes' in kwargs : dsuffixes = kwargs [ 'suffixes' ] else : dsuffixes = ( '_x' , '_y' ) if left . _grouped_on ... | generic function for mutating dplyr - style joins |
53,586 | def _chart_support ( self , name , data , caller , ** kwargs ) : "template chart support function" id = 'chart-%s' % next ( self . id ) name = self . _chart_class_name ( name ) options = dict ( self . environment . options ) options . update ( name = name , id = id ) if jinja2 . __version__ >= '2.9' : kwargs = dict ( (... | template chart support function |
53,587 | def load_library ( self ) : "loads configuration options" try : filename = self . environment . get_template ( 'chartkick.json' ) . filename except TemplateNotFound : return { } else : options = Options ( ) options . load ( filename ) return options | loads configuration options |
53,588 | def js ( ) : "returns home directory of js" return os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , 'js' ) | returns home directory of js |
53,589 | def parse_options ( source ) : options = { } tokens = [ t . strip ( ) for t in source . split ( '=' ) ] name = tokens [ 0 ] for token in tokens [ 1 : - 1 ] : value , next_name = token . rsplit ( ' ' , 1 ) options [ name . strip ( ) ] = value name = next_name options [ name . strip ( ) ] = tokens [ - 1 ] . strip ( ) ret... | parses chart tag options |
53,590 | def copy ( self ) : return RigidTransform ( np . copy ( self . rotation ) , np . copy ( self . translation ) , self . from_frame , self . to_frame ) | Returns a copy of the RigidTransform . |
53,591 | def _check_valid_rotation ( self , rotation ) : if not isinstance ( rotation , np . ndarray ) or not np . issubdtype ( rotation . dtype , np . number ) : raise ValueError ( 'Rotation must be specified as numeric numpy array' ) if len ( rotation . shape ) != 2 or rotation . shape [ 0 ] != 3 or rotation . shape [ 1 ] != ... | Checks that the given rotation matrix is valid . |
53,592 | def _check_valid_translation ( self , translation ) : if not isinstance ( translation , np . ndarray ) or not np . issubdtype ( translation . dtype , np . number ) : raise ValueError ( 'Translation must be specified as numeric numpy array' ) t = translation . squeeze ( ) if len ( t . shape ) != 1 or t . shape [ 0 ] != ... | Checks that the translation vector is valid . |
53,593 | def interpolate_with ( self , other_tf , t ) : if t < 0 or t > 1 : raise ValueError ( 'Must interpolate between 0 and 1' ) interp_translation = ( 1.0 - t ) * self . translation + t * other_tf . translation interp_rotation = transformations . quaternion_slerp ( self . quaternion , other_tf . quaternion , t ) interp_tf =... | Interpolate with another rigid transformation . |
53,594 | def linear_trajectory_to ( self , target_tf , traj_len ) : if traj_len < 0 : raise ValueError ( 'Traj len must at least 0' ) delta_t = 1.0 / ( traj_len + 1 ) t = 0.0 traj = [ ] while t < 1.0 : traj . append ( self . interpolate_with ( target_tf , t ) ) t += delta_t traj . append ( target_tf ) return traj | Creates a trajectory of poses linearly interpolated from this tf to a target tf . |
53,595 | def apply ( self , points ) : if not isinstance ( points , BagOfPoints ) : raise ValueError ( 'Rigid transformations can only be applied to bags of points' ) if points . dim != 3 : raise ValueError ( 'Rigid transformations can only be applied to 3-dimensional points' ) if points . frame != self . _from_frame : raise Va... | Applies the rigid transformation to a set of 3D objects . |
53,596 | def dot ( self , other_tf ) : if other_tf . to_frame != self . from_frame : raise ValueError ( 'To frame of right hand side ({0}) must match from frame of left hand side ({1})' . format ( other_tf . to_frame , self . from_frame ) ) pose_tf = self . matrix . dot ( other_tf . matrix ) rotation , translation = RigidTransf... | Compose this rigid transform with another . |
53,597 | def inverse ( self ) : inv_rotation = self . rotation . T inv_translation = np . dot ( - self . rotation . T , self . translation ) return RigidTransform ( inv_rotation , inv_translation , from_frame = self . _to_frame , to_frame = self . _from_frame ) | Take the inverse of the rigid transform . |
53,598 | def save ( self , filename ) : file_root , file_ext = os . path . splitext ( filename ) if file_ext . lower ( ) != TF_EXTENSION : raise ValueError ( 'Extension %s not supported for RigidTransform. Must be stored with extension %s' % ( file_ext , TF_EXTENSION ) ) f = open ( filename , 'w' ) f . write ( '%s\n' % ( self .... | Save the RigidTransform to a file . |
53,599 | def as_frames ( self , from_frame , to_frame = 'world' ) : return RigidTransform ( self . rotation , self . translation , from_frame , to_frame ) | Return a shallow copy of this rigid transform with just the frames changed . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.