query stringlengths 5 1.23k | positive stringlengths 53 15.2k | id_ int64 0 252k | task_name stringlengths 87 242 | negative listlengths 20 553 |
|---|---|---|---|---|
Performs a Q iteration updates Vm . | def _q_iteration ( self , Q , Bpp_solver , Vm , Va , pq ) : dVm = - Bpp_solver . solve ( Q ) # Update voltage. Vm [ pq ] = Vm [ pq ] + dVm V = Vm * exp ( 1j * Va ) return V , Vm , Va | 800 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L494-L503 | [
"def",
"_handle_eio_message",
"(",
"self",
",",
"sid",
",",
"data",
")",
":",
"if",
"sid",
"in",
"self",
".",
"_binary_packet",
":",
"pkt",
"=",
"self",
".",
"_binary_packet",
"[",
"sid",
"]",
"if",
"pkt",
".",
"add_attachment",
"(",
"data",
")",
":",
... |
Signal with sinusoidal frequency modulation . | def fmsin ( N , fnormin = 0.05 , fnormax = 0.45 , period = None , t0 = None , fnorm0 = 0.25 , pm1 = 1 ) : if period == None : period = N if t0 == None : t0 = N / 2 pm1 = nx . sign ( pm1 ) fnormid = 0.5 * ( fnormax + fnormin ) delta = 0.5 * ( fnormax - fnormin ) phi = - pm1 * nx . arccos ( ( fnorm0 - fnormid ) / delta )... | 801 | https://github.com/melizalab/libtfr/blob/9f7e7705793d258a0b205f185b20e3bbcda473da/examples/tfr_tm.py#L14-L56 | [
"def",
"on_failure",
"(",
"self",
",",
"entity",
")",
":",
"logger",
".",
"error",
"(",
"\"Login failed, reason: %s\"",
"%",
"entity",
".",
"getReason",
"(",
")",
")",
"self",
".",
"connected",
"=",
"False"
] |
Returns a case from the given file . | def _parse_rdf ( self , file ) : store = Graph ( ) store . parse ( file ) print len ( store ) | 802 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/rdf.py#L72-L78 | [
"def",
"calculate_pore_diameter",
"(",
"self",
")",
":",
"self",
".",
"pore_diameter",
",",
"self",
".",
"pore_closest_atom",
"=",
"pore_diameter",
"(",
"self",
".",
"elements",
",",
"self",
".",
"coordinates",
")",
"self",
".",
"properties",
"[",
"'pore_diame... |
Load and installed metrics plugins . | def load_plugins ( group = 'metrics.plugin.10' ) : # on using entrypoints: # http://stackoverflow.com/questions/774824/explain-python-entry-points file_processors = [ ] build_processors = [ ] for ep in pkg_resources . iter_entry_points ( group , name = None ) : log . debug ( 'loading \'%s\'' , ep ) plugin = ep . load (... | 803 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/plugins.py#L11-L25 | [
"def",
"_bsecurate_cli_compare_basis_files",
"(",
"args",
")",
":",
"ret",
"=",
"curate",
".",
"compare_basis_files",
"(",
"args",
".",
"file1",
",",
"args",
".",
"file2",
",",
"args",
".",
"readfmt1",
",",
"args",
".",
"readfmt2",
",",
"args",
".",
"uncon... |
Returns a case object from the given input file object . The data format may be optionally specified . | def read_case ( input , format = None ) : # Map of data file types to readers. format_map = { "matpower" : MATPOWERReader , "psse" : PSSEReader , "pickle" : PickleReader } # Read case data. if format_map . has_key ( format ) : reader_klass = format_map [ format ] reader = reader_klass ( ) case = reader . read ( input )... | 804 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/main.py#L48-L74 | [
"def",
"_sync",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_opcount",
">",
"self",
".",
"checkpoint_operations",
"or",
"datetime",
".",
"now",
"(",
")",
">",
"self",
".",
"_last_sync",
"+",
"self",
".",
"checkpoint_timeout",
")",
":",
"self",
".",... |
Detects the format of a network data file according to the file extension and the header . | def detect_data_file ( input , file_name = "" ) : _ , ext = os . path . splitext ( file_name ) if ext == ".m" : line = input . readline ( ) # first line if line . startswith ( "function" ) : type = "matpower" logger . info ( "Recognised MATPOWER data file." ) elif line . startswith ( "Bus.con" or line . startswith ( "%... | 805 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/main.py#L80-L109 | [
"async",
"def",
"_wait",
"(",
"self",
",",
"entity_type",
",",
"entity_id",
",",
"action",
",",
"predicate",
"=",
"None",
")",
":",
"q",
"=",
"asyncio",
".",
"Queue",
"(",
"loop",
"=",
"self",
".",
"_connector",
".",
"loop",
")",
"async",
"def",
"cal... |
Writes the case data in Graphviz DOT language . | def write ( self , file_or_filename , prog = None , format = 'xdot' ) : if prog is None : file = super ( DotWriter , self ) . write ( file_or_filename ) else : buf = StringIO . StringIO ( ) super ( DotWriter , self ) . write ( buf ) buf . seek ( 0 ) data = self . create ( buf . getvalue ( ) , prog , format ) if isinsta... | 806 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/dot.py#L71-L100 | [
"def",
"unchunk",
"(",
"self",
")",
":",
"if",
"self",
".",
"padding",
"!=",
"len",
"(",
"self",
".",
"shape",
")",
"*",
"(",
"0",
",",
")",
":",
"shape",
"=",
"self",
".",
"values",
".",
"shape",
"arr",
"=",
"empty",
"(",
"shape",
",",
"dtype"... |
Writes bus data to file . | def write_bus_data ( self , file , padding = " " ) : for bus in self . case . buses : attrs = [ '%s="%s"' % ( k , v ) for k , v in self . bus_attr . iteritems ( ) ] # attrs.insert(0, 'label="%s"' % bus.name) attr_str = ", " . join ( attrs ) file . write ( "%s%s [%s];\n" % ( padding , bus . name , attr_str... | 807 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/dot.py#L114-L122 | [
"def",
"_unwrap_result",
"(",
"action",
",",
"result",
")",
":",
"if",
"not",
"result",
":",
"return",
"elif",
"action",
"in",
"{",
"'DeleteItem'",
",",
"'PutItem'",
",",
"'UpdateItem'",
"}",
":",
"return",
"_unwrap_delete_put_update_item",
"(",
"result",
")",... |
Writes branch data in Graphviz DOT language . | def write_branch_data ( self , file , padding = " " ) : attrs = [ '%s="%s"' % ( k , v ) for k , v in self . branch_attr . iteritems ( ) ] attr_str = ", " . join ( attrs ) for br in self . case . branches : file . write ( "%s%s -> %s [%s];\n" % ( padding , br . from_bus . name , br . to_bus . name , attr_str ) ) | 808 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/dot.py#L125-L133 | [
"def",
"_batch_norm_new_params",
"(",
"input_shape",
",",
"rng",
",",
"axis",
"=",
"(",
"0",
",",
"1",
",",
"2",
")",
",",
"center",
"=",
"True",
",",
"scale",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"del",
"rng",
",",
"kwargs",
"axis",
"... |
Write generator data in Graphviz DOT language . | def write_generator_data ( self , file , padding = " " ) : attrs = [ '%s="%s"' % ( k , v ) for k , v in self . gen_attr . iteritems ( ) ] attr_str = ", " . join ( attrs ) edge_attrs = [ '%s="%s"' % ( k , v ) for k , v in { } . iteritems ( ) ] edge_attr_str = ", " . join ( edge_attrs ) for g in self . case . generato... | 809 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/dot.py#L136-L151 | [
"def",
"_batch_norm_new_params",
"(",
"input_shape",
",",
"rng",
",",
"axis",
"=",
"(",
"0",
",",
"1",
",",
"2",
")",
",",
"center",
"=",
"True",
",",
"scale",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"del",
"rng",
",",
"kwargs",
"axis",
"... |
Creates and returns a representation of the graph using the Graphviz layout program given by prog according to the given format . | def create ( self , dotdata , prog = "dot" , format = "xdot" ) : import os , tempfile from dot2tex . dotparsing import find_graphviz # Map Graphviz executable names to their paths. progs = find_graphviz ( ) if progs is None : logger . warning ( "GraphViz executables not found." ) return None if not progs . has_key ( pr... | 810 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/dot.py#L157-L235 | [
"def",
"cleanup",
"(",
"self",
")",
":",
"self",
".",
"_processing_stop",
"=",
"True",
"self",
".",
"_wakeup_processing_thread",
"(",
")",
"self",
".",
"_processing_stopped_event",
".",
"wait",
"(",
"3",
")"
] |
compute output in XML format . | def format ( file_metrics , build_metrics ) : def indent ( elem , level = 0 ) : i = "\n" + level * " " if len ( elem ) : if not elem . text or not elem . text . strip ( ) : elem . text = i + " " if not elem . tail or not elem . tail . strip ( ) : elem . tail = i for elem in elem : indent ( elem , level + 1 ) if not e... | 811 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/outputformat_xml.py#L16-L59 | [
"def",
"defBoundary",
"(",
"self",
")",
":",
"self",
".",
"BoroCnstNatAll",
"=",
"np",
".",
"zeros",
"(",
"self",
".",
"StateCount",
")",
"+",
"np",
".",
"nan",
"# Find the natural borrowing constraint conditional on next period's state",
"for",
"j",
"in",
"range"... |
Asks the user his opinion . | def ask ( message = 'Are you sure? [y/N]' ) : agree = False answer = raw_input ( message ) . lower ( ) if answer . startswith ( 'y' ) : agree = True return agree | 812 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L45-L51 | [
"def",
"synchronizeLayout",
"(",
"primary",
",",
"secondary",
",",
"surface_size",
")",
":",
"primary",
".",
"configure_bound",
"(",
"surface_size",
")",
"secondary",
".",
"configure_bound",
"(",
"surface_size",
")",
"# Check for key size.",
"if",
"(",
"primary",
... |
What do you expect? | def main ( prog_args = None ) : if prog_args is None : prog_args = sys . argv parser = optparse . OptionParser ( ) parser . usage = """Usage: %[prog] [options] [<path>]""" parser . add_option ( "-t" , "--test-program" , dest = "test_program" , default = "nose" , help = "specifies the test-program to use. Valid values" ... | 813 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L235-L288 | [
"def",
"write_tables",
"(",
"fname",
",",
"table_names",
"=",
"None",
",",
"prefix",
"=",
"None",
",",
"compress",
"=",
"False",
",",
"local",
"=",
"False",
")",
":",
"if",
"table_names",
"is",
"None",
":",
"table_names",
"=",
"list_tables",
"(",
")",
... |
Checks if configuration is ok . | def check_configuration ( self , file_path , test_program , custom_args ) : # checking filepath if not os . path . isdir ( file_path ) : raise InvalidFilePath ( "INVALID CONFIGURATION: file path %s is not a directory" % os . path . abspath ( file_path ) ) if not test_program in IMPLEMENTED_TEST_PROGRAMS : raise Invalid... | 814 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L88-L101 | [
"def",
"fetch",
"(",
"self",
")",
":",
"if",
"self",
".",
"_file_path",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_file_path",
"temp_path",
"=",
"self",
".",
"context",
".",
"work_path",
"if",
"self",
".",
"_content_hash",
"is",
"not",
"None",
... |
Checks if the test program is available in the python environnement | def check_dependencies ( self ) : if self . test_program == 'nose' : try : import nose except ImportError : sys . exit ( 'Nosetests is not available on your system. Please install it and try to run it again' ) if self . test_program == 'py' : try : import py except : sys . exit ( 'py.test is not available on your syste... | 815 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L103-L129 | [
"def",
"unindex_layers_with_issues",
"(",
"self",
",",
"use_cache",
"=",
"False",
")",
":",
"from",
"hypermap",
".",
"aggregator",
".",
"models",
"import",
"Issue",
",",
"Layer",
",",
"Service",
"from",
"django",
".",
"contrib",
".",
"contenttypes",
".",
"mo... |
Returns the full command to be executed at runtime | def get_cmd ( self ) : cmd = None if self . test_program in ( 'nose' , 'nosetests' ) : cmd = "nosetests %s" % self . file_path elif self . test_program == 'django' : executable = "%s/manage.py" % self . file_path if os . path . exists ( executable ) : cmd = "python %s/manage.py test" % self . file_path else : cmd = "dj... | 816 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L132-L164 | [
"def",
"deletecols",
"(",
"X",
",",
"cols",
")",
":",
"if",
"isinstance",
"(",
"cols",
",",
"str",
")",
":",
"cols",
"=",
"cols",
".",
"split",
"(",
"','",
")",
"retain",
"=",
"[",
"n",
"for",
"n",
"in",
"X",
".",
"dtype",
".",
"names",
"if",
... |
Returns True if the file is not ignored | def include ( self , path ) : for extension in IGNORE_EXTENSIONS : if path . endswith ( extension ) : return False parts = path . split ( os . path . sep ) for part in parts : if part in self . ignore_dirs : return False return True | 817 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L167-L176 | [
"def",
"_conn_string_adodbapi",
"(",
"self",
",",
"db_key",
",",
"instance",
"=",
"None",
",",
"conn_key",
"=",
"None",
",",
"db_name",
"=",
"None",
")",
":",
"if",
"instance",
":",
"_",
",",
"host",
",",
"username",
",",
"password",
",",
"database",
"... |
Extracts differences between lists . For debug purposes | def diff_list ( self , list1 , list2 ) : for key in list1 : if key in list2 and list2 [ key ] != list1 [ key ] : print key elif key not in list2 : print key | 818 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L205-L211 | [
"def",
"schedule",
"(",
"self",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# if the func is already a job object, just schedule that directly.",
"if",
"isinstance",
"(",
"func",
",",
"Job",
")",
":",
"job",
"=",
"func",
"# else, turn it i... |
Runs the appropriate command | def run ( self , cmd ) : print datetime . datetime . now ( ) output = subprocess . Popen ( cmd , shell = True ) output = output . communicate ( ) [ 0 ] print output | 819 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L213-L218 | [
"def",
"start",
"(",
"st_reg_number",
")",
":",
"#st_reg_number = str(st_reg_number)",
"weights",
"=",
"[",
"4",
",",
"3",
",",
"2",
",",
"9",
",",
"8",
",",
"7",
",",
"6",
",",
"5",
",",
"4",
",",
"3",
",",
"2",
"]",
"digits",
"=",
"st_reg_number"... |
Main loop daemon . | def loop ( self ) : while True : sleep ( 1 ) new_file_list = self . walk ( self . file_path , { } ) if new_file_list != self . file_list : if self . debug : self . diff_list ( new_file_list , self . file_list ) self . run_tests ( ) self . file_list = new_file_list | 820 | https://github.com/brunobord/tdaemon/blob/733b5bddb4b12bc3db326a192ce5606f28768307/tdaemon.py#L224-L233 | [
"def",
"set_attrs",
"(",
"self",
")",
":",
"self",
".",
"attrs",
".",
"table_type",
"=",
"str",
"(",
"self",
".",
"table_type",
")",
"self",
".",
"attrs",
".",
"index_cols",
"=",
"self",
".",
"index_cols",
"(",
")",
"self",
".",
"attrs",
".",
"values... |
compute output in JSON format . | def format ( file_metrics , build_metrics ) : metrics = { 'files' : file_metrics } if build_metrics : metrics [ 'build' ] = build_metrics body = json . dumps ( metrics , sort_keys = True , indent = 4 ) + '\n' return body | 821 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/outputformat_json.py#L9-L15 | [
"def",
"aux",
"(",
"self",
",",
"aux",
")",
":",
"if",
"aux",
"==",
"self",
".",
"_aux",
":",
"return",
"if",
"self",
".",
"_aux",
":",
"self",
".",
"_manager",
".",
"port_manager",
".",
"release_tcp_port",
"(",
"self",
".",
"_aux",
",",
"self",
".... |
Returns the linear equality and inequality constraints . | def split_linear_constraints ( A , l , u ) : ieq = [ ] igt = [ ] ilt = [ ] ibx = [ ] for i in range ( len ( l ) ) : if abs ( u [ i ] - l [ i ] ) <= EPS : ieq . append ( i ) elif ( u [ i ] > 1e10 ) and ( l [ i ] > - 1e10 ) : igt . append ( i ) elif ( l [ i ] <= - 1e10 ) and ( u [ i ] < 1e10 ) : ilt . append ( i ) elif (... | 822 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L472-L496 | [
"def",
"create_stream_subscription",
"(",
"self",
",",
"stream",
",",
"on_data",
",",
"timeout",
"=",
"60",
")",
":",
"options",
"=",
"rest_pb2",
".",
"StreamSubscribeRequest",
"(",
")",
"options",
".",
"stream",
"=",
"stream",
"manager",
"=",
"WebSocketSubscr... |
Computes the partial derivative of power injection w . r . t . voltage . | def dSbus_dV ( Y , V ) : I = Y * V diagV = spdiag ( V ) diagIbus = spdiag ( I ) diagVnorm = spdiag ( div ( V , abs ( V ) ) ) # Element-wise division. dS_dVm = diagV * conj ( Y * diagVnorm ) + conj ( diagIbus ) * diagVnorm dS_dVa = 1j * diagV * conj ( diagIbus - Y * diagV ) return dS_dVm , dS_dVa | 823 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L502-L518 | [
"def",
"json_options_to_metadata",
"(",
"options",
",",
"add_brackets",
"=",
"True",
")",
":",
"try",
":",
"options",
"=",
"loads",
"(",
"'{'",
"+",
"options",
"+",
"'}'",
"if",
"add_brackets",
"else",
"options",
")",
"return",
"options",
"except",
"ValueErr... |
Computes partial derivatives of branch currents w . r . t . voltage . | def dIbr_dV ( Yf , Yt , V ) : # nb = len(V) Vnorm = div ( V , abs ( V ) ) diagV = spdiag ( V ) diagVnorm = spdiag ( Vnorm ) dIf_dVa = Yf * 1j * diagV dIf_dVm = Yf * diagVnorm dIt_dVa = Yt * 1j * diagV dIt_dVm = Yt * diagVnorm # Compute currents. If = Yf * V It = Yt * V return dIf_dVa , dIf_dVm , dIt_dVa , dIt_dV... | 824 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L524-L544 | [
"def",
"read_json",
"(",
"cls",
",",
"filename",
")",
":",
"proxy",
"=",
"UnitySArrayProxy",
"(",
")",
"proxy",
".",
"load_from_json_record_files",
"(",
"_make_internal_url",
"(",
"filename",
")",
")",
"return",
"cls",
"(",
"_proxy",
"=",
"proxy",
")"
] |
Computes the branch power flow vector and the partial derivative of branch power flow w . r . t voltage . | def dSbr_dV ( Yf , Yt , V , buses , branches ) : nl = len ( branches ) nb = len ( V ) f = matrix ( [ l . from_bus . _i for l in branches ] ) t = matrix ( [ l . to_bus . _i for l in branches ] ) # Compute currents. If = Yf * V It = Yt * V Vnorm = div ( V , abs ( V ) ) diagVf = spdiag ( V [ f ] ) diagIf = spdiag ( If ) d... | 825 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L550-L593 | [
"def",
"stop_listener",
"(",
"self",
")",
":",
"if",
"self",
".",
"sock",
"is",
"not",
"None",
":",
"self",
".",
"sock",
".",
"close",
"(",
")",
"self",
".",
"sock",
"=",
"None",
"self",
".",
"tracks",
"=",
"{",
"}"
] |
Partial derivatives of squared flow magnitudes w . r . t voltage . | def dAbr_dV ( dSf_dVa , dSf_dVm , dSt_dVa , dSt_dVm , Sf , St ) : dAf_dPf = spdiag ( 2 * Sf . real ( ) ) dAf_dQf = spdiag ( 2 * Sf . imag ( ) ) dAt_dPt = spdiag ( 2 * St . real ( ) ) dAt_dQt = spdiag ( 2 * St . imag ( ) ) # Partial derivative of apparent power magnitude w.r.t voltage # phase angle. dAf_dVa = dAf_dPf * ... | 826 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L599-L621 | [
"def",
"save_key_file",
"(",
"self",
")",
":",
"if",
"self",
".",
"client_key",
"is",
"None",
":",
"return",
"if",
"self",
".",
"key_file_path",
":",
"key_file_path",
"=",
"self",
".",
"key_file_path",
"else",
":",
"key_file_path",
"=",
"self",
".",
"_get_... |
Computes 2nd derivatives of power injection w . r . t . voltage . | def d2Sbus_dV2 ( Ybus , V , lam ) : n = len ( V ) Ibus = Ybus * V diaglam = spdiag ( lam ) diagV = spdiag ( V ) A = spmatrix ( mul ( lam , V ) , range ( n ) , range ( n ) ) B = Ybus * diagV C = A * conj ( B ) D = Ybus . H * diagV E = conj ( diagV ) * ( D * diaglam - spmatrix ( D * lam , range ( n ) , range ( n ) ) ) F ... | 827 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L627-L648 | [
"def",
"json_options_to_metadata",
"(",
"options",
",",
"add_brackets",
"=",
"True",
")",
":",
"try",
":",
"options",
"=",
"loads",
"(",
"'{'",
"+",
"options",
"+",
"'}'",
"if",
"add_brackets",
"else",
"options",
")",
"return",
"options",
"except",
"ValueErr... |
Computes 2nd derivatives of complex branch current w . r . t . voltage . | def d2Ibr_dV2 ( Ybr , V , lam ) : nb = len ( V ) diaginvVm = spdiag ( div ( matrix ( 1.0 , ( nb , 1 ) ) , abs ( V ) ) ) Haa = spdiag ( mul ( - ( Ybr . T * lam ) , V ) ) Hva = - 1j * Haa * diaginvVm Hav = Hva Hvv = spmatrix ( [ ] , [ ] , [ ] , ( nb , nb ) ) return Haa , Hav , Hva , Hvv | 828 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L654-L665 | [
"def",
"to_json",
"(",
"self",
",",
"value",
",",
"preserve_ro",
")",
":",
"if",
"hasattr",
"(",
"value",
",",
"'to_json_dict'",
")",
":",
"return",
"value",
".",
"to_json_dict",
"(",
"preserve_ro",
")",
"elif",
"isinstance",
"(",
"value",
",",
"dict",
"... |
Computes 2nd derivatives of complex power flow w . r . t . voltage . | def d2Sbr_dV2 ( Cbr , Ybr , V , lam ) : nb = len ( V ) diaglam = spdiag ( lam ) diagV = spdiag ( V ) A = Ybr . H * diaglam * Cbr B = conj ( diagV ) * A * diagV D = spdiag ( mul ( ( A * V ) , conj ( V ) ) ) E = spdiag ( mul ( ( A . T * conj ( V ) ) , V ) ) F = B + B . T G = spdiag ( div ( matrix ( 1.0 , ( nb , 1 ) ) , a... | 829 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L671-L691 | [
"def",
"copy_uri_options",
"(",
"hosts",
",",
"mongodb_uri",
")",
":",
"if",
"\"?\"",
"in",
"mongodb_uri",
":",
"options",
"=",
"mongodb_uri",
".",
"split",
"(",
"\"?\"",
",",
"1",
")",
"[",
"1",
"]",
"else",
":",
"options",
"=",
"None",
"uri",
"=",
... |
Converts a sparse SciPy matrix into a sparse CVXOPT matrix . | def tocvx ( B ) : Bcoo = B . tocoo ( ) return spmatrix ( Bcoo . data , Bcoo . row . tolist ( ) , Bcoo . col . tolist ( ) ) | 830 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/cvxopf.py#L741-L745 | [
"def",
"delete_datapoints_in_time_range",
"(",
"self",
",",
"start_dt",
"=",
"None",
",",
"end_dt",
"=",
"None",
")",
":",
"start_dt",
"=",
"to_none_or_dt",
"(",
"validate_type",
"(",
"start_dt",
",",
"datetime",
".",
"datetime",
",",
"type",
"(",
"None",
")... |
Directly maps the agents and the tasks . | def doInteractions ( self , number = 1 ) : t0 = time . time ( ) for _ in range ( number ) : self . _oneInteraction ( ) elapsed = time . time ( ) - t0 logger . info ( "%d interactions executed in %.3fs." % ( number , elapsed ) ) return self . stepid | 831 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/discrete/experiment.py#L72-L83 | [
"def",
"parse_token_response",
"(",
"body",
",",
"scope",
"=",
"None",
")",
":",
"try",
":",
"params",
"=",
"json",
".",
"loads",
"(",
"body",
")",
"except",
"ValueError",
":",
"# Fall back to URL-encoded string, to support old implementations,",
"# including (at time... |
Exciter model . | def exciter ( self , Xexc , Pexc , Vexc ) : exciters = self . exciters F = zeros ( Xexc . shape ) typ1 = [ e . generator . _i for e in exciters if e . model == CONST_EXCITATION ] typ2 = [ e . generator . _i for e in exciters if e . model == IEEE_DC1A ] # Exciter type 1: constant excitation F [ typ1 , : ] = 0.0 # Excite... | 832 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dyn.py#L409-L464 | [
"def",
"OnAdjustVolume",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"volume",
"=",
"self",
".",
"player",
".",
"audio_get_volume",
"(",
")",
"if",
"event",
".",
"GetWheelRotation",
"(",
")",
"<",
"0",
":",
"self",
".",
"volume",
"=",
"max",
"(... |
Governor model . | def governor ( self , Xgov , Pgov , Vgov ) : governors = self . governors omegas = 2 * pi * self . freq F = zeros ( Xgov . shape ) typ1 = [ g . generator . _i for g in governors if g . model == CONST_POWER ] typ2 = [ g . generator . _i for g in governors if g . model == GENERAL_IEEE ] # Governor type 1: constant power ... | 833 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dyn.py#L467-L530 | [
"def",
"issueViaEmail",
"(",
"self",
",",
"issuer",
",",
"email",
",",
"product",
",",
"templateData",
",",
"domainName",
",",
"httpPort",
"=",
"80",
")",
":",
"ticket",
"=",
"self",
".",
"createTicket",
"(",
"issuer",
",",
"unicode",
"(",
"email",
",",
... |
Generator model . | def generator ( self , Xgen , Xexc , Xgov , Vgen ) : generators = self . dyn_generators omegas = 2 * pi * self . freq F = zeros ( Xgen . shape ) typ1 = [ g . _i for g in generators if g . model == CLASSICAL ] typ2 = [ g . _i for g in generators if g . model == FOURTH_ORDER ] # Generator type 1: classical model omega = ... | 834 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dyn.py#L533-L595 | [
"def",
"_add_dependency",
"(",
"self",
",",
"dependency",
",",
"var_name",
"=",
"None",
")",
":",
"if",
"var_name",
"is",
"None",
":",
"var_name",
"=",
"next",
"(",
"self",
".",
"temp_var_names",
")",
"# Don't add duplicate dependencies",
"if",
"(",
"dependenc... |
Writes case data to file in ReStructuredText format . | def _write_data ( self , file ) : self . write_case_data ( file ) file . write ( "Bus Data\n" ) file . write ( "-" * 8 + "\n" ) self . write_bus_data ( file ) file . write ( "\n" ) file . write ( "Branch Data\n" ) file . write ( "-" * 11 + "\n" ) self . write_branch_data ( file ) file . write ( "\n" ) file . write ( "G... | 835 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/rst.py#L40-L58 | [
"def",
"utilization",
"(",
"prev",
",",
"curr",
",",
"counters",
")",
":",
"busy_prop",
",",
"idle_prop",
"=",
"counters",
"pb",
"=",
"getattr",
"(",
"prev",
",",
"busy_prop",
")",
"pi",
"=",
"getattr",
"(",
"prev",
",",
"idle_prop",
")",
"cb",
"=",
... |
Writes bus data to a ReST table . | def write_bus_data ( self , file ) : report = CaseReport ( self . case ) buses = self . case . buses col_width = 8 col_width_2 = col_width * 2 + 1 col1_width = 6 sep = "=" * 6 + " " + ( "=" * col_width + " " ) * 6 + "\n" file . write ( sep ) # Line one of column headers file . write ( "Name" . center ( col1_width ) + "... | 836 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/rst.py#L87-L146 | [
"def",
"__isOpenThreadWpanRunning",
"(",
"self",
")",
":",
"print",
"'call __isOpenThreadWpanRunning'",
"if",
"self",
".",
"__stripValue",
"(",
"self",
".",
"__sendCommand",
"(",
"WPANCTL_CMD",
"+",
"'getprop -v NCP:State'",
")",
"[",
"0",
"]",
")",
"==",
"'associ... |
Writes component numbers to a table . | def write_how_many ( self , file ) : report = CaseReport ( self . case ) # Map component labels to attribute names components = [ ( "Bus" , "n_buses" ) , ( "Generator" , "n_generators" ) , ( "Committed Generator" , "n_online_generators" ) , ( "Load" , "n_loads" ) , ( "Fixed Load" , "n_fixed_loads" ) , ( "Despatchable L... | 837 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/rst.py#L312-L355 | [
"def",
"get_license_assignment_manager",
"(",
"service_instance",
")",
":",
"log",
".",
"debug",
"(",
"'Retrieving license assignment manager'",
")",
"try",
":",
"lic_assignment_manager",
"=",
"service_instance",
".",
"content",
".",
"licenseManager",
".",
"licenseAssignm... |
Writes minimum and maximum values to a table . | def write_min_max ( self , file ) : report = CaseReport ( self . case ) col1_header = "Attribute" col1_width = 19 col2_header = "Minimum" col3_header = "Maximum" col_width = 22 sep = "=" * col1_width + " " + "=" * col_width + " " + "=" * col_width + "\n" # Row headers file . write ( sep ) file . write ( "%s" % col1_hea... | 838 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/rst.py#L438-L478 | [
"def",
"stop",
"(",
"self",
")",
":",
"for",
"client",
"in",
"self",
".",
"_snippet_clients",
".",
"values",
"(",
")",
":",
"if",
"client",
".",
"is_alive",
":",
"self",
".",
"_device",
".",
"log",
".",
"debug",
"(",
"'Stopping SnippetClient<%s>.'",
",",... |
Return a name unique within a context based on the specified name . | def make_unique_name ( base , existing = [ ] , format = "%s_%s" ) : count = 2 name = base while name in existing : name = format % ( base , count ) count += 1 return name | 839 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/parsing_util.py#L167-L180 | [
"def",
"_merge_meta",
"(",
"self",
",",
"encoded_meta",
",",
"meta",
")",
":",
"new_meta",
"=",
"None",
"if",
"meta",
":",
"_meta",
"=",
"self",
".",
"_decode_meta",
"(",
"encoded_meta",
")",
"for",
"key",
",",
"value",
"in",
"six",
".",
"iteritems",
"... |
calls antlr4 on grammar file | def call_antlr4 ( arg ) : # pylint: disable=unused-argument, unused-variable antlr_path = os . path . join ( ROOT_DIR , "java" , "antlr-4.7-complete.jar" ) classpath = os . pathsep . join ( [ "." , "{:s}" . format ( antlr_path ) , "$CLASSPATH" ] ) generated = os . path . join ( ROOT_DIR , 'src' , 'pymoca' , 'generated'... | 840 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/setup.py#L74-L86 | [
"def",
"get_listing",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'listing'",
")",
":",
"allEvents",
"=",
"self",
".",
"get_allEvents",
"(",
")",
"openEvents",
"=",
"allEvents",
".",
"filter",
"(",
"registrationOpen",
"=",
"True",
"... |
Setup the package . | def setup_package ( ) : with open ( 'requirements.txt' , 'r' ) as req_file : install_reqs = req_file . read ( ) . split ( '\n' ) cmdclass_ = { 'antlr' : AntlrBuildCommand } cmdclass_ . update ( versioneer . get_cmdclass ( ) ) setup ( version = versioneer . get_version ( ) , name = 'pymoca' , maintainer = "James Goppert... | 841 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/setup.py#L89-L121 | [
"def",
"apply_binding",
"(",
"self",
",",
"binding",
",",
"msg_str",
",",
"destination",
"=",
"\"\"",
",",
"relay_state",
"=",
"\"\"",
",",
"response",
"=",
"False",
",",
"sign",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"# unless if BINDING_HTTP_AR... |
Creates the dialog body . Returns the widget that should have initial focus . | def body ( self , frame ) : master = Frame ( self ) master . pack ( padx = 5 , pady = 0 , expand = 1 , fill = BOTH ) title = Label ( master , text = "Buses" ) title . pack ( side = TOP ) bus_lb = self . bus_lb = Listbox ( master , selectmode = SINGLE , width = 10 ) bus_lb . pack ( side = LEFT ) for bus in self . case .... | 842 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/pylontk.py#L538-L558 | [
"def",
"remove_stale_javascripts",
"(",
"portal",
")",
":",
"logger",
".",
"info",
"(",
"\"Removing stale javascripts ...\"",
")",
"for",
"js",
"in",
"JAVASCRIPTS_TO_REMOVE",
":",
"logger",
".",
"info",
"(",
"\"Unregistering JS %s\"",
"%",
"js",
")",
"portal",
"."... |
Solves an optimal power flow and returns a results dictionary . | def solve ( self , solver_klass = None ) : # Start the clock. t0 = time ( ) # Build an OPF model with variables and constraints. om = self . _construct_opf_model ( self . case ) if om is None : return { "converged" : False , "output" : { "message" : "No Ref Bus." } } # Call the specific solver. # if self.opt["ve... | 843 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L79-L110 | [
"def",
"concatenate_not_none",
"(",
"l",
",",
"axis",
"=",
"0",
")",
":",
"# Get the indexes of the arrays in the list",
"mask",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"l",
")",
")",
":",
"if",
"l",
"[",
"i",
"]",
"is",
"not",
"No... |
Returns an OPF model . | def _construct_opf_model ( self , case ) : # Zero the case result attributes. self . case . reset ( ) base_mva = case . base_mva # Check for one reference bus. oneref , refs = self . _ref_check ( case ) if not oneref : #return {"status": "error"} None # Remove isolated components. bs , ln , gn = self . _remove_isolated... | 844 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L116-L190 | [
"def",
"append_to_multiple",
"(",
"self",
",",
"d",
",",
"value",
",",
"selector",
",",
"data_columns",
"=",
"None",
",",
"axes",
"=",
"None",
",",
"dropna",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"axes",
"is",
"not",
"None",
":",
"... |
Checks that there is only one reference bus . | def _ref_check ( self , case ) : refs = [ bus . _i for bus in case . buses if bus . type == REFERENCE ] if len ( refs ) == 1 : return True , refs else : logger . error ( "OPF requires a single reference bus." ) return False , refs | 845 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L193-L202 | [
"def",
"_initialize",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Start initializing data from %s\"",
",",
"self",
".",
"url",
")",
"resp",
"=",
"self",
".",
"get",
"(",
"self",
".",
"url",
",",
"verify",
"=",
"False",
",",
"proxie... |
Returns non - isolated case components . | def _remove_isolated ( self , case ) : # case.deactivate_isolated() buses = case . connected_buses branches = case . online_branches gens = case . online_generators return buses , branches , gens | 846 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L205-L213 | [
"def",
"user_deletemedia",
"(",
"mediaids",
",",
"*",
"*",
"kwargs",
")",
":",
"conn_args",
"=",
"_login",
"(",
"*",
"*",
"kwargs",
")",
"ret",
"=",
"{",
"}",
"try",
":",
"if",
"conn_args",
":",
"method",
"=",
"'user.deletemedia'",
"if",
"not",
"isinst... |
Converts single - block piecewise - linear costs into linear polynomial . | def _pwl1_to_poly ( self , generators ) : for g in generators : if ( g . pcost_model == PW_LINEAR ) and ( len ( g . p_cost ) == 2 ) : g . pwl_to_poly ( ) return generators | 847 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L216-L224 | [
"def",
"_normalize_port",
"(",
"scheme",
",",
"port",
")",
":",
"if",
"not",
"scheme",
":",
"return",
"port",
"if",
"port",
"and",
"port",
"!=",
"DEFAULT_PORT",
"[",
"scheme",
"]",
":",
"return",
"port"
] |
Returns the voltage angle variable set . | def _get_voltage_angle_var ( self , refs , buses ) : Va = array ( [ b . v_angle * ( pi / 180.0 ) for b in buses ] ) Vau = Inf * ones ( len ( buses ) ) Val = - Vau Vau [ refs ] = Va [ refs ] Val [ refs ] = Va [ refs ] return Variable ( "Va" , len ( buses ) , Va , Val , Vau ) | 848 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L230-L240 | [
"def",
"update_custom_field_options",
"(",
"self",
",",
"custom_field_key",
",",
"new_options",
",",
"keep_existing_options",
")",
":",
"custom_field_key",
"=",
"quote",
"(",
"custom_field_key",
",",
"''",
")",
"body",
"=",
"{",
"\"Options\"",
":",
"new_options",
... |
Returns the voltage magnitude variable set . | def _get_voltage_magnitude_var ( self , buses , generators ) : Vm = array ( [ b . v_magnitude for b in buses ] ) # For buses with generators initialise Vm from gen data. for g in generators : Vm [ g . bus . _i ] = g . v_magnitude Vmin = array ( [ b . v_min for b in buses ] ) Vmax = array ( [ b . v_max for b in buses ] ... | 849 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L243-L255 | [
"def",
"update_notebook_actions",
"(",
"self",
")",
":",
"if",
"self",
".",
"recent_notebooks",
":",
"self",
".",
"clear_recent_notebooks_action",
".",
"setEnabled",
"(",
"True",
")",
"else",
":",
"self",
".",
"clear_recent_notebooks_action",
".",
"setEnabled",
"(... |
Returns the generator active power set - point variable . | def _get_pgen_var ( self , generators , base_mva ) : Pg = array ( [ g . p / base_mva for g in generators ] ) Pmin = array ( [ g . p_min / base_mva for g in generators ] ) Pmax = array ( [ g . p_max / base_mva for g in generators ] ) return Variable ( "Pg" , len ( generators ) , Pg , Pmin , Pmax ) | 850 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L258-L266 | [
"def",
"get_mentions",
"(",
"self",
",",
"docs",
"=",
"None",
",",
"sort",
"=",
"False",
")",
":",
"result",
"=",
"[",
"]",
"if",
"docs",
":",
"docs",
"=",
"docs",
"if",
"isinstance",
"(",
"docs",
",",
"(",
"list",
",",
"tuple",
")",
")",
"else",... |
Returns the generator reactive power variable set . | def _get_qgen_var ( self , generators , base_mva ) : Qg = array ( [ g . q / base_mva for g in generators ] ) Qmin = array ( [ g . q_min / base_mva for g in generators ] ) Qmax = array ( [ g . q_max / base_mva for g in generators ] ) return Variable ( "Qg" , len ( generators ) , Qg , Qmin , Qmax ) | 851 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L269-L277 | [
"def",
"guess_extension",
"(",
"amimetype",
",",
"normalize",
"=",
"False",
")",
":",
"ext",
"=",
"_mimes",
".",
"guess_extension",
"(",
"amimetype",
")",
"if",
"ext",
"and",
"normalize",
":",
"# Normalize some common magic mis-interpreation",
"ext",
"=",
"{",
"... |
Returns non - linear constraints for OPF . | def _nln_constraints ( self , nb , nl ) : Pmis = NonLinearConstraint ( "Pmis" , nb ) Qmis = NonLinearConstraint ( "Qmis" , nb ) Sf = NonLinearConstraint ( "Sf" , nl ) St = NonLinearConstraint ( "St" , nl ) return Pmis , Qmis , Sf , St | 852 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L283-L291 | [
"def",
"iterstruct",
"(",
"self",
")",
":",
"from",
"rowgenerators",
".",
"rowpipe",
".",
"json",
"import",
"add_to_struct",
"json_headers",
"=",
"self",
".",
"json_headers",
"for",
"row",
"in",
"islice",
"(",
"self",
",",
"1",
",",
"None",
")",
":",
"# ... |
Returns a linear constraint enforcing constant power factor for dispatchable loads . | def _const_pf_constraints ( self , gn , base_mva ) : ivl = array ( [ i for i , g in enumerate ( gn ) if g . is_load and ( g . q_min != 0.0 or g . q_max != 0.0 ) ] ) vl = [ gn [ i ] for i in ivl ] nvl = len ( vl ) ng = len ( gn ) Pg = array ( [ g . p for g in vl ] ) / base_mva Qg = array ( [ g . q for g in vl ] ) / base... | 853 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L330-L384 | [
"def",
"remove",
"(",
"self",
",",
"uids",
":",
"Iterable",
"[",
"int",
"]",
")",
"->",
"None",
":",
"for",
"uid",
"in",
"uids",
":",
"self",
".",
"_recent",
".",
"discard",
"(",
"uid",
")",
"self",
".",
"_flags",
".",
"pop",
"(",
"uid",
",",
"... |
Returns the constraint on the branch voltage angle differences . | def _voltage_angle_diff_limit ( self , buses , branches ) : nb = len ( buses ) if not self . ignore_ang_lim : iang = [ i for i , b in enumerate ( branches ) if ( b . ang_min and ( b . ang_min > - 360.0 ) ) or ( b . ang_max and ( b . ang_max < 360.0 ) ) ] iangl = array ( [ i for i , b in enumerate ( branches ) if b . an... | 854 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L387-L430 | [
"def",
"make_param_dict_from_file",
"(",
"self",
",",
"path_to_params",
")",
":",
"# then we were given a path to a parameter file",
"param_list",
"=",
"list",
"(",
"csv",
".",
"reader",
"(",
"open",
"(",
"path_to_params",
",",
"\"rb\"",
")",
")",
")",
"# delete emp... |
Adds a variable to the model . | def add_var ( self , var ) : if var . name in [ v . name for v in self . vars ] : logger . error ( "Variable set named '%s' already exists." % var . name ) return var . i1 = self . var_N var . iN = self . var_N + var . N - 1 self . vars . append ( var ) | 855 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L731-L740 | [
"def",
"get_listing",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'listing'",
")",
":",
"allEvents",
"=",
"self",
".",
"get_allEvents",
"(",
")",
"openEvents",
"=",
"allEvents",
".",
"filter",
"(",
"registrationOpen",
"=",
"True",
"... |
Returns the variable set with the given name . | def get_var ( self , name ) : for var in self . vars : if var . name == name : return var else : raise ValueError | 856 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L750-L757 | [
"def",
"isSupportedContent",
"(",
"cls",
",",
"fileContent",
")",
":",
"magic",
"=",
"bytearray",
"(",
"fileContent",
")",
"[",
":",
"4",
"]",
"return",
"magic",
"==",
"p",
"(",
"'>I'",
",",
"0xfeedface",
")",
"or",
"magic",
"==",
"p",
"(",
"'>I'",
"... |
Returns the linear constraints . | def linear_constraints ( self ) : if self . lin_N == 0 : return None , array ( [ ] ) , array ( [ ] ) A = lil_matrix ( ( self . lin_N , self . var_N ) , dtype = float64 ) l = - Inf * ones ( self . lin_N ) u = - l for lin in self . lin_constraints : if lin . N : # non-zero number of rows to add Ak = lin . A # A for kth l... | 857 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L782-L818 | [
"def",
"ttl",
"(",
"self",
",",
"value",
")",
":",
"# get timer",
"timer",
"=",
"getattr",
"(",
"self",
",",
"Annotation",
".",
"__TIMER",
",",
"None",
")",
"# if timer is running, stop the timer",
"if",
"timer",
"is",
"not",
"None",
":",
"timer",
".",
"ca... |
Adds a constraint to the model . | def add_constraint ( self , con ) : if isinstance ( con , LinearConstraint ) : N , M = con . A . shape if con . name in [ c . name for c in self . lin_constraints ] : logger . error ( "Constraint set named '%s' already exists." % con . name ) return False else : con . i1 = self . lin_N # + 1 con . iN = self . lin_N + N... | 858 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/opf.py#L821-L854 | [
"def",
"register_dataframe_method",
"(",
"method",
")",
":",
"def",
"inner",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"class",
"AccessorMethod",
"(",
"object",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"pandas_obj",
")",
":",
"self",
"... |
Solves using the Interior Point OPTimizer . | def _solve ( self , x0 , A , l , u , xmin , xmax ) : # Indexes of constrained lines. il = [ i for i , ln in enumerate ( self . _ln ) if 0.0 < ln . rate_a < 1e10 ] nl2 = len ( il ) neqnln = 2 * self . _nb # no. of non-linear equality constraints niqnln = 2 * len ( il ) # no. of lines with constraints user_data = { "A" :... | 859 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ipopf.py#L44-L86 | [
"def",
"pack_rows",
"(",
"rows",
",",
"bitdepth",
")",
":",
"assert",
"bitdepth",
"<",
"8",
"assert",
"8",
"%",
"bitdepth",
"==",
"0",
"# samples per byte",
"spb",
"=",
"int",
"(",
"8",
"/",
"bitdepth",
")",
"def",
"make_byte",
"(",
"block",
")",
":",
... |
Applies branch outtages . | def doOutages ( self ) : assert len ( self . branchOutages ) == len ( self . market . case . branches ) weights = [ [ ( False , r ) , ( True , 1 - ( r ) ) ] for r in self . branchOutages ] for i , ln in enumerate ( self . market . case . branches ) : ln . online = weighted_choice ( weights [ i ] ) if ln . online == Fal... | 860 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/continuous/experiment.py#L133-L143 | [
"def",
"clean",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"clean",
"(",
")",
"# At least a poster (user) or a session key must be associated with",
"# the vote instance.",
"if",
"self",
".",
"voter",
"is",
"None",
"and",
"self",
".",
"anonymous_key",
"is",
"N... |
Returns the case to its original state . | def reset_case ( self ) : for bus in self . market . case . buses : bus . p_demand = self . pdemand [ bus ] for task in self . tasks : for g in task . env . generators : g . p = task . env . _g0 [ g ] [ "p" ] g . p_max = task . env . _g0 [ g ] [ "p_max" ] g . p_min = task . env . _g0 [ g ] [ "p_min" ] g . q = task . en... | 861 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/continuous/experiment.py#L146-L164 | [
"def",
"update_thumbnail",
"(",
"api_key",
",",
"api_secret",
",",
"video_key",
",",
"position",
"=",
"7.0",
",",
"*",
"*",
"kwargs",
")",
":",
"jwplatform_client",
"=",
"jwplatform",
".",
"Client",
"(",
"api_key",
",",
"api_secret",
")",
"logging",
".",
"... |
Do the given numer of episodes and return the rewards of each step as a list . | def doEpisodes ( self , number = 1 ) : for episode in range ( number ) : print "Starting episode %d." % episode # Initialise the profile cycle. if len ( self . profile . shape ) == 1 : # 1D array self . _pcycle = cycle ( self . profile ) else : assert self . profile . shape [ 0 ] >= number self . _pcycle = cycle ( self... | 862 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/continuous/experiment.py#L170-L199 | [
"def",
"arcball_constrain_to_axis",
"(",
"point",
",",
"axis",
")",
":",
"v",
"=",
"np",
".",
"array",
"(",
"point",
",",
"dtype",
"=",
"np",
".",
"float64",
",",
"copy",
"=",
"True",
")",
"a",
"=",
"np",
".",
"array",
"(",
"axis",
",",
"dtype",
... |
Sets initial conditions for the experiment . | def reset ( self ) : self . stepid = 0 for task , agent in zip ( self . tasks , self . agents ) : task . reset ( ) agent . module . reset ( ) agent . history . reset ( ) | 863 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/continuous/experiment.py#L249-L258 | [
"def",
"read_avro",
"(",
"file_path_or_buffer",
",",
"schema",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"file_path_or_buffer",
",",
"six",
".",
"string_types",
")",
":",
"with",
"open",
"(",
"file_path_or_buffer",
",",
"'rb'",... |
Update the propensities for all actions . The propensity for last action chosen will be updated using the feedback value that resulted from performing the action . | def _updatePropensities ( self , lastState , lastAction , reward ) : phi = self . recency for action in range ( self . module . numActions ) : carryOver = ( 1 - phi ) * self . module . getValue ( lastState , action ) experience = self . _experience ( lastState , action , lastAction , reward ) self . module . updateValu... | 864 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/roth_erev.py#L136-L154 | [
"def",
"union",
"(",
"self",
",",
"other",
")",
":",
"union",
"=",
"Rect",
"(",
")",
"lib",
".",
"SDL_UnionRect",
"(",
"self",
".",
"_ptr",
",",
"other",
".",
"_ptr",
",",
"union",
".",
"_ptr",
")",
"return",
"union"
] |
Proportional probability method . | def _forwardImplementation ( self , inbuf , outbuf ) : assert self . module propensities = self . module . getActionValues ( 0 ) summedProps = sum ( propensities ) probabilities = propensities / summedProps action = eventGenerator ( probabilities ) # action = drawIndex(probabilities) outbuf [ : ] = scipy . array... | 865 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/roth_erev.py#L254-L267 | [
"def",
"_parse_args",
"(",
")",
":",
"token_file",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"'~/.nikeplus_access_token'",
")",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Export NikePlus data to CSV'",
")",
"parser",
".",
... |
Writes case data to file in Excel format . | def write ( self , file_or_filename ) : self . book = Workbook ( ) self . _write_data ( None ) self . book . save ( file_or_filename ) | 866 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L38-L43 | [
"def",
"sample",
"(",
"self",
",",
"features",
")",
":",
"logits",
",",
"losses",
"=",
"self",
"(",
"features",
")",
"# pylint: disable=not-callable",
"if",
"self",
".",
"_target_modality_is_real",
":",
"return",
"logits",
",",
"logits",
",",
"losses",
"# Raw ... |
Writes bus data to an Excel spreadsheet . | def write_bus_data ( self , file ) : bus_sheet = self . book . add_sheet ( "Buses" ) for i , bus in enumerate ( self . case . buses ) : for j , attr in enumerate ( BUS_ATTRS ) : bus_sheet . write ( i , j , getattr ( bus , attr ) ) | 867 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L56-L63 | [
"def",
"_get_stddevs",
"(",
"self",
",",
"C",
",",
"sites",
",",
"pga1100",
",",
"sigma_pga",
",",
"stddev_types",
")",
":",
"std_intra",
"=",
"self",
".",
"_compute_intra_event_std",
"(",
"C",
",",
"sites",
".",
"vs30",
",",
"pga1100",
",",
"sigma_pga",
... |
Writes branch data to an Excel spreadsheet . | def write_branch_data ( self , file ) : branch_sheet = self . book . add_sheet ( "Branches" ) for i , branch in enumerate ( self . case . branches ) : for j , attr in enumerate ( BRANCH_ATTRS ) : branch_sheet . write ( i , j , getattr ( branch , attr ) ) | 868 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L66-L73 | [
"def",
"_get_observed_mmax",
"(",
"catalogue",
",",
"config",
")",
":",
"if",
"config",
"[",
"'input_mmax'",
"]",
":",
"obsmax",
"=",
"config",
"[",
"'input_mmax'",
"]",
"if",
"config",
"[",
"'input_mmax_uncertainty'",
"]",
":",
"return",
"config",
"[",
"'in... |
Write generator data to file . | def write_generator_data ( self , file ) : generator_sheet = self . book . add_sheet ( "Generators" ) for j , generator in enumerate ( self . case . generators ) : i = generator . bus . _i for k , attr in enumerate ( GENERATOR_ATTRS ) : generator_sheet . write ( j , 0 , i ) | 869 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L76-L84 | [
"def",
"defBoundary",
"(",
"self",
")",
":",
"self",
".",
"BoroCnstNatAll",
"=",
"np",
".",
"zeros",
"(",
"self",
".",
"StateCount",
")",
"+",
"np",
".",
"nan",
"# Find the natural borrowing constraint conditional on next period's state",
"for",
"j",
"in",
"range"... |
Writes case data as CSV . | def write ( self , file_or_filename ) : if isinstance ( file_or_filename , basestring ) : file = open ( file_or_filename , "wb" ) else : file = file_or_filename self . writer = csv . writer ( file ) super ( CSVWriter , self ) . write ( file ) | 870 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L112-L122 | [
"def",
"unbind",
"(",
"self",
",",
"devices_to_unbind",
")",
":",
"if",
"self",
".",
"entity_api_key",
"==",
"\"\"",
":",
"return",
"{",
"'status'",
":",
"'failure'",
",",
"'response'",
":",
"'No API key found in request'",
"}",
"url",
"=",
"self",
".",
"bas... |
Writes the case data as CSV . | def write_case_data ( self , file ) : writer = self . _get_writer ( file ) writer . writerow ( [ "Name" , "base_mva" ] ) writer . writerow ( [ self . case . name , self . case . base_mva ] ) | 871 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L125-L130 | [
"def",
"dump",
"(",
"self",
")",
":",
"assert",
"self",
".",
"database",
"is",
"not",
"None",
"cmd",
"=",
"\"SELECT count from {} WHERE rowid={}\"",
"self",
".",
"_execute",
"(",
"cmd",
".",
"format",
"(",
"self",
".",
"STATE_INFO_TABLE",
",",
"self",
".",
... |
Writes bus data as CSV . | def write_bus_data ( self , file ) : writer = self . _get_writer ( file ) writer . writerow ( BUS_ATTRS ) for bus in self . case . buses : writer . writerow ( [ getattr ( bus , attr ) for attr in BUS_ATTRS ] ) | 872 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L133-L139 | [
"def",
"unbind",
"(",
"self",
",",
"devices_to_unbind",
")",
":",
"if",
"self",
".",
"entity_api_key",
"==",
"\"\"",
":",
"return",
"{",
"'status'",
":",
"'failure'",
",",
"'response'",
":",
"'No API key found in request'",
"}",
"url",
"=",
"self",
".",
"bas... |
Writes branch data as CSV . | def write_branch_data ( self , file ) : writer = self . _get_writer ( file ) writer . writerow ( BRANCH_ATTRS ) for branch in self . case . branches : writer . writerow ( [ getattr ( branch , a ) for a in BRANCH_ATTRS ] ) | 873 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L142-L148 | [
"def",
"unbind",
"(",
"self",
",",
"devices_to_unbind",
")",
":",
"if",
"self",
".",
"entity_api_key",
"==",
"\"\"",
":",
"return",
"{",
"'status'",
":",
"'failure'",
",",
"'response'",
":",
"'No API key found in request'",
"}",
"url",
"=",
"self",
".",
"bas... |
Write generator data as CSV . | def write_generator_data ( self , file ) : writer = self . _get_writer ( file ) writer . writerow ( [ "bus" ] + GENERATOR_ATTRS ) for g in self . case . generators : i = g . bus . _i writer . writerow ( [ i ] + [ getattr ( g , a ) for a in GENERATOR_ATTRS ] ) | 874 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/excel.py#L151-L159 | [
"def",
"unbind",
"(",
"self",
",",
"devices_to_unbind",
")",
":",
"if",
"self",
".",
"entity_api_key",
"==",
"\"\"",
":",
"return",
"{",
"'status'",
":",
"'failure'",
",",
"'response'",
":",
"'No API key found in request'",
"}",
"url",
"=",
"self",
".",
"bas... |
Computes cleared offers and bids . | def run ( self ) : # Start the clock. t0 = time . time ( ) # Manage reactive power offers/bids. haveQ = self . _isReactiveMarket ( ) # Withhold offers/bids outwith optional price limits. self . _withholdOffbids ( ) # Convert offers/bids to pwl functions and update limits. self . _offbidToCase ( ) # Compute dispatch poi... | 875 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/smart_market.py#L131-L166 | [
"def",
"_ssweek_to_gregorian",
"(",
"ssweek_year",
",",
"ssweek_week",
",",
"ssweek_day",
")",
":",
"year_start",
"=",
"_ssweek_year_start",
"(",
"ssweek_year",
")",
"return",
"year_start",
"+",
"dt",
".",
"timedelta",
"(",
"days",
"=",
"ssweek_day",
"-",
"1",
... |
Computes dispatch points and LMPs using OPF . | def _runOPF ( self ) : if self . decommit : solver = UDOPF ( self . case , dc = ( self . locationalAdjustment == "dc" ) ) elif self . locationalAdjustment == "dc" : solver = OPF ( self . case , dc = True ) else : solver = OPF ( self . case , dc = False , opt = { "verbose" : True } ) self . _solution = solver . solve ( ... | 876 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/smart_market.py#L266-L281 | [
"def",
"surviors_are_inconsistent",
"(",
"survivor_mapping",
":",
"Mapping",
"[",
"BaseEntity",
",",
"Set",
"[",
"BaseEntity",
"]",
"]",
")",
"->",
"Set",
"[",
"BaseEntity",
"]",
":",
"victim_mapping",
"=",
"set",
"(",
")",
"for",
"victim",
"in",
"itt",
".... |
Return a JSON string representation of a Python data structure . | def encode ( self , o ) : # This doesn't pass the iterator directly to ''.join() because it # sucks at reporting exceptions. It's going to do this internally # anyway because it uses PySequence_Fast or similar. chunks = list ( self . iterencode ( o ) ) return '' . join ( chunks ) | 877 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/simplejson/encoder.py#L278-L289 | [
"def",
"removeAllEntitlements",
"(",
"self",
",",
"appId",
")",
":",
"params",
"=",
"{",
"\"f\"",
":",
"\"json\"",
",",
"\"appId\"",
":",
"appId",
"}",
"url",
"=",
"self",
".",
"_url",
"+",
"\"/licenses/removeAllEntitlements\"",
"return",
"self",
".",
"_post... |
use processors to compute file metrics . | def compute_file_metrics ( processors , language , key , token_list ) : # multiply iterator tli = itertools . tee ( token_list , len ( processors ) ) metrics = OrderedDict ( ) # reset all processors for p in processors : p . reset ( ) # process all tokens for p , tl in zip ( processors , tli ) : p . process_file ( lang... | 878 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/compute.py#L8-L26 | [
"def",
"_post_process_yaml_data",
"(",
"self",
",",
"fixture_data",
":",
"Dict",
"[",
"str",
",",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
",",
"relationship_columns",
":",
"Set",
"[",
"str",
"]",
",",
")",
"->",
"Tuple",
"[",
"Dict",
"[",
"str",
",... |
This methods load the IWNLP . Lemmatizer json file and creates a dictionary of lowercased forms which maps each form to its possible lemmas . | def load ( self , lemmatizer_path ) : self . lemmatizer = { } with io . open ( lemmatizer_path , encoding = 'utf-8' ) as data_file : raw = json . load ( data_file ) for entry in raw : self . lemmatizer [ entry [ "Form" ] ] = entry [ "Lemmas" ] self . apply_blacklist ( ) | 879 | https://github.com/Liebeck/IWNLP-py/blob/fd4b81769317476eac0487396cce0faf482a1913/iwnlp/iwnlp_wrapper.py#L14-L24 | [
"def",
"_print_duration",
"(",
"self",
")",
":",
"duration",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"_start_time",
")",
"self",
".",
"_print",
"(",
"datetime",
".",
"timedelta",
"(",
"seconds",
"=",
"duration",
")",
")"
] |
Writes the case data to file . | def write ( self , file_or_filename ) : if isinstance ( file_or_filename , basestring ) : file = None try : file = open ( file_or_filename , "wb" ) except Exception , detail : logger . error ( "Error opening %s." % detail ) finally : if file is not None : self . _write_data ( file ) file . close ( ) else : file = file_... | 880 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/common.py#L64-L81 | [
"def",
"listrecords",
"(",
"*",
"*",
"kwargs",
")",
":",
"record_dumper",
"=",
"serializer",
"(",
"kwargs",
"[",
"'metadataPrefix'",
"]",
")",
"e_tree",
",",
"e_listrecords",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"result",
"=",
"get_records",
"(",
"... |
The action vector is stripped and the only element is cast to integer and given to the super class . | def performAction ( self , action ) : self . t += 1 super ( ProfitTask , self ) . performAction ( int ( action [ 0 ] ) ) self . samples += 1 | 881 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/discrete/task.py#L120-L126 | [
"def",
"get_cycle_time",
"(",
"self",
",",
"issue_or_start_or_key",
")",
":",
"if",
"isinstance",
"(",
"issue_or_start_or_key",
",",
"basestring",
")",
":",
"issue_or_start_or_key",
"=",
"self",
".",
"get_issue",
"(",
"issue_or_start_or_key",
")",
"if",
"isinstance"... |
A filtered mapping towards performAction of the underlying environment . | def addReward ( self , r = None ) : r = self . getReward ( ) if r is None else r # by default, the cumulative reward is just the sum over the episode if self . discount : self . cumulativeReward += power ( self . discount , self . samples ) * r else : self . cumulativeReward += r | 882 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/discrete/task.py#L156-L166 | [
"def",
"bucketCSVs",
"(",
"csvFile",
",",
"bucketIdx",
"=",
"2",
")",
":",
"try",
":",
"with",
"open",
"(",
"csvFile",
",",
"\"rU\"",
")",
"as",
"f",
":",
"reader",
"=",
"csv",
".",
"reader",
"(",
"f",
")",
"headers",
"=",
"next",
"(",
"reader",
... |
Returns the initial voltage profile . | def getV0 ( self , v_mag_guess , buses , generators , type = CASE_GUESS ) : if type == CASE_GUESS : Va = array ( [ b . v_angle * ( pi / 180.0 ) for b in buses ] ) Vm = array ( [ b . v_magnitude for b in buses ] ) V0 = Vm * exp ( 1j * Va ) elif type == FLAT_START : V0 = ones ( len ( buses ) ) elif type == FROM_INPUT : V... | 883 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/estimator.py#L300-L321 | [
"def",
"DeleteNotifications",
"(",
"self",
",",
"session_ids",
",",
"start",
"=",
"None",
",",
"end",
"=",
"None",
")",
":",
"if",
"not",
"session_ids",
":",
"return",
"for",
"session_id",
"in",
"session_ids",
":",
"if",
"not",
"isinstance",
"(",
"session_... |
Prints comparison of measurements and their estimations . | def output_solution ( self , fd , z , z_est , error_sqrsum ) : col_width = 11 sep = ( "=" * col_width + " " ) * 4 + "\n" fd . write ( "State Estimation\n" ) fd . write ( "-" * 16 + "\n" ) fd . write ( sep ) fd . write ( "Type" . center ( col_width ) + " " ) fd . write ( "Name" . center ( col_width ) + " " ) fd . write ... | 884 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/estimator.py#L324-L352 | [
"def",
"make_inheritable",
"(",
"token",
")",
":",
"return",
"win32api",
".",
"DuplicateHandle",
"(",
"win32api",
".",
"GetCurrentProcess",
"(",
")",
",",
"token",
",",
"win32api",
".",
"GetCurrentProcess",
"(",
")",
",",
"0",
",",
"1",
",",
"win32con",
".... |
Clears a set of bids and offers . | def run ( self ) : # Compute cleared offer/bid quantities from total dispatched quantity. self . _clearQuantities ( ) # Compute shift values to add to lam to get desired pricing. # lao, fro, lab, frb = self._first_rejected_last_accepted() # Clear offer/bid prices according to auction type. self . _clearPrices ( ... | 885 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/auction.py#L85-L103 | [
"def",
"format_log_context",
"(",
"msg",
",",
"connection",
"=",
"None",
",",
"keyspace",
"=",
"None",
")",
":",
"connection_info",
"=",
"connection",
"or",
"'DEFAULT_CONNECTION'",
"if",
"keyspace",
":",
"msg",
"=",
"'[Connection: {0}, Keyspace: {1}] {2}'",
".",
"... |
Computes the cleared bid quantity from total dispatched quantity . | def _clearQuantity ( self , offbids , gen ) : # Filter out offers/bids not applicable to the generator in question. gOffbids = [ offer for offer in offbids if offer . generator == gen ] # Offers/bids within valid price limits (not withheld). valid = [ ob for ob in gOffbids if not ob . withheld ] # Sort offers by price ... | 886 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/auction.py#L120-L158 | [
"def",
"_setup_conn_old",
"(",
"*",
"*",
"kwargs",
")",
":",
"host",
"=",
"__salt__",
"[",
"'config.option'",
"]",
"(",
"'kubernetes.api_url'",
",",
"'http://localhost:8080'",
")",
"username",
"=",
"__salt__",
"[",
"'config.option'",
"]",
"(",
"'kubernetes.user'",... |
Clears prices according to auction type . | def _clearPrices ( self ) : for offbid in self . offers + self . bids : if self . auctionType == DISCRIMINATIVE : offbid . clearedPrice = offbid . price elif self . auctionType == FIRST_PRICE : offbid . clearedPrice = offbid . lmbda else : raise ValueError | 887 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/auction.py#L219-L228 | [
"def",
"_reset_id_table",
"(",
"self",
",",
"mapping",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_initialized_id_tables\"",
")",
":",
"self",
".",
"_initialized_id_tables",
"=",
"set",
"(",
")",
"id_table_name",
"=",
"\"{}_sf_ids\"",
".",
"format"... |
Clip cleared prices according to guarantees and limits . | def _clipPrices ( self ) : # Guarantee that cleared offer prices are >= offers. if self . guaranteeOfferPrice : for offer in self . offers : if offer . accepted and offer . clearedPrice < offer . price : offer . clearedPrice = offer . price # Guarantee that cleared bid prices are <= bids. if self . guaranteeBidPrice : ... | 888 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/auction.py#L265-L311 | [
"def",
"receive_message",
"(",
"self",
",",
"message",
",",
"data",
")",
":",
"# noqa: E501 pylint: disable=too-many-return-statements",
"if",
"data",
"[",
"MESSAGE_TYPE",
"]",
"==",
"TYPE_DEVICE_ADDED",
":",
"uuid",
"=",
"data",
"[",
"'device'",
"]",
"[",
"'devic... |
Try make a GET request with an HTTP client against a certain path and return once any response has been received ignoring any errors . | def wait_for_response ( client , timeout , path = '/' , expected_status_code = None ) : # We want time.monotonic on Pythons that have it, otherwise time.time will # have to do. get_time = getattr ( time , 'monotonic' , time . time ) deadline = get_time ( ) + timeout while True : try : # Don't care what the response is,... | 889 | https://github.com/praekeltfoundation/seaworthy/blob/6f10a19b45d4ea1dc3bd0553cc4d0438696c079c/seaworthy/client.py#L205-L248 | [
"def",
"lessThan",
"(",
"self",
",",
"leftIndex",
",",
"rightIndex",
")",
":",
"leftData",
"=",
"self",
".",
"sourceModel",
"(",
")",
".",
"data",
"(",
"leftIndex",
",",
"RegistryTableModel",
".",
"SORT_ROLE",
")",
"rightData",
"=",
"self",
".",
"sourceMod... |
Make a request against a container . | def request ( self , method , path = None , url_kwargs = None , * * kwargs ) : return self . _session . request ( method , self . _url ( path , url_kwargs ) , * * kwargs ) | 890 | https://github.com/praekeltfoundation/seaworthy/blob/6f10a19b45d4ea1dc3bd0553cc4d0438696c079c/seaworthy/client.py#L90-L104 | [
"def",
"swd_sync",
"(",
"self",
",",
"pad",
"=",
"False",
")",
":",
"if",
"pad",
":",
"self",
".",
"_dll",
".",
"JLINK_SWD_SyncBytes",
"(",
")",
"else",
":",
"self",
".",
"_dll",
".",
"JLINK_SWD_SyncBits",
"(",
")",
"return",
"None"
] |
Sends an OPTIONS request . | def options ( self , path = None , url_kwargs = None , * * kwargs ) : return self . _session . options ( self . _url ( path , url_kwargs ) , * * kwargs ) | 891 | https://github.com/praekeltfoundation/seaworthy/blob/6f10a19b45d4ea1dc3bd0553cc4d0438696c079c/seaworthy/client.py#L120-L132 | [
"def",
"_generate_examples_validation",
"(",
"self",
",",
"archive",
",",
"labels",
")",
":",
"# Get the current random seeds.",
"numpy_st0",
"=",
"np",
".",
"random",
".",
"get_state",
"(",
")",
"# Set new random seeds.",
"np",
".",
"random",
".",
"seed",
"(",
... |
Sends a HEAD request . | def head ( self , path = None , url_kwargs = None , * * kwargs ) : return self . _session . head ( self . _url ( path , url_kwargs ) , * * kwargs ) | 892 | https://github.com/praekeltfoundation/seaworthy/blob/6f10a19b45d4ea1dc3bd0553cc4d0438696c079c/seaworthy/client.py#L134-L146 | [
"def",
"get_listing",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'listing'",
")",
":",
"allEvents",
"=",
"self",
".",
"get_allEvents",
"(",
")",
"openEvents",
"=",
"allEvents",
".",
"filter",
"(",
"registrationOpen",
"=",
"True",
"... |
Sends a POST request . | def post ( self , path = None , url_kwargs = None , * * kwargs ) : return self . _session . post ( self . _url ( path , url_kwargs ) , * * kwargs ) | 893 | https://github.com/praekeltfoundation/seaworthy/blob/6f10a19b45d4ea1dc3bd0553cc4d0438696c079c/seaworthy/client.py#L148-L160 | [
"def",
"_generate_examples_validation",
"(",
"self",
",",
"archive",
",",
"labels",
")",
":",
"# Get the current random seeds.",
"numpy_st0",
"=",
"np",
".",
"random",
".",
"get_state",
"(",
")",
"# Set new random seeds.",
"np",
".",
"random",
".",
"seed",
"(",
... |
This function serves as a handler for the different implementations of the IUWT decomposition . It allows the different methods to be used almost interchangeably . | def iuwt_decomposition ( in1 , scale_count , scale_adjust = 0 , mode = 'ser' , core_count = 2 , store_smoothed = False , store_on_gpu = False ) : if mode == 'ser' : return ser_iuwt_decomposition ( in1 , scale_count , scale_adjust , store_smoothed ) elif mode == 'mp' : return mp_iuwt_decomposition ( in1 , scale_count , ... | 894 | https://github.com/ratt-ru/PyMORESANE/blob/b024591ad0bbb69320d08841f28a2c27f62ae1af/pymoresane/iuwt.py#L17-L41 | [
"def",
"leader_for_partition",
"(",
"self",
",",
"partition",
")",
":",
"if",
"partition",
".",
"topic",
"not",
"in",
"self",
".",
"_partitions",
":",
"return",
"None",
"elif",
"partition",
".",
"partition",
"not",
"in",
"self",
".",
"_partitions",
"[",
"p... |
This function serves as a handler for the different implementations of the IUWT recomposition . It allows the different methods to be used almost interchangeably . | def iuwt_recomposition ( in1 , scale_adjust = 0 , mode = 'ser' , core_count = 1 , store_on_gpu = False , smoothed_array = None ) : if mode == 'ser' : return ser_iuwt_recomposition ( in1 , scale_adjust , smoothed_array ) elif mode == 'mp' : return mp_iuwt_recomposition ( in1 , scale_adjust , core_count , smoothed_array ... | 895 | https://github.com/ratt-ru/PyMORESANE/blob/b024591ad0bbb69320d08841f28a2c27f62ae1af/pymoresane/iuwt.py#L43-L64 | [
"def",
"handshake_timed_out",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"__timer",
":",
"return",
"False",
"if",
"self",
".",
"__handshake_complete",
":",
"return",
"False",
"return",
"self",
".",
"__timer_expired"
] |
This function calls the a trous algorithm code to decompose the input into its wavelet coefficients . This is the isotropic undecimated wavelet transform implemented for a single CPU core . | def ser_iuwt_decomposition ( in1 , scale_count , scale_adjust , store_smoothed ) : wavelet_filter = ( 1. / 16 ) * np . array ( [ 1 , 4 , 6 , 4 , 1 ] ) # Filter-bank for use in the a trous algorithm. # Initialises an empty array to store the coefficients. detail_coeffs = np . empty ( [ scale_count - scale_adjust , in1 .... | 896 | https://github.com/ratt-ru/PyMORESANE/blob/b024591ad0bbb69320d08841f28a2c27f62ae1af/pymoresane/iuwt.py#L66-L111 | [
"def",
"init_defaults",
"(",
"self",
")",
":",
"super",
"(",
"SimpleTable",
",",
"self",
")",
".",
"init_defaults",
"(",
")",
"self",
".",
"name",
"=",
"self",
".",
"table"
] |
This function calls the a trous algorithm code to recompose the input into a single array . This is the implementation of the isotropic undecimated wavelet transform recomposition for a single CPU core . | def ser_iuwt_recomposition ( in1 , scale_adjust , smoothed_array ) : wavelet_filter = ( 1. / 16 ) * np . array ( [ 1 , 4 , 6 , 4 , 1 ] ) # Filter-bank for use in the a trous algorithm. # Determines scale with adjustment and creates a zero array to store the output, unless smoothed_array is given. max_scale = in1 . shap... | 897 | https://github.com/ratt-ru/PyMORESANE/blob/b024591ad0bbb69320d08841f28a2c27f62ae1af/pymoresane/iuwt.py#L113-L149 | [
"def",
"set_end_date",
"(",
"self",
",",
"lifetime",
")",
":",
"self",
".",
"end_date",
"=",
"(",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"+",
"datetime",
".",
"timedelta",
"(",
"0",
",",
"lifetime",
")",
")"
] |
This function calls the a trous algorithm code to recompose the input into a single array . This is the implementation of the isotropic undecimated wavelet transform recomposition for multiple CPU cores . | def mp_iuwt_recomposition ( in1 , scale_adjust , core_count , smoothed_array ) : wavelet_filter = ( 1. / 16 ) * np . array ( [ 1 , 4 , 6 , 4 , 1 ] ) # Filter-bank for use in the a trous algorithm. # Determines scale with adjustment and creates a zero array to store the output, unless smoothed_array is given. max_scale ... | 898 | https://github.com/ratt-ru/PyMORESANE/blob/b024591ad0bbb69320d08841f28a2c27f62ae1af/pymoresane/iuwt.py#L242-L279 | [
"def",
"set_end_date",
"(",
"self",
",",
"lifetime",
")",
":",
"self",
".",
"end_date",
"=",
"(",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"+",
"datetime",
".",
"timedelta",
"(",
"0",
",",
"lifetime",
")",
")"
] |
This function calls the a trous algorithm code to decompose the input into its wavelet coefficients . This is the isotropic undecimated wavelet transform implemented for a GPU . | def gpu_iuwt_decomposition ( in1 , scale_count , scale_adjust , store_smoothed , store_on_gpu ) : # The following simple kernel just allows for the construction of a 3D decomposition on the GPU. ker = SourceModule ( """
__global__ void gpu_store_detail_coeffs(float *in1, float *in2, float* out1,... | 899 | https://github.com/ratt-ru/PyMORESANE/blob/b024591ad0bbb69320d08841f28a2c27f62ae1af/pymoresane/iuwt.py#L384-L499 | [
"def",
"_record_offset",
"(",
"self",
")",
":",
"offset",
"=",
"self",
".",
"blob_file",
".",
"tell",
"(",
")",
"self",
".",
"event_offsets",
".",
"append",
"(",
"offset",
")"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.