repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
rwl/pylon | pylon/solver.py | _Solver._var_bounds | def _var_bounds(self):
""" Returns bounds on the optimisation variables.
"""
x0 = array([])
xmin = array([])
xmax = array([])
for var in self.om.vars:
x0 = r_[x0, var.v0]
xmin = r_[xmin, var.vl]
xmax = r_[xmax, var.vu]
return ... | python | def _var_bounds(self):
""" Returns bounds on the optimisation variables.
"""
x0 = array([])
xmin = array([])
xmax = array([])
for var in self.om.vars:
x0 = r_[x0, var.v0]
xmin = r_[xmin, var.vl]
xmax = r_[xmax, var.vu]
return ... | [
"def",
"_var_bounds",
"(",
"self",
")",
":",
"x0",
"=",
"array",
"(",
"[",
"]",
")",
"xmin",
"=",
"array",
"(",
"[",
"]",
")",
"xmax",
"=",
"array",
"(",
"[",
"]",
")",
"for",
"var",
"in",
"self",
".",
"om",
".",
"vars",
":",
"x0",
"=",
"r_... | Returns bounds on the optimisation variables. | [
"Returns",
"bounds",
"on",
"the",
"optimisation",
"variables",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L152-L164 | train |
rwl/pylon | pylon/solver.py | _Solver._initial_interior_point | def _initial_interior_point(self, buses, generators, xmin, xmax, ny):
""" Selects an interior initial point for interior point solver.
"""
Va = self.om.get_var("Va")
va_refs = [b.v_angle * pi / 180.0 for b in buses
if b.type == REFERENCE]
x0 = (xmin + xmax) / 2... | python | def _initial_interior_point(self, buses, generators, xmin, xmax, ny):
""" Selects an interior initial point for interior point solver.
"""
Va = self.om.get_var("Va")
va_refs = [b.v_angle * pi / 180.0 for b in buses
if b.type == REFERENCE]
x0 = (xmin + xmax) / 2... | [
"def",
"_initial_interior_point",
"(",
"self",
",",
"buses",
",",
"generators",
",",
"xmin",
",",
"xmax",
",",
"ny",
")",
":",
"Va",
"=",
"self",
".",
"om",
".",
"get_var",
"(",
"\"Va\"",
")",
"va_refs",
"=",
"[",
"b",
".",
"v_angle",
"*",
"pi",
"/... | Selects an interior initial point for interior point solver. | [
"Selects",
"an",
"interior",
"initial",
"point",
"for",
"interior",
"point",
"solver",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L167-L190 | train |
rwl/pylon | pylon/solver.py | DCOPFSolver.solve | def solve(self):
""" Solves DC optimal power flow and returns a results dict.
"""
base_mva = self.om.case.base_mva
Bf = self.om._Bf
Pfinj = self.om._Pfinj
# Unpack the OPF model.
bs, ln, gn, cp = self._unpack_model(self.om)
# Compute problem dimensions.
... | python | def solve(self):
""" Solves DC optimal power flow and returns a results dict.
"""
base_mva = self.om.case.base_mva
Bf = self.om._Bf
Pfinj = self.om._Pfinj
# Unpack the OPF model.
bs, ln, gn, cp = self._unpack_model(self.om)
# Compute problem dimensions.
... | [
"def",
"solve",
"(",
"self",
")",
":",
"base_mva",
"=",
"self",
".",
"om",
".",
"case",
".",
"base_mva",
"Bf",
"=",
"self",
".",
"om",
".",
"_Bf",
"Pfinj",
"=",
"self",
".",
"om",
".",
"_Pfinj",
"bs",
",",
"ln",
",",
"gn",
",",
"cp",
"=",
"se... | Solves DC optimal power flow and returns a results dict. | [
"Solves",
"DC",
"optimal",
"power",
"flow",
"and",
"returns",
"a",
"results",
"dict",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L218-L257 | train |
rwl/pylon | pylon/solver.py | DCOPFSolver._pwl_costs | def _pwl_costs(self, ny, nxyz, ipwl):
""" Returns the piece-wise linear components of the objective function.
"""
any_pwl = int(ny > 0)
if any_pwl:
y = self.om.get_var("y")
# Sum of y vars.
Npwl = csr_matrix((ones(ny), (zeros(ny), array(ipwl) + y.i1)))... | python | def _pwl_costs(self, ny, nxyz, ipwl):
""" Returns the piece-wise linear components of the objective function.
"""
any_pwl = int(ny > 0)
if any_pwl:
y = self.om.get_var("y")
# Sum of y vars.
Npwl = csr_matrix((ones(ny), (zeros(ny), array(ipwl) + y.i1)))... | [
"def",
"_pwl_costs",
"(",
"self",
",",
"ny",
",",
"nxyz",
",",
"ipwl",
")",
":",
"any_pwl",
"=",
"int",
"(",
"ny",
">",
"0",
")",
"if",
"any_pwl",
":",
"y",
"=",
"self",
".",
"om",
".",
"get_var",
"(",
"\"y\"",
")",
"Npwl",
"=",
"csr_matrix",
"... | Returns the piece-wise linear components of the objective function. | [
"Returns",
"the",
"piece",
"-",
"wise",
"linear",
"components",
"of",
"the",
"objective",
"function",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L260-L277 | train |
rwl/pylon | pylon/solver.py | DCOPFSolver._quadratic_costs | def _quadratic_costs(self, generators, ipol, nxyz, base_mva):
""" Returns the quadratic cost components of the objective function.
"""
npol = len(ipol)
rnpol = range(npol)
gpol = [g for g in generators if g.pcost_model == POLYNOMIAL]
if [g for g in gpol if len(g.p_cost) ... | python | def _quadratic_costs(self, generators, ipol, nxyz, base_mva):
""" Returns the quadratic cost components of the objective function.
"""
npol = len(ipol)
rnpol = range(npol)
gpol = [g for g in generators if g.pcost_model == POLYNOMIAL]
if [g for g in gpol if len(g.p_cost) ... | [
"def",
"_quadratic_costs",
"(",
"self",
",",
"generators",
",",
"ipol",
",",
"nxyz",
",",
"base_mva",
")",
":",
"npol",
"=",
"len",
"(",
"ipol",
")",
"rnpol",
"=",
"range",
"(",
"npol",
")",
"gpol",
"=",
"[",
"g",
"for",
"g",
"in",
"generators",
"i... | Returns the quadratic cost components of the objective function. | [
"Returns",
"the",
"quadratic",
"cost",
"components",
"of",
"the",
"objective",
"function",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L280-L316 | train |
rwl/pylon | pylon/solver.py | DCOPFSolver._combine_costs | def _combine_costs(self, Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl,
Npol, Hpol, Cpol, fparm_pol, npol, nw):
""" Combines pwl, polynomial and user-defined costs.
"""
NN = vstack([n for n in [Npwl, Npol] if n is not None], "csr")
if (Hpwl is not None) and (Hpol is not No... | python | def _combine_costs(self, Npwl, Hpwl, Cpwl, fparm_pwl, any_pwl,
Npol, Hpol, Cpol, fparm_pol, npol, nw):
""" Combines pwl, polynomial and user-defined costs.
"""
NN = vstack([n for n in [Npwl, Npol] if n is not None], "csr")
if (Hpwl is not None) and (Hpol is not No... | [
"def",
"_combine_costs",
"(",
"self",
",",
"Npwl",
",",
"Hpwl",
",",
"Cpwl",
",",
"fparm_pwl",
",",
"any_pwl",
",",
"Npol",
",",
"Hpol",
",",
"Cpol",
",",
"fparm_pol",
",",
"npol",
",",
"nw",
")",
":",
"NN",
"=",
"vstack",
"(",
"[",
"n",
"for",
"... | Combines pwl, polynomial and user-defined costs. | [
"Combines",
"pwl",
"polynomial",
"and",
"user",
"-",
"defined",
"costs",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L319-L337 | train |
rwl/pylon | pylon/solver.py | DCOPFSolver._transform_coefficients | def _transform_coefficients(self, NN, HHw, CCw, ffparm, polycf,
any_pwl, npol, nw):
""" Transforms quadratic coefficients for w into coefficients for x.
"""
nnw = any_pwl + npol + nw
M = csr_matrix((ffparm[:, 3], (range(nnw), range(nnw))))
MR = M * ... | python | def _transform_coefficients(self, NN, HHw, CCw, ffparm, polycf,
any_pwl, npol, nw):
""" Transforms quadratic coefficients for w into coefficients for x.
"""
nnw = any_pwl + npol + nw
M = csr_matrix((ffparm[:, 3], (range(nnw), range(nnw))))
MR = M * ... | [
"def",
"_transform_coefficients",
"(",
"self",
",",
"NN",
",",
"HHw",
",",
"CCw",
",",
"ffparm",
",",
"polycf",
",",
"any_pwl",
",",
"npol",
",",
"nw",
")",
":",
"nnw",
"=",
"any_pwl",
"+",
"npol",
"+",
"nw",
"M",
"=",
"csr_matrix",
"(",
"(",
"ffpa... | Transforms quadratic coefficients for w into coefficients for x. | [
"Transforms",
"quadratic",
"coefficients",
"for",
"w",
"into",
"coefficients",
"for",
"x",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L340-L354 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._ref_bus_angle_constraint | def _ref_bus_angle_constraint(self, buses, Va, xmin, xmax):
""" Adds a constraint on the reference bus angles.
"""
refs = [bus._i for bus in buses if bus.type == REFERENCE]
Varefs = array([b.v_angle for b in buses if b.type == REFERENCE])
xmin[Va.i1 - 1 + refs] = Varefs
... | python | def _ref_bus_angle_constraint(self, buses, Va, xmin, xmax):
""" Adds a constraint on the reference bus angles.
"""
refs = [bus._i for bus in buses if bus.type == REFERENCE]
Varefs = array([b.v_angle for b in buses if b.type == REFERENCE])
xmin[Va.i1 - 1 + refs] = Varefs
... | [
"def",
"_ref_bus_angle_constraint",
"(",
"self",
",",
"buses",
",",
"Va",
",",
"xmin",
",",
"xmax",
")",
":",
"refs",
"=",
"[",
"bus",
".",
"_i",
"for",
"bus",
"in",
"buses",
"if",
"bus",
".",
"type",
"==",
"REFERENCE",
"]",
"Varefs",
"=",
"array",
... | Adds a constraint on the reference bus angles. | [
"Adds",
"a",
"constraint",
"on",
"the",
"reference",
"bus",
"angles",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L444-L453 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._f | def _f(self, x, user_data=None):
""" Evaluates the objective function.
"""
p_gen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
q_gen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.
# Polynomial cost of P and Q.
xx = r_[p_gen, q_gen] * self._... | python | def _f(self, x, user_data=None):
""" Evaluates the objective function.
"""
p_gen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
q_gen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.
# Polynomial cost of P and Q.
xx = r_[p_gen, q_gen] * self._... | [
"def",
"_f",
"(",
"self",
",",
"x",
",",
"user_data",
"=",
"None",
")",
":",
"p_gen",
"=",
"x",
"[",
"self",
".",
"_Pg",
".",
"i1",
":",
"self",
".",
"_Pg",
".",
"iN",
"+",
"1",
"]",
"q_gen",
"=",
"x",
"[",
"self",
".",
"_Qg",
".",
"i1",
... | Evaluates the objective function. | [
"Evaluates",
"the",
"objective",
"function",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L515-L539 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._df | def _df(self, x, user_data=None):
""" Evaluates the cost gradient.
"""
p_gen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
q_gen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.
# Polynomial cost of P and Q.
xx = r_[p_gen, q_gen] * self._base... | python | def _df(self, x, user_data=None):
""" Evaluates the cost gradient.
"""
p_gen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
q_gen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.
# Polynomial cost of P and Q.
xx = r_[p_gen, q_gen] * self._base... | [
"def",
"_df",
"(",
"self",
",",
"x",
",",
"user_data",
"=",
"None",
")",
":",
"p_gen",
"=",
"x",
"[",
"self",
".",
"_Pg",
".",
"i1",
":",
"self",
".",
"_Pg",
".",
"iN",
"+",
"1",
"]",
"q_gen",
"=",
"x",
"[",
"self",
".",
"_Qg",
".",
"i1",
... | Evaluates the cost gradient. | [
"Evaluates",
"the",
"cost",
"gradient",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L542-L573 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._d2f | def _d2f(self, x):
""" Evaluates the cost Hessian.
"""
d2f_dPg2 = lil_matrix((self._ng, 1)) # w.r.t p.u. Pg
d2f_dQg2 = lil_matrix((self._ng, 1)) # w.r.t p.u. Qg]
for i in self._ipol:
p_cost = list(self._gn[i].p_cost)
d2f_dPg2[i, 0] = polyval(polyder(p_cos... | python | def _d2f(self, x):
""" Evaluates the cost Hessian.
"""
d2f_dPg2 = lil_matrix((self._ng, 1)) # w.r.t p.u. Pg
d2f_dQg2 = lil_matrix((self._ng, 1)) # w.r.t p.u. Qg]
for i in self._ipol:
p_cost = list(self._gn[i].p_cost)
d2f_dPg2[i, 0] = polyval(polyder(p_cos... | [
"def",
"_d2f",
"(",
"self",
",",
"x",
")",
":",
"d2f_dPg2",
"=",
"lil_matrix",
"(",
"(",
"self",
".",
"_ng",
",",
"1",
")",
")",
"d2f_dQg2",
"=",
"lil_matrix",
"(",
"(",
"self",
".",
"_ng",
",",
"1",
")",
")",
"for",
"i",
"in",
"self",
".",
"... | Evaluates the cost Hessian. | [
"Evaluates",
"the",
"cost",
"Hessian",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L576-L595 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._gh | def _gh(self, x):
""" Evaluates the constraint function values.
"""
Pgen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
Qgen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.
for i, gen in enumerate(self._gn):
gen.p = Pgen[i] * self._base_m... | python | def _gh(self, x):
""" Evaluates the constraint function values.
"""
Pgen = x[self._Pg.i1:self._Pg.iN + 1] # Active generation in p.u.
Qgen = x[self._Qg.i1:self._Qg.iN + 1] # Reactive generation in p.u.
for i, gen in enumerate(self._gn):
gen.p = Pgen[i] * self._base_m... | [
"def",
"_gh",
"(",
"self",
",",
"x",
")",
":",
"Pgen",
"=",
"x",
"[",
"self",
".",
"_Pg",
".",
"i1",
":",
"self",
".",
"_Pg",
".",
"iN",
"+",
"1",
"]",
"Qgen",
"=",
"x",
"[",
"self",
".",
"_Qg",
".",
"i1",
":",
"self",
".",
"_Qg",
".",
... | Evaluates the constraint function values. | [
"Evaluates",
"the",
"constraint",
"function",
"values",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L598-L654 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._costfcn | def _costfcn(self, x):
""" Evaluates the objective function, gradient and Hessian for OPF.
"""
f = self._f(x)
df = self._df(x)
d2f = self._d2f(x)
return f, df, d2f | python | def _costfcn(self, x):
""" Evaluates the objective function, gradient and Hessian for OPF.
"""
f = self._f(x)
df = self._df(x)
d2f = self._d2f(x)
return f, df, d2f | [
"def",
"_costfcn",
"(",
"self",
",",
"x",
")",
":",
"f",
"=",
"self",
".",
"_f",
"(",
"x",
")",
"df",
"=",
"self",
".",
"_df",
"(",
"x",
")",
"d2f",
"=",
"self",
".",
"_d2f",
"(",
"x",
")",
"return",
"f",
",",
"df",
",",
"d2f"
] | Evaluates the objective function, gradient and Hessian for OPF. | [
"Evaluates",
"the",
"objective",
"function",
"gradient",
"and",
"Hessian",
"for",
"OPF",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L716-L723 | train |
rwl/pylon | pylon/solver.py | PIPSSolver._consfcn | def _consfcn(self, x):
""" Evaluates nonlinear constraints and their Jacobian for OPF.
"""
h, g = self._gh(x)
dh, dg = self._dgh(x)
return h, g, dh, dg | python | def _consfcn(self, x):
""" Evaluates nonlinear constraints and their Jacobian for OPF.
"""
h, g = self._gh(x)
dh, dg = self._dgh(x)
return h, g, dh, dg | [
"def",
"_consfcn",
"(",
"self",
",",
"x",
")",
":",
"h",
",",
"g",
"=",
"self",
".",
"_gh",
"(",
"x",
")",
"dh",
",",
"dg",
"=",
"self",
".",
"_dgh",
"(",
"x",
")",
"return",
"h",
",",
"g",
",",
"dh",
",",
"dg"
] | Evaluates nonlinear constraints and their Jacobian for OPF. | [
"Evaluates",
"nonlinear",
"constraints",
"and",
"their",
"Jacobian",
"for",
"OPF",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/solver.py#L726-L732 | train |
rwl/pylon | pylon/io/pickle.py | PickleReader.read | def read(self, file_or_filename):
""" Loads a pickled case.
"""
if isinstance(file_or_filename, basestring):
fname = os.path.basename(file_or_filename)
logger.info("Unpickling case file [%s]." % fname)
file = None
try:
file = open(... | python | def read(self, file_or_filename):
""" Loads a pickled case.
"""
if isinstance(file_or_filename, basestring):
fname = os.path.basename(file_or_filename)
logger.info("Unpickling case file [%s]." % fname)
file = None
try:
file = open(... | [
"def",
"read",
"(",
"self",
",",
"file_or_filename",
")",
":",
"if",
"isinstance",
"(",
"file_or_filename",
",",
"basestring",
")",
":",
"fname",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"file_or_filename",
")",
"logger",
".",
"info",
"(",
"\"Unpickli... | Loads a pickled case. | [
"Loads",
"a",
"pickled",
"case",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/pickle.py#L45-L66 | train |
rwl/pylon | pylon/io/pickle.py | PickleWriter.write | def write(self, file_or_filename):
""" Writes the case to file using pickle.
"""
if isinstance(file_or_filename, basestring):
fname = os.path.basename(file_or_filename)
logger.info("Pickling case [%s]." % fname)
file = None
try:
fi... | python | def write(self, file_or_filename):
""" Writes the case to file using pickle.
"""
if isinstance(file_or_filename, basestring):
fname = os.path.basename(file_or_filename)
logger.info("Pickling case [%s]." % fname)
file = None
try:
fi... | [
"def",
"write",
"(",
"self",
",",
"file_or_filename",
")",
":",
"if",
"isinstance",
"(",
"file_or_filename",
",",
"basestring",
")",
":",
"fname",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"file_or_filename",
")",
"logger",
".",
"info",
"(",
"\"Picklin... | Writes the case to file using pickle. | [
"Writes",
"the",
"case",
"to",
"file",
"using",
"pickle",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/pickle.py#L76-L97 | train |
finklabs/metrics | metrics/sloc.py | SLOCMetric.process_token | def process_token(self, tok):
"""count comments and non-empty lines that contain code"""
if(tok[0].__str__() in ('Token.Comment.Multiline', 'Token.Comment',
'Token.Literal.String.Doc')):
self.comments += tok[1].count('\n')+1
elif(tok[0].__str__() in ('Token.Comment.Si... | python | def process_token(self, tok):
"""count comments and non-empty lines that contain code"""
if(tok[0].__str__() in ('Token.Comment.Multiline', 'Token.Comment',
'Token.Literal.String.Doc')):
self.comments += tok[1].count('\n')+1
elif(tok[0].__str__() in ('Token.Comment.Si... | [
"def",
"process_token",
"(",
"self",
",",
"tok",
")",
":",
"if",
"(",
"tok",
"[",
"0",
"]",
".",
"__str__",
"(",
")",
"in",
"(",
"'Token.Comment.Multiline'",
",",
"'Token.Comment'",
",",
"'Token.Literal.String.Doc'",
")",
")",
":",
"self",
".",
"comments",... | count comments and non-empty lines that contain code | [
"count",
"comments",
"and",
"non",
"-",
"empty",
"lines",
"that",
"contain",
"code"
] | fd9974af498831664b9ae8e8f3834e1ec2e8a699 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/sloc.py#L34-L53 | train |
finklabs/metrics | metrics/sloc.py | SLOCMetric.get_metrics | def get_metrics(self):
"""Calculate ratio_comment_to_code and return with the other values"""
if(self.sloc == 0):
if(self.comments == 0):
ratio_comment_to_code = 0.00
else:
ratio_comment_to_code = 1.00
else:
ratio_comment_to_cod... | python | def get_metrics(self):
"""Calculate ratio_comment_to_code and return with the other values"""
if(self.sloc == 0):
if(self.comments == 0):
ratio_comment_to_code = 0.00
else:
ratio_comment_to_code = 1.00
else:
ratio_comment_to_cod... | [
"def",
"get_metrics",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"sloc",
"==",
"0",
")",
":",
"if",
"(",
"self",
".",
"comments",
"==",
"0",
")",
":",
"ratio_comment_to_code",
"=",
"0.00",
"else",
":",
"ratio_comment_to_code",
"=",
"1.00",
"else",
... | Calculate ratio_comment_to_code and return with the other values | [
"Calculate",
"ratio_comment_to_code",
"and",
"return",
"with",
"the",
"other",
"values"
] | fd9974af498831664b9ae8e8f3834e1ec2e8a699 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/sloc.py#L68-L79 | train |
rwl/pylon | pyreto/rlopf.py | CaseEnvironment.performAction | def performAction(self, action):
""" Perform an action on the world that changes it's internal state.
"""
gs = [g for g in self.case.online_generators if g.bus.type !=REFERENCE]
assert len(action) == len(gs)
logger.info("Action: %s" % list(action))
# Set the output of ... | python | def performAction(self, action):
""" Perform an action on the world that changes it's internal state.
"""
gs = [g for g in self.case.online_generators if g.bus.type !=REFERENCE]
assert len(action) == len(gs)
logger.info("Action: %s" % list(action))
# Set the output of ... | [
"def",
"performAction",
"(",
"self",
",",
"action",
")",
":",
"gs",
"=",
"[",
"g",
"for",
"g",
"in",
"self",
".",
"case",
".",
"online_generators",
"if",
"g",
".",
"bus",
".",
"type",
"!=",
"REFERENCE",
"]",
"assert",
"len",
"(",
"action",
")",
"==... | Perform an action on the world that changes it's internal state. | [
"Perform",
"an",
"action",
"on",
"the",
"world",
"that",
"changes",
"it",
"s",
"internal",
"state",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/rlopf.py#L109-L137 | train |
rwl/pylon | pyreto/rlopf.py | CaseEnvironment.reset | def reset(self):
""" Re-initialises the environment.
"""
logger.info("Reseting environment.")
self._step = 0
# Reset the set-point of each generator to its original value.
gs = [g for g in self.case.online_generators if g.bus.type !=REFERENCE]
for i, g in enumer... | python | def reset(self):
""" Re-initialises the environment.
"""
logger.info("Reseting environment.")
self._step = 0
# Reset the set-point of each generator to its original value.
gs = [g for g in self.case.online_generators if g.bus.type !=REFERENCE]
for i, g in enumer... | [
"def",
"reset",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"\"Reseting environment.\"",
")",
"self",
".",
"_step",
"=",
"0",
"gs",
"=",
"[",
"g",
"for",
"g",
"in",
"self",
".",
"case",
".",
"online_generators",
"if",
"g",
".",
"bus",
".",
"... | Re-initialises the environment. | [
"Re",
"-",
"initialises",
"the",
"environment",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/rlopf.py#L140-L162 | train |
rwl/pylon | pyreto/rlopf.py | MinimiseCostTask.isFinished | def isFinished(self):
""" Is the current episode over?
"""
finished = (self.env._step == len(self.env.profile))
if finished:
logger.info("Finished episode.")
return finished | python | def isFinished(self):
""" Is the current episode over?
"""
finished = (self.env._step == len(self.env.profile))
if finished:
logger.info("Finished episode.")
return finished | [
"def",
"isFinished",
"(",
"self",
")",
":",
"finished",
"=",
"(",
"self",
".",
"env",
".",
"_step",
"==",
"len",
"(",
"self",
".",
"env",
".",
"profile",
")",
")",
"if",
"finished",
":",
"logger",
".",
"info",
"(",
"\"Finished episode.\"",
")",
"retu... | Is the current episode over? | [
"Is",
"the",
"current",
"episode",
"over?"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/rlopf.py#L216-L222 | train |
rwl/pylon | pyreto/rlopf.py | OPFExperiment._oneInteraction | def _oneInteraction(self):
""" Does one interaction between the task and the agent.
"""
if self.doOptimization:
raise Exception('When using a black-box learning algorithm, only full episodes can be done.')
else:
self.stepid += 1
self.agent.integrateObs... | python | def _oneInteraction(self):
""" Does one interaction between the task and the agent.
"""
if self.doOptimization:
raise Exception('When using a black-box learning algorithm, only full episodes can be done.')
else:
self.stepid += 1
self.agent.integrateObs... | [
"def",
"_oneInteraction",
"(",
"self",
")",
":",
"if",
"self",
".",
"doOptimization",
":",
"raise",
"Exception",
"(",
"'When using a black-box learning algorithm, only full episodes can be done.'",
")",
"else",
":",
"self",
".",
"stepid",
"+=",
"1",
"self",
".",
"ag... | Does one interaction between the task and the agent. | [
"Does",
"one",
"interaction",
"between",
"the",
"task",
"and",
"the",
"agent",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/rlopf.py#L272-L288 | train |
rwl/pylon | pyreto/rlopf.py | OPFExperiment.doEpisodes | def doEpisodes(self, number=1):
""" Does the the given number of episodes.
"""
env = self.task.env
self.Pg = zeros((len(env.case.online_generators), len(env.profile)))
rewards = super(OPFExperiment, self).doEpisodes(number)
# Average the set-points for each period.
... | python | def doEpisodes(self, number=1):
""" Does the the given number of episodes.
"""
env = self.task.env
self.Pg = zeros((len(env.case.online_generators), len(env.profile)))
rewards = super(OPFExperiment, self).doEpisodes(number)
# Average the set-points for each period.
... | [
"def",
"doEpisodes",
"(",
"self",
",",
"number",
"=",
"1",
")",
":",
"env",
"=",
"self",
".",
"task",
".",
"env",
"self",
".",
"Pg",
"=",
"zeros",
"(",
"(",
"len",
"(",
"env",
".",
"case",
".",
"online_generators",
")",
",",
"len",
"(",
"env",
... | Does the the given number of episodes. | [
"Does",
"the",
"the",
"given",
"number",
"of",
"episodes",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/rlopf.py#L291-L302 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | getMethodByName | def getMethodByName(obj, name):
"""searches for an object with the name given inside the object given.
"obj.child.meth" will return the meth obj.
"""
try:#to get a method by asking the service
obj = obj._getMethodByName(name)
except:
#assumed a childObject is ment
#split... | python | def getMethodByName(obj, name):
"""searches for an object with the name given inside the object given.
"obj.child.meth" will return the meth obj.
"""
try:#to get a method by asking the service
obj = obj._getMethodByName(name)
except:
#assumed a childObject is ment
#split... | [
"def",
"getMethodByName",
"(",
"obj",
",",
"name",
")",
":",
"try",
":",
"obj",
"=",
"obj",
".",
"_getMethodByName",
"(",
"name",
")",
"except",
":",
"names",
"=",
"name",
".",
"split",
"(",
"\".\"",
")",
"for",
"name",
"in",
"names",
":",
"if",
"n... | searches for an object with the name given inside the object given.
"obj.child.meth" will return the meth obj. | [
"searches",
"for",
"an",
"object",
"with",
"the",
"name",
"given",
"inside",
"the",
"object",
"given",
".",
"obj",
".",
"child",
".",
"meth",
"will",
"return",
"the",
"meth",
"obj",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L168-L186 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | ResponseEvent.waitForResponse | def waitForResponse(self, timeOut=None):
"""blocks until the response arrived or timeout is reached."""
self.__evt.wait(timeOut)
if self.waiting():
raise Timeout()
else:
if self.response["error"]:
raise Exception(self.response["error"])
... | python | def waitForResponse(self, timeOut=None):
"""blocks until the response arrived or timeout is reached."""
self.__evt.wait(timeOut)
if self.waiting():
raise Timeout()
else:
if self.response["error"]:
raise Exception(self.response["error"])
... | [
"def",
"waitForResponse",
"(",
"self",
",",
"timeOut",
"=",
"None",
")",
":",
"self",
".",
"__evt",
".",
"wait",
"(",
"timeOut",
")",
"if",
"self",
".",
"waiting",
"(",
")",
":",
"raise",
"Timeout",
"(",
")",
"else",
":",
"if",
"self",
".",
"respon... | blocks until the response arrived or timeout is reached. | [
"blocks",
"until",
"the",
"response",
"arrived",
"or",
"timeout",
"is",
"reached",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L51-L60 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | SimpleMessageHandler.sendRequest | def sendRequest(self, name, args):
"""sends a request to the peer"""
(respEvt, id) = self.newResponseEvent()
self.sendMessage({"id":id, "method":name, "params": args})
return respEvt | python | def sendRequest(self, name, args):
"""sends a request to the peer"""
(respEvt, id) = self.newResponseEvent()
self.sendMessage({"id":id, "method":name, "params": args})
return respEvt | [
"def",
"sendRequest",
"(",
"self",
",",
"name",
",",
"args",
")",
":",
"(",
"respEvt",
",",
"id",
")",
"=",
"self",
".",
"newResponseEvent",
"(",
")",
"self",
".",
"sendMessage",
"(",
"{",
"\"id\"",
":",
"id",
",",
"\"method\"",
":",
"name",
",",
"... | sends a request to the peer | [
"sends",
"a",
"request",
"to",
"the",
"peer"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L108-L112 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | SimpleMessageHandler.sendResponse | def sendResponse(self, id, result, error):
"""sends a response to the peer"""
self.sendMessage({"result":result, "error": error, "id":id}) | python | def sendResponse(self, id, result, error):
"""sends a response to the peer"""
self.sendMessage({"result":result, "error": error, "id":id}) | [
"def",
"sendResponse",
"(",
"self",
",",
"id",
",",
"result",
",",
"error",
")",
":",
"self",
".",
"sendMessage",
"(",
"{",
"\"result\"",
":",
"result",
",",
"\"error\"",
":",
"error",
",",
"\"id\"",
":",
"id",
"}",
")"
] | sends a response to the peer | [
"sends",
"a",
"response",
"to",
"the",
"peer"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L114-L116 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | SimpleMessageHandler.newResponseEvent | def newResponseEvent(self):
"""creates a response event and adds it to a waiting list
When the reponse arrives it will be removed from the list.
"""
respEvt = ResponseEvent()
self.respLock.acquire()
eid = id(respEvt)
self.respEvents[eid] = respEvt
self... | python | def newResponseEvent(self):
"""creates a response event and adds it to a waiting list
When the reponse arrives it will be removed from the list.
"""
respEvt = ResponseEvent()
self.respLock.acquire()
eid = id(respEvt)
self.respEvents[eid] = respEvt
self... | [
"def",
"newResponseEvent",
"(",
"self",
")",
":",
"respEvt",
"=",
"ResponseEvent",
"(",
")",
"self",
".",
"respLock",
".",
"acquire",
"(",
")",
"eid",
"=",
"id",
"(",
"respEvt",
")",
"self",
".",
"respEvents",
"[",
"eid",
"]",
"=",
"respEvt",
"self",
... | creates a response event and adds it to a waiting list
When the reponse arrives it will be removed from the list. | [
"creates",
"a",
"response",
"event",
"and",
"adds",
"it",
"to",
"a",
"waiting",
"list",
"When",
"the",
"reponse",
"arrives",
"it",
"will",
"be",
"removed",
"from",
"the",
"list",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L118-L127 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | SimpleMessageHandler.handleResponse | def handleResponse(self, resp):
"""handles a response by fireing the response event for the response coming in"""
id=resp["id"]
evt = self.respEvents[id]
del(self.respEvents[id])
evt.handleResponse(resp) | python | def handleResponse(self, resp):
"""handles a response by fireing the response event for the response coming in"""
id=resp["id"]
evt = self.respEvents[id]
del(self.respEvents[id])
evt.handleResponse(resp) | [
"def",
"handleResponse",
"(",
"self",
",",
"resp",
")",
":",
"id",
"=",
"resp",
"[",
"\"id\"",
"]",
"evt",
"=",
"self",
".",
"respEvents",
"[",
"id",
"]",
"del",
"(",
"self",
".",
"respEvents",
"[",
"id",
"]",
")",
"evt",
".",
"handleResponse",
"("... | handles a response by fireing the response event for the response coming in | [
"handles",
"a",
"response",
"by",
"fireing",
"the",
"response",
"event",
"for",
"the",
"response",
"coming",
"in"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L145-L150 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | SimpleServiceHandler.handleRequest | def handleRequest(self, req):
"""handles a request by calling the appropriete method the service exposes"""
name = req["method"]
params = req["params"]
id=req["id"]
obj=None
try: #to get a callable obj
obj = getMethodByName(self.service, name)
except ... | python | def handleRequest(self, req):
"""handles a request by calling the appropriete method the service exposes"""
name = req["method"]
params = req["params"]
id=req["id"]
obj=None
try: #to get a callable obj
obj = getMethodByName(self.service, name)
except ... | [
"def",
"handleRequest",
"(",
"self",
",",
"req",
")",
":",
"name",
"=",
"req",
"[",
"\"method\"",
"]",
"params",
"=",
"req",
"[",
"\"params\"",
"]",
"id",
"=",
"req",
"[",
"\"id\"",
"]",
"obj",
"=",
"None",
"try",
":",
"obj",
"=",
"getMethodByName",
... | handles a request by calling the appropriete method the service exposes | [
"handles",
"a",
"request",
"by",
"calling",
"the",
"appropriete",
"method",
"the",
"service",
"exposes"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L205-L227 | train |
rwl/pylon | contrib/public/services/jsonrpc/__init__.py | SimpleServiceHandler.handleNotification | def handleNotification(self, req):
"""handles a notification request by calling the appropriete method the service exposes"""
name = req["method"]
params = req["params"]
try: #to get a callable obj
obj = getMethodByName(self.service, name)
rslt = obj(*params)
... | python | def handleNotification(self, req):
"""handles a notification request by calling the appropriete method the service exposes"""
name = req["method"]
params = req["params"]
try: #to get a callable obj
obj = getMethodByName(self.service, name)
rslt = obj(*params)
... | [
"def",
"handleNotification",
"(",
"self",
",",
"req",
")",
":",
"name",
"=",
"req",
"[",
"\"method\"",
"]",
"params",
"=",
"req",
"[",
"\"params\"",
"]",
"try",
":",
"obj",
"=",
"getMethodByName",
"(",
"self",
".",
"service",
",",
"name",
")",
"rslt",
... | handles a notification request by calling the appropriete method the service exposes | [
"handles",
"a",
"notification",
"request",
"by",
"calling",
"the",
"appropriete",
"method",
"the",
"service",
"exposes"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/contrib/public/services/jsonrpc/__init__.py#L229-L237 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.read | def read(self, file_or_filename):
""" Parses a PSAT data file and returns a case object
file_or_filename: File object or path to PSAT data file
return: Case object
"""
self.file_or_filename = file_or_filename
logger.info("Parsing PSAT case file [%s]." % file_or_... | python | def read(self, file_or_filename):
""" Parses a PSAT data file and returns a case object
file_or_filename: File object or path to PSAT data file
return: Case object
"""
self.file_or_filename = file_or_filename
logger.info("Parsing PSAT case file [%s]." % file_or_... | [
"def",
"read",
"(",
"self",
",",
"file_or_filename",
")",
":",
"self",
".",
"file_or_filename",
"=",
"file_or_filename",
"logger",
".",
"info",
"(",
"\"Parsing PSAT case file [%s].\"",
"%",
"file_or_filename",
")",
"t0",
"=",
"time",
".",
"time",
"(",
")",
"se... | Parses a PSAT data file and returns a case object
file_or_filename: File object or path to PSAT data file
return: Case object | [
"Parses",
"a",
"PSAT",
"data",
"file",
"and",
"returns",
"a",
"case",
"object"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L54-L101 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_bus_array_construct | def _get_bus_array_construct(self):
""" Returns a construct for an array of bus data.
"""
bus_no = integer.setResultsName("bus_no")
v_base = real.setResultsName("v_base") # kV
v_magnitude = Optional(real).setResultsName("v_magnitude")
v_angle = Optional(real).setResultsNa... | python | def _get_bus_array_construct(self):
""" Returns a construct for an array of bus data.
"""
bus_no = integer.setResultsName("bus_no")
v_base = real.setResultsName("v_base") # kV
v_magnitude = Optional(real).setResultsName("v_magnitude")
v_angle = Optional(real).setResultsNa... | [
"def",
"_get_bus_array_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"v_base",
"=",
"real",
".",
"setResultsName",
"(",
"\"v_base\"",
")",
"v_magnitude",
"=",
"Optional",
"(",
"real",
")",
".",
"s... | Returns a construct for an array of bus data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"bus",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L107-L128 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_line_array_construct | def _get_line_array_construct(self):
""" Returns a construct for an array of line data.
"""
from_bus = integer.setResultsName("fbus")
to_bus = integer.setResultsName("tbus")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
... | python | def _get_line_array_construct(self):
""" Returns a construct for an array of line data.
"""
from_bus = integer.setResultsName("fbus")
to_bus = integer.setResultsName("tbus")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
... | [
"def",
"_get_line_array_construct",
"(",
"self",
")",
":",
"from_bus",
"=",
"integer",
".",
"setResultsName",
"(",
"\"fbus\"",
")",
"to_bus",
"=",
"integer",
".",
"setResultsName",
"(",
"\"tbus\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s... | Returns a construct for an array of line data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"line",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L131-L160 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_slack_array_construct | def _get_slack_array_construct(self):
""" Returns a construct for an array of slack bus data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
v_magnitude = real.setResultsName("... | python | def _get_slack_array_construct(self):
""" Returns a construct for an array of slack bus data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
v_magnitude = real.setResultsName("... | [
"def",
"_get_slack_array_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"v_rating",
"=",
"real",
".",
"setResultsName",
"(",
... | Returns a construct for an array of slack bus data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"slack",
"bus",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L163-L190 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_pv_array_construct | def _get_pv_array_construct(self):
""" Returns a construct for an array of PV generator data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
p = real.setResultsName("p") # p.u.... | python | def _get_pv_array_construct(self):
""" Returns a construct for an array of PV generator data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
p = real.setResultsName("p") # p.u.... | [
"def",
"_get_pv_array_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"v_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"... | Returns a construct for an array of PV generator data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"PV",
"generator",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L193-L217 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_pq_array_construct | def _get_pq_array_construct(self):
""" Returns a construct for an array of PQ load data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
p = real.setResultsName("p") # p.u.
... | python | def _get_pq_array_construct(self):
""" Returns a construct for an array of PQ load data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
v_rating = real.setResultsName("v_rating") # kV
p = real.setResultsName("p") # p.u.
... | [
"def",
"_get_pq_array_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"v_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"... | Returns a construct for an array of PQ load data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"PQ",
"load",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L220-L242 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_demand_array_construct | def _get_demand_array_construct(self):
""" Returns a construct for an array of power demand data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
p_direction = real.setResultsName("p_direction") # p.u.
q_direction = real.setR... | python | def _get_demand_array_construct(self):
""" Returns a construct for an array of power demand data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
p_direction = real.setResultsName("p_direction") # p.u.
q_direction = real.setR... | [
"def",
"_get_demand_array_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"p_direction",
"=",
"real",
".",
"setResultsName",
"("... | Returns a construct for an array of power demand data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"power",
"demand",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L245-L278 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_supply_array_construct | def _get_supply_array_construct(self):
""" Returns a construct for an array of power supply data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
p_direction = real.setResultsName("p_direction") # CPF
p_bid_max = real.setResu... | python | def _get_supply_array_construct(self):
""" Returns a construct for an array of power supply data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
p_direction = real.setResultsName("p_direction") # CPF
p_bid_max = real.setResu... | [
"def",
"_get_supply_array_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"p_direction",
"=",
"real",
".",
"setResultsName",
"("... | Returns a construct for an array of power supply data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"power",
"supply",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L281-L316 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_generator_ramping_construct | def _get_generator_ramping_construct(self):
""" Returns a construct for an array of generator ramping data.
"""
supply_no = integer.setResultsName("supply_no")
s_rating = real.setResultsName("s_rating") # MVA
up_rate = real.setResultsName("up_rate") # p.u./h
down_rate = r... | python | def _get_generator_ramping_construct(self):
""" Returns a construct for an array of generator ramping data.
"""
supply_no = integer.setResultsName("supply_no")
s_rating = real.setResultsName("s_rating") # MVA
up_rate = real.setResultsName("up_rate") # p.u./h
down_rate = r... | [
"def",
"_get_generator_ramping_construct",
"(",
"self",
")",
":",
"supply_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"supply_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"up_rate",
"=",
"real",
".",
"setResultsName"... | Returns a construct for an array of generator ramping data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"generator",
"ramping",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L319-L340 | train |
rwl/pylon | pylon/io/psat.py | PSATReader._get_load_ramping_construct | def _get_load_ramping_construct(self):
""" Returns a construct for an array of load ramping data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
up_rate = real.setResultsName("up_rate") # p.u./h
down_rate = real.setResultsNa... | python | def _get_load_ramping_construct(self):
""" Returns a construct for an array of load ramping data.
"""
bus_no = integer.setResultsName("bus_no")
s_rating = real.setResultsName("s_rating") # MVA
up_rate = real.setResultsName("up_rate") # p.u./h
down_rate = real.setResultsNa... | [
"def",
"_get_load_ramping_construct",
"(",
"self",
")",
":",
"bus_no",
"=",
"integer",
".",
"setResultsName",
"(",
"\"bus_no\"",
")",
"s_rating",
"=",
"real",
".",
"setResultsName",
"(",
"\"s_rating\"",
")",
"up_rate",
"=",
"real",
".",
"setResultsName",
"(",
... | Returns a construct for an array of load ramping data. | [
"Returns",
"a",
"construct",
"for",
"an",
"array",
"of",
"load",
"ramping",
"data",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L343-L363 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.push_bus | def push_bus(self, tokens):
""" Adds a Bus object to the case.
"""
logger.debug("Pushing bus data: %s" % tokens)
bus = Bus()
bus.name = tokens["bus_no"]
bus.v_magnitude = tokens["v_magnitude"]
bus.v_angle = tokens["v_angle"]
bus.v_magnitude = tokens["v_ma... | python | def push_bus(self, tokens):
""" Adds a Bus object to the case.
"""
logger.debug("Pushing bus data: %s" % tokens)
bus = Bus()
bus.name = tokens["bus_no"]
bus.v_magnitude = tokens["v_magnitude"]
bus.v_angle = tokens["v_angle"]
bus.v_magnitude = tokens["v_ma... | [
"def",
"push_bus",
"(",
"self",
",",
"tokens",
")",
":",
"logger",
".",
"debug",
"(",
"\"Pushing bus data: %s\"",
"%",
"tokens",
")",
"bus",
"=",
"Bus",
"(",
")",
"bus",
".",
"name",
"=",
"tokens",
"[",
"\"bus_no\"",
"]",
"bus",
".",
"v_magnitude",
"="... | Adds a Bus object to the case. | [
"Adds",
"a",
"Bus",
"object",
"to",
"the",
"case",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L369-L381 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.push_line | def push_line(self, tokens):
""" Adds a Branch object to the case.
"""
logger.debug("Pushing line data: %s" % tokens)
from_bus = self.case.buses[tokens["fbus"]-1]
to_bus = self.case.buses[tokens["tbus"]-1]
e = Branch(from_bus=from_bus, to_bus=to_bus)
e.r = token... | python | def push_line(self, tokens):
""" Adds a Branch object to the case.
"""
logger.debug("Pushing line data: %s" % tokens)
from_bus = self.case.buses[tokens["fbus"]-1]
to_bus = self.case.buses[tokens["tbus"]-1]
e = Branch(from_bus=from_bus, to_bus=to_bus)
e.r = token... | [
"def",
"push_line",
"(",
"self",
",",
"tokens",
")",
":",
"logger",
".",
"debug",
"(",
"\"Pushing line data: %s\"",
"%",
"tokens",
")",
"from_bus",
"=",
"self",
".",
"case",
".",
"buses",
"[",
"tokens",
"[",
"\"fbus\"",
"]",
"-",
"1",
"]",
"to_bus",
"=... | Adds a Branch object to the case. | [
"Adds",
"a",
"Branch",
"object",
"to",
"the",
"case",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L390-L415 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.push_slack | def push_slack(self, tokens):
""" Finds the slack bus, adds a Generator with the appropriate data
and sets the bus type to slack.
"""
logger.debug("Pushing slack data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"] - 1]
g = Generator(bus)
g.q_max = tokens[... | python | def push_slack(self, tokens):
""" Finds the slack bus, adds a Generator with the appropriate data
and sets the bus type to slack.
"""
logger.debug("Pushing slack data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"] - 1]
g = Generator(bus)
g.q_max = tokens[... | [
"def",
"push_slack",
"(",
"self",
",",
"tokens",
")",
":",
"logger",
".",
"debug",
"(",
"\"Pushing slack data: %s\"",
"%",
"tokens",
")",
"bus",
"=",
"self",
".",
"case",
".",
"buses",
"[",
"tokens",
"[",
"\"bus_no\"",
"]",
"-",
"1",
"]",
"g",
"=",
"... | Finds the slack bus, adds a Generator with the appropriate data
and sets the bus type to slack. | [
"Finds",
"the",
"slack",
"bus",
"adds",
"a",
"Generator",
"with",
"the",
"appropriate",
"data",
"and",
"sets",
"the",
"bus",
"type",
"to",
"slack",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L418-L435 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.push_pv | def push_pv(self, tokens):
""" Creates and Generator object, populates it with data, finds its Bus
and adds it.
"""
logger.debug("Pushing PV data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"]-1]
g = Generator(bus)
g.p = tokens["p"]
g.q_max = toke... | python | def push_pv(self, tokens):
""" Creates and Generator object, populates it with data, finds its Bus
and adds it.
"""
logger.debug("Pushing PV data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"]-1]
g = Generator(bus)
g.p = tokens["p"]
g.q_max = toke... | [
"def",
"push_pv",
"(",
"self",
",",
"tokens",
")",
":",
"logger",
".",
"debug",
"(",
"\"Pushing PV data: %s\"",
"%",
"tokens",
")",
"bus",
"=",
"self",
".",
"case",
".",
"buses",
"[",
"tokens",
"[",
"\"bus_no\"",
"]",
"-",
"1",
"]",
"g",
"=",
"Genera... | Creates and Generator object, populates it with data, finds its Bus
and adds it. | [
"Creates",
"and",
"Generator",
"object",
"populates",
"it",
"with",
"data",
"finds",
"its",
"Bus",
"and",
"adds",
"it",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L438-L454 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.push_pq | def push_pq(self, tokens):
""" Creates and Load object, populates it with data, finds its Bus and
adds it.
"""
logger.debug("Pushing PQ data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"] - 1]
bus.p_demand = tokens["p"]
bus.q_demand = tokens["q"] | python | def push_pq(self, tokens):
""" Creates and Load object, populates it with data, finds its Bus and
adds it.
"""
logger.debug("Pushing PQ data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"] - 1]
bus.p_demand = tokens["p"]
bus.q_demand = tokens["q"] | [
"def",
"push_pq",
"(",
"self",
",",
"tokens",
")",
":",
"logger",
".",
"debug",
"(",
"\"Pushing PQ data: %s\"",
"%",
"tokens",
")",
"bus",
"=",
"self",
".",
"case",
".",
"buses",
"[",
"tokens",
"[",
"\"bus_no\"",
"]",
"-",
"1",
"]",
"bus",
".",
"p_de... | Creates and Load object, populates it with data, finds its Bus and
adds it. | [
"Creates",
"and",
"Load",
"object",
"populates",
"it",
"with",
"data",
"finds",
"its",
"Bus",
"and",
"adds",
"it",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L457-L465 | train |
rwl/pylon | pylon/io/psat.py | PSATReader.push_supply | def push_supply(self, tokens):
""" Adds OPF and CPF data to a Generator.
"""
logger.debug("Pushing supply data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"] - 1]
n_generators = len([g for g in self.case.generators if g.bus == bus])
if n_generators == 0:
... | python | def push_supply(self, tokens):
""" Adds OPF and CPF data to a Generator.
"""
logger.debug("Pushing supply data: %s" % tokens)
bus = self.case.buses[tokens["bus_no"] - 1]
n_generators = len([g for g in self.case.generators if g.bus == bus])
if n_generators == 0:
... | [
"def",
"push_supply",
"(",
"self",
",",
"tokens",
")",
":",
"logger",
".",
"debug",
"(",
"\"Pushing supply data: %s\"",
"%",
"tokens",
")",
"bus",
"=",
"self",
".",
"case",
".",
"buses",
"[",
"tokens",
"[",
"\"bus_no\"",
"]",
"-",
"1",
"]",
"n_generators... | Adds OPF and CPF data to a Generator. | [
"Adds",
"OPF",
"and",
"CPF",
"data",
"to",
"a",
"Generator",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psat.py#L493-L518 | train |
rwl/pylon | pylon/io/matpower.py | MATPOWERReader._parse_file | def _parse_file(self, file):
""" Parses the given file-like object.
"""
case = Case()
file.seek(0)
line = file.readline().split()
if line[0] != "function":
logger.error("Invalid data file header.")
return case
if line[1] != "mpc":
... | python | def _parse_file(self, file):
""" Parses the given file-like object.
"""
case = Case()
file.seek(0)
line = file.readline().split()
if line[0] != "function":
logger.error("Invalid data file header.")
return case
if line[1] != "mpc":
... | [
"def",
"_parse_file",
"(",
"self",
",",
"file",
")",
":",
"case",
"=",
"Case",
"(",
")",
"file",
".",
"seek",
"(",
"0",
")",
"line",
"=",
"file",
".",
"readline",
"(",
")",
".",
"split",
"(",
")",
"if",
"line",
"[",
"0",
"]",
"!=",
"\"function\... | Parses the given file-like object. | [
"Parses",
"the",
"given",
"file",
"-",
"like",
"object",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/matpower.py#L95-L125 | train |
rwl/pylon | pylon/io/matpower.py | MATPOWERWriter.write | def write(self, file_or_filename):
""" Writes case data to file in MATPOWER format.
"""
if isinstance(file_or_filename, basestring):
self._fcn_name, _ = splitext(basename(file_or_filename))
else:
self._fcn_name = self.case.name
self._fcn_name = self._fcn_... | python | def write(self, file_or_filename):
""" Writes case data to file in MATPOWER format.
"""
if isinstance(file_or_filename, basestring):
self._fcn_name, _ = splitext(basename(file_or_filename))
else:
self._fcn_name = self.case.name
self._fcn_name = self._fcn_... | [
"def",
"write",
"(",
"self",
",",
"file_or_filename",
")",
":",
"if",
"isinstance",
"(",
"file_or_filename",
",",
"basestring",
")",
":",
"self",
".",
"_fcn_name",
",",
"_",
"=",
"splitext",
"(",
"basename",
"(",
"file_or_filename",
")",
")",
"else",
":",
... | Writes case data to file in MATPOWER format. | [
"Writes",
"case",
"data",
"to",
"file",
"in",
"MATPOWER",
"format",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/matpower.py#L748-L758 | train |
rwl/pylon | pylon/io/matpower.py | MATPOWERWriter.write_case_data | def write_case_data(self, file):
""" Writes the case data in MATPOWER format.
"""
file.write("function mpc = %s\n" % self._fcn_name)
file.write('\n%%%% MATPOWER Case Format : Version %d\n' % 2)
file.write("mpc.version = '%d';\n" % 2)
file.write("\n%%%%----- Power Flow D... | python | def write_case_data(self, file):
""" Writes the case data in MATPOWER format.
"""
file.write("function mpc = %s\n" % self._fcn_name)
file.write('\n%%%% MATPOWER Case Format : Version %d\n' % 2)
file.write("mpc.version = '%d';\n" % 2)
file.write("\n%%%%----- Power Flow D... | [
"def",
"write_case_data",
"(",
"self",
",",
"file",
")",
":",
"file",
".",
"write",
"(",
"\"function mpc = %s\\n\"",
"%",
"self",
".",
"_fcn_name",
")",
"file",
".",
"write",
"(",
"'\\n%%%% MATPOWER Case Format : Version %d\\n'",
"%",
"2",
")",
"file",
".",
"w... | Writes the case data in MATPOWER format. | [
"Writes",
"the",
"case",
"data",
"in",
"MATPOWER",
"format",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/matpower.py#L767-L776 | train |
rwl/pylon | pylon/io/matpower.py | MATPOWERWriter.write_generator_cost_data | def write_generator_cost_data(self, file):
""" Writes generator cost data to file.
"""
file.write("\n%%%% generator cost data\n")
file.write("%%\t1\tstartup\tshutdown\tn\tx1\ty1\t...\txn\tyn\n")
file.write("%%\t2\tstartup\tshutdown\tn\tc(n-1)\t...\tc0\n")
file.write("%sge... | python | def write_generator_cost_data(self, file):
""" Writes generator cost data to file.
"""
file.write("\n%%%% generator cost data\n")
file.write("%%\t1\tstartup\tshutdown\tn\tx1\ty1\t...\txn\tyn\n")
file.write("%%\t2\tstartup\tshutdown\tn\tc(n-1)\t...\tc0\n")
file.write("%sge... | [
"def",
"write_generator_cost_data",
"(",
"self",
",",
"file",
")",
":",
"file",
".",
"write",
"(",
"\"\\n%%%% generator cost data\\n\"",
")",
"file",
".",
"write",
"(",
"\"%%\\t1\\tstartup\\tshutdown\\tn\\tx1\\ty1\\t...\\txn\\tyn\\n\"",
")",
"file",
".",
"write",
"(",
... | Writes generator cost data to file. | [
"Writes",
"generator",
"cost",
"data",
"to",
"file",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/matpower.py#L858-L888 | train |
rwl/pylon | pylon/io/matpower.py | MATPOWERWriter.write_area_data | def write_area_data(self, file):
""" Writes area data to file.
"""
file.write("%% area data" + "\n")
file.write("%\tno.\tprice_ref_bus" + "\n")
file.write("areas = [" + "\n")
# TODO: Implement areas
file.write("\t1\t1;" + "\n")
file.write("];" + "\n") | python | def write_area_data(self, file):
""" Writes area data to file.
"""
file.write("%% area data" + "\n")
file.write("%\tno.\tprice_ref_bus" + "\n")
file.write("areas = [" + "\n")
# TODO: Implement areas
file.write("\t1\t1;" + "\n")
file.write("];" + "\n") | [
"def",
"write_area_data",
"(",
"self",
",",
"file",
")",
":",
"file",
".",
"write",
"(",
"\"%% area data\"",
"+",
"\"\\n\"",
")",
"file",
".",
"write",
"(",
"\"%\\tno.\\tprice_ref_bus\"",
"+",
"\"\\n\"",
")",
"file",
".",
"write",
"(",
"\"areas = [\"",
"+",
... | Writes area data to file. | [
"Writes",
"area",
"data",
"to",
"file",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/matpower.py#L906-L915 | train |
finklabs/metrics | metrics/metricbase.py | MetricBase.process_file | def process_file(self, language, key, token_list):
"""
Initiate processing for each token.
Override this if you want tt control the processing of the tokens yourself.
"""
self.language = language
for tok in token_list:
self.process_token(tok) | python | def process_file(self, language, key, token_list):
"""
Initiate processing for each token.
Override this if you want tt control the processing of the tokens yourself.
"""
self.language = language
for tok in token_list:
self.process_token(tok) | [
"def",
"process_file",
"(",
"self",
",",
"language",
",",
"key",
",",
"token_list",
")",
":",
"self",
".",
"language",
"=",
"language",
"for",
"tok",
"in",
"token_list",
":",
"self",
".",
"process_token",
"(",
"tok",
")"
] | Initiate processing for each token.
Override this if you want tt control the processing of the tokens yourself. | [
"Initiate",
"processing",
"for",
"each",
"token",
"."
] | fd9974af498831664b9ae8e8f3834e1ec2e8a699 | https://github.com/finklabs/metrics/blob/fd9974af498831664b9ae8e8f3834e1ec2e8a699/metrics/metricbase.py#L26-L34 | train |
rwl/pylon | pyreto/renderer.py | ParticipantRenderer.draw_plot | def draw_plot(self):
""" Initialises plots of the environment.
"""
pylab.ion()
fig = pylab.figure(1)
# State plot.
# state_axis = fig.add_subplot(3, 1, 1) # numrows, numcols, fignum
# state_axis.title = 'State'
# state_axis.xlabel = 'Time (hours)'
# s... | python | def draw_plot(self):
""" Initialises plots of the environment.
"""
pylab.ion()
fig = pylab.figure(1)
# State plot.
# state_axis = fig.add_subplot(3, 1, 1) # numrows, numcols, fignum
# state_axis.title = 'State'
# state_axis.xlabel = 'Time (hours)'
# s... | [
"def",
"draw_plot",
"(",
"self",
")",
":",
"pylab",
".",
"ion",
"(",
")",
"fig",
"=",
"pylab",
".",
"figure",
"(",
"1",
")",
"reward_axis",
"=",
"fig",
".",
"add_subplot",
"(",
"3",
",",
"1",
",",
"3",
")",
"reward_lines",
"=",
"reward_axis",
".",
... | Initialises plots of the environment. | [
"Initialises",
"plots",
"of",
"the",
"environment",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/renderer.py#L177-L211 | train |
rwl/pylon | pylon/io/psse.py | PSSEWriter.write_case_data | def write_case_data(self, file):
""" Writes case data to file.
"""
change_code = 0
s_base = self.case.base_mva
timestr = time.strftime("%Y%m%d%H%M", time.gmtime())
file.write("%d, %8.2f, 30 / PSS(tm)E-30 RAW created by Pylon (%s).\n" %
(change_co... | python | def write_case_data(self, file):
""" Writes case data to file.
"""
change_code = 0
s_base = self.case.base_mva
timestr = time.strftime("%Y%m%d%H%M", time.gmtime())
file.write("%d, %8.2f, 30 / PSS(tm)E-30 RAW created by Pylon (%s).\n" %
(change_co... | [
"def",
"write_case_data",
"(",
"self",
",",
"file",
")",
":",
"change_code",
"=",
"0",
"s_base",
"=",
"self",
".",
"case",
".",
"base_mva",
"timestr",
"=",
"time",
".",
"strftime",
"(",
"\"%Y%m%d%H%M\"",
",",
"time",
".",
"gmtime",
"(",
")",
")",
"file... | Writes case data to file. | [
"Writes",
"case",
"data",
"to",
"file",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/io/psse.py#L387-L397 | train |
rwl/pylon | pyreto/util.py | plotGenCost | def plotGenCost(generators):
""" Plots the costs of the given generators.
"""
figure()
plots = []
for generator in generators:
if generator.pcost_model == PW_LINEAR:
x = [x for x, _ in generator.p_cost]
y = [y for _, y in generator.p_cost]
elif generator.pcost... | python | def plotGenCost(generators):
""" Plots the costs of the given generators.
"""
figure()
plots = []
for generator in generators:
if generator.pcost_model == PW_LINEAR:
x = [x for x, _ in generator.p_cost]
y = [y for _, y in generator.p_cost]
elif generator.pcost... | [
"def",
"plotGenCost",
"(",
"generators",
")",
":",
"figure",
"(",
")",
"plots",
"=",
"[",
"]",
"for",
"generator",
"in",
"generators",
":",
"if",
"generator",
".",
"pcost_model",
"==",
"PW_LINEAR",
":",
"x",
"=",
"[",
"x",
"for",
"x",
",",
"_",
"in",... | Plots the costs of the given generators. | [
"Plots",
"the",
"costs",
"of",
"the",
"given",
"generators",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/util.py#L129-L147 | train |
rwl/pylon | pyreto/util.py | ReSTExperimentWriter.write | def write(self, file):
""" Writes market experiment data to file in ReStructuredText format.
"""
# Write environment state data.
file.write("State\n")
file.write( ("-" * 5) + "\n")
self.writeDataTable(file, type="state")
# Write action data.
file.write("A... | python | def write(self, file):
""" Writes market experiment data to file in ReStructuredText format.
"""
# Write environment state data.
file.write("State\n")
file.write( ("-" * 5) + "\n")
self.writeDataTable(file, type="state")
# Write action data.
file.write("A... | [
"def",
"write",
"(",
"self",
",",
"file",
")",
":",
"file",
".",
"write",
"(",
"\"State\\n\"",
")",
"file",
".",
"write",
"(",
"(",
"\"-\"",
"*",
"5",
")",
"+",
"\"\\n\"",
")",
"self",
".",
"writeDataTable",
"(",
"file",
",",
"type",
"=",
"\"state\... | Writes market experiment data to file in ReStructuredText format. | [
"Writes",
"market",
"experiment",
"data",
"to",
"file",
"in",
"ReStructuredText",
"format",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/util.py#L210-L226 | train |
rwl/pylon | pyreto/util.py | ReSTExperimentWriter.writeDataTable | def writeDataTable(self, file, type):
""" Writes agent data to an ReST table. The 'type' argument may
be 'state', 'action' or 'reward'.
"""
agents = self.experiment.agents
numAgents = len(self.experiment.agents)
colWidth = 8
idxColWidth = 3
sep = ("=" *... | python | def writeDataTable(self, file, type):
""" Writes agent data to an ReST table. The 'type' argument may
be 'state', 'action' or 'reward'.
"""
agents = self.experiment.agents
numAgents = len(self.experiment.agents)
colWidth = 8
idxColWidth = 3
sep = ("=" *... | [
"def",
"writeDataTable",
"(",
"self",
",",
"file",
",",
"type",
")",
":",
"agents",
"=",
"self",
".",
"experiment",
".",
"agents",
"numAgents",
"=",
"len",
"(",
"self",
".",
"experiment",
".",
"agents",
")",
"colWidth",
"=",
"8",
"idxColWidth",
"=",
"3... | Writes agent data to an ReST table. The 'type' argument may
be 'state', 'action' or 'reward'. | [
"Writes",
"agent",
"data",
"to",
"an",
"ReST",
"table",
".",
"The",
"type",
"argument",
"may",
"be",
"state",
"action",
"or",
"reward",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/util.py#L229-L269 | train |
rwl/pylon | pyreto/continuous/task.py | ProfitTask.performAction | def performAction(self, action):
""" Execute one action.
"""
# print "ACTION:", action
self.t += 1
Task.performAction(self, action)
# self.addReward()
self.samples += 1 | python | def performAction(self, action):
""" Execute one action.
"""
# print "ACTION:", action
self.t += 1
Task.performAction(self, action)
# self.addReward()
self.samples += 1 | [
"def",
"performAction",
"(",
"self",
",",
"action",
")",
":",
"self",
".",
"t",
"+=",
"1",
"Task",
".",
"performAction",
"(",
"self",
",",
"action",
")",
"self",
".",
"samples",
"+=",
"1"
] | Execute one action. | [
"Execute",
"one",
"action",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pyreto/continuous/task.py#L74-L81 | train |
pymoca/pymoca | src/pymoca/backends/xml/model.py | split_dae_alg | def split_dae_alg(eqs: SYM, dx: SYM) -> Dict[str, SYM]:
"""Split equations into differential algebraic and algebraic only"""
dae = []
alg = []
for eq in ca.vertsplit(eqs):
if ca.depends_on(eq, dx):
dae.append(eq)
else:
alg.append(eq)
return {
'dae': ca... | python | def split_dae_alg(eqs: SYM, dx: SYM) -> Dict[str, SYM]:
"""Split equations into differential algebraic and algebraic only"""
dae = []
alg = []
for eq in ca.vertsplit(eqs):
if ca.depends_on(eq, dx):
dae.append(eq)
else:
alg.append(eq)
return {
'dae': ca... | [
"def",
"split_dae_alg",
"(",
"eqs",
":",
"SYM",
",",
"dx",
":",
"SYM",
")",
"->",
"Dict",
"[",
"str",
",",
"SYM",
"]",
":",
"dae",
"=",
"[",
"]",
"alg",
"=",
"[",
"]",
"for",
"eq",
"in",
"ca",
".",
"vertsplit",
"(",
"eqs",
")",
":",
"if",
"... | Split equations into differential algebraic and algebraic only | [
"Split",
"equations",
"into",
"differential",
"algebraic",
"and",
"algebraic",
"only"
] | 14b5eb7425e96689de6cc5c10f400895d586a978 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/src/pymoca/backends/xml/model.py#L174-L186 | train |
pymoca/pymoca | src/pymoca/backends/xml/model.py | permute | def permute(x: SYM, perm: List[int]) -> SYM:
"""Perumute a vector"""
x_s = []
for i in perm:
x_s.append(x[i])
return ca.vertcat(*x_s) | python | def permute(x: SYM, perm: List[int]) -> SYM:
"""Perumute a vector"""
x_s = []
for i in perm:
x_s.append(x[i])
return ca.vertcat(*x_s) | [
"def",
"permute",
"(",
"x",
":",
"SYM",
",",
"perm",
":",
"List",
"[",
"int",
"]",
")",
"->",
"SYM",
":",
"x_s",
"=",
"[",
"]",
"for",
"i",
"in",
"perm",
":",
"x_s",
".",
"append",
"(",
"x",
"[",
"i",
"]",
")",
"return",
"ca",
".",
"vertcat... | Perumute a vector | [
"Perumute",
"a",
"vector"
] | 14b5eb7425e96689de6cc5c10f400895d586a978 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/src/pymoca/backends/xml/model.py#L189-L194 | train |
pymoca/pymoca | src/pymoca/backends/xml/model.py | blt | def blt(f: List[SYM], x: List[SYM]) -> Dict[str, Any]:
"""
Sort equations by dependence
"""
J = ca.jacobian(f, x)
nblock, rowperm, colperm, rowblock, colblock, coarserow, coarsecol = J.sparsity().btf()
return {
'J': J,
'nblock': nblock,
'rowperm': rowperm,
'colper... | python | def blt(f: List[SYM], x: List[SYM]) -> Dict[str, Any]:
"""
Sort equations by dependence
"""
J = ca.jacobian(f, x)
nblock, rowperm, colperm, rowblock, colblock, coarserow, coarsecol = J.sparsity().btf()
return {
'J': J,
'nblock': nblock,
'rowperm': rowperm,
'colper... | [
"def",
"blt",
"(",
"f",
":",
"List",
"[",
"SYM",
"]",
",",
"x",
":",
"List",
"[",
"SYM",
"]",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"J",
"=",
"ca",
".",
"jacobian",
"(",
"f",
",",
"x",
")",
"nblock",
",",
"rowperm",
",",
"c... | Sort equations by dependence | [
"Sort",
"equations",
"by",
"dependence"
] | 14b5eb7425e96689de6cc5c10f400895d586a978 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/src/pymoca/backends/xml/model.py#L198-L213 | train |
pymoca/pymoca | src/pymoca/backends/xml/model.py | HybridOde.create_function_f_m | def create_function_f_m(self):
"""Discrete state dynamics"""
return ca.Function(
'f_m',
[self.t, self.x, self.y, self.m, self.p, self.c, self.pre_c, self.ng, self.nu],
[self.f_m],
['t', 'x', 'y', 'm', 'p', 'c', 'pre_c', 'ng', 'nu'], ['m'], self.func_opt) | python | def create_function_f_m(self):
"""Discrete state dynamics"""
return ca.Function(
'f_m',
[self.t, self.x, self.y, self.m, self.p, self.c, self.pre_c, self.ng, self.nu],
[self.f_m],
['t', 'x', 'y', 'm', 'p', 'c', 'pre_c', 'ng', 'nu'], ['m'], self.func_opt) | [
"def",
"create_function_f_m",
"(",
"self",
")",
":",
"return",
"ca",
".",
"Function",
"(",
"'f_m'",
",",
"[",
"self",
".",
"t",
",",
"self",
".",
"x",
",",
"self",
".",
"y",
",",
"self",
".",
"m",
",",
"self",
".",
"p",
",",
"self",
".",
"c",
... | Discrete state dynamics | [
"Discrete",
"state",
"dynamics"
] | 14b5eb7425e96689de6cc5c10f400895d586a978 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/src/pymoca/backends/xml/model.py#L94-L100 | train |
pymoca/pymoca | src/pymoca/backends/xml/model.py | HybridOde.create_function_f_J | def create_function_f_J(self):
"""Jacobian for state integration"""
return ca.Function(
'J',
[self.t, self.x, self.y, self.m, self.p, self.c, self.ng, self.nu],
[ca.jacobian(self.f_x_rhs, self.x)],
['t', 'x', 'y', 'm', 'p', 'c', 'ng', 'nu'], ['J'], self.fu... | python | def create_function_f_J(self):
"""Jacobian for state integration"""
return ca.Function(
'J',
[self.t, self.x, self.y, self.m, self.p, self.c, self.ng, self.nu],
[ca.jacobian(self.f_x_rhs, self.x)],
['t', 'x', 'y', 'm', 'p', 'c', 'ng', 'nu'], ['J'], self.fu... | [
"def",
"create_function_f_J",
"(",
"self",
")",
":",
"return",
"ca",
".",
"Function",
"(",
"'J'",
",",
"[",
"self",
".",
"t",
",",
"self",
".",
"x",
",",
"self",
".",
"y",
",",
"self",
".",
"m",
",",
"self",
".",
"p",
",",
"self",
".",
"c",
"... | Jacobian for state integration | [
"Jacobian",
"for",
"state",
"integration"
] | 14b5eb7425e96689de6cc5c10f400895d586a978 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/src/pymoca/backends/xml/model.py#L102-L108 | train |
pymoca/pymoca | src/pymoca/backends/xml/model.py | HybridDae.to_ode | def to_ode(self) -> HybridOde:
"""Convert to a HybridOde"""
res_split = split_dae_alg(self.f_x, self.dx)
alg = res_split['alg']
dae = res_split['dae']
x_rhs = tangent_approx(dae, self.dx, assert_linear=True)
y_rhs = tangent_approx(alg, self.y, assert_linear=True)
... | python | def to_ode(self) -> HybridOde:
"""Convert to a HybridOde"""
res_split = split_dae_alg(self.f_x, self.dx)
alg = res_split['alg']
dae = res_split['dae']
x_rhs = tangent_approx(dae, self.dx, assert_linear=True)
y_rhs = tangent_approx(alg, self.y, assert_linear=True)
... | [
"def",
"to_ode",
"(",
"self",
")",
"->",
"HybridOde",
":",
"res_split",
"=",
"split_dae_alg",
"(",
"self",
".",
"f_x",
",",
"self",
".",
"dx",
")",
"alg",
"=",
"res_split",
"[",
"'alg'",
"]",
"dae",
"=",
"res_split",
"[",
"'dae'",
"]",
"x_rhs",
"=",
... | Convert to a HybridOde | [
"Convert",
"to",
"a",
"HybridOde"
] | 14b5eb7425e96689de6cc5c10f400895d586a978 | https://github.com/pymoca/pymoca/blob/14b5eb7425e96689de6cc5c10f400895d586a978/src/pymoca/backends/xml/model.py#L143-L171 | train |
rwl/pylon | pylon/util.py | format_from_extension | def format_from_extension(fname):
""" Tries to infer a protocol from the file extension."""
_base, ext = os.path.splitext(fname)
if not ext:
return None
try:
format = known_extensions[ext.replace('.', '')]
except KeyError:
format = None
return format | python | def format_from_extension(fname):
""" Tries to infer a protocol from the file extension."""
_base, ext = os.path.splitext(fname)
if not ext:
return None
try:
format = known_extensions[ext.replace('.', '')]
except KeyError:
format = None
return format | [
"def",
"format_from_extension",
"(",
"fname",
")",
":",
"_base",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"fname",
")",
"if",
"not",
"ext",
":",
"return",
"None",
"try",
":",
"format",
"=",
"known_extensions",
"[",
"ext",
".",
"replace... | Tries to infer a protocol from the file extension. | [
"Tries",
"to",
"infer",
"a",
"protocol",
"from",
"the",
"file",
"extension",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L159-L168 | train |
rwl/pylon | pylon/util.py | pickle_matpower_cases | def pickle_matpower_cases(case_paths, case_format=2):
""" Parses the MATPOWER case files at the given paths and pickles the
resulting Case objects to the same directory.
"""
import pylon.io
if isinstance(case_paths, basestring):
case_paths = [case_paths]
for case_path in case_paths... | python | def pickle_matpower_cases(case_paths, case_format=2):
""" Parses the MATPOWER case files at the given paths and pickles the
resulting Case objects to the same directory.
"""
import pylon.io
if isinstance(case_paths, basestring):
case_paths = [case_paths]
for case_path in case_paths... | [
"def",
"pickle_matpower_cases",
"(",
"case_paths",
",",
"case_format",
"=",
"2",
")",
":",
"import",
"pylon",
".",
"io",
"if",
"isinstance",
"(",
"case_paths",
",",
"basestring",
")",
":",
"case_paths",
"=",
"[",
"case_paths",
"]",
"for",
"case_path",
"in",
... | Parses the MATPOWER case files at the given paths and pickles the
resulting Case objects to the same directory. | [
"Parses",
"the",
"MATPOWER",
"case",
"files",
"at",
"the",
"given",
"paths",
"and",
"pickles",
"the",
"resulting",
"Case",
"objects",
"to",
"the",
"same",
"directory",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L174-L194 | train |
rwl/pylon | pylon/util.py | fair_max | def fair_max(x):
""" Takes a single iterable as an argument and returns the same output as
the built-in function max with two output parameters, except that where
the maximum value occurs at more than one position in the vector, the
index is chosen randomly from these positions as opposed to just choos... | python | def fair_max(x):
""" Takes a single iterable as an argument and returns the same output as
the built-in function max with two output parameters, except that where
the maximum value occurs at more than one position in the vector, the
index is chosen randomly from these positions as opposed to just choos... | [
"def",
"fair_max",
"(",
"x",
")",
":",
"value",
"=",
"max",
"(",
"x",
")",
"i",
"=",
"[",
"x",
".",
"index",
"(",
"v",
")",
"for",
"v",
"in",
"x",
"if",
"v",
"==",
"value",
"]",
"idx",
"=",
"random",
".",
"choice",
"(",
"i",
")",
"return",
... | Takes a single iterable as an argument and returns the same output as
the built-in function max with two output parameters, except that where
the maximum value occurs at more than one position in the vector, the
index is chosen randomly from these positions as opposed to just choosing
the first occuran... | [
"Takes",
"a",
"single",
"iterable",
"as",
"an",
"argument",
"and",
"returns",
"the",
"same",
"output",
"as",
"the",
"built",
"-",
"in",
"function",
"max",
"with",
"two",
"output",
"parameters",
"except",
"that",
"where",
"the",
"maximum",
"value",
"occurs",
... | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L243-L256 | train |
rwl/pylon | pylon/util.py | factorial | def factorial(n):
""" Returns the factorial of n.
"""
f = 1
while (n > 0):
f = f * n
n = n - 1
return f | python | def factorial(n):
""" Returns the factorial of n.
"""
f = 1
while (n > 0):
f = f * n
n = n - 1
return f | [
"def",
"factorial",
"(",
"n",
")",
":",
"f",
"=",
"1",
"while",
"(",
"n",
">",
"0",
")",
":",
"f",
"=",
"f",
"*",
"n",
"n",
"=",
"n",
"-",
"1",
"return",
"f"
] | Returns the factorial of n. | [
"Returns",
"the",
"factorial",
"of",
"n",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L262-L269 | train |
rwl/pylon | pylon/util.py | _Named._get_name | def _get_name(self):
""" Returns the name, which is generated if it has not been already.
"""
if self._name is None:
self._name = self._generate_name()
return self._name | python | def _get_name(self):
""" Returns the name, which is generated if it has not been already.
"""
if self._name is None:
self._name = self._generate_name()
return self._name | [
"def",
"_get_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_name",
"is",
"None",
":",
"self",
".",
"_name",
"=",
"self",
".",
"_generate_name",
"(",
")",
"return",
"self",
".",
"_name"
] | Returns the name, which is generated if it has not been already. | [
"Returns",
"the",
"name",
"which",
"is",
"generated",
"if",
"it",
"has",
"not",
"been",
"already",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L61-L66 | train |
rwl/pylon | pylon/util.py | _Serializable.save_to_file_object | def save_to_file_object(self, fd, format=None, **kwargs):
""" Save the object to a given file like object in the given format.
"""
format = 'pickle' if format is None else format
save = getattr(self, "save_%s" % format, None)
if save is None:
raise ValueError("Unknown... | python | def save_to_file_object(self, fd, format=None, **kwargs):
""" Save the object to a given file like object in the given format.
"""
format = 'pickle' if format is None else format
save = getattr(self, "save_%s" % format, None)
if save is None:
raise ValueError("Unknown... | [
"def",
"save_to_file_object",
"(",
"self",
",",
"fd",
",",
"format",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"format",
"=",
"'pickle'",
"if",
"format",
"is",
"None",
"else",
"format",
"save",
"=",
"getattr",
"(",
"self",
",",
"\"save_%s\"",
"%",
"f... | Save the object to a given file like object in the given format. | [
"Save",
"the",
"object",
"to",
"a",
"given",
"file",
"like",
"object",
"in",
"the",
"given",
"format",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L98-L105 | train |
rwl/pylon | pylon/util.py | _Serializable.load_from_file_object | def load_from_file_object(cls, fd, format=None):
""" Load the object from a given file like object in the given format.
"""
format = 'pickle' if format is None else format
load = getattr(cls, "load_%s" % format, None)
if load is None:
raise ValueError("Unknown format ... | python | def load_from_file_object(cls, fd, format=None):
""" Load the object from a given file like object in the given format.
"""
format = 'pickle' if format is None else format
load = getattr(cls, "load_%s" % format, None)
if load is None:
raise ValueError("Unknown format ... | [
"def",
"load_from_file_object",
"(",
"cls",
",",
"fd",
",",
"format",
"=",
"None",
")",
":",
"format",
"=",
"'pickle'",
"if",
"format",
"is",
"None",
"else",
"format",
"load",
"=",
"getattr",
"(",
"cls",
",",
"\"load_%s\"",
"%",
"format",
",",
"None",
... | Load the object from a given file like object in the given format. | [
"Load",
"the",
"object",
"from",
"a",
"given",
"file",
"like",
"object",
"in",
"the",
"given",
"format",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L109-L116 | train |
rwl/pylon | pylon/util.py | _Serializable.save | def save(self, filename, format=None, **kwargs):
""" Save the object to file given by filename.
"""
if format is None:
# try to derive protocol from file extension
format = format_from_extension(filename)
with file(filename, 'wb') as fp:
self.save_to_f... | python | def save(self, filename, format=None, **kwargs):
""" Save the object to file given by filename.
"""
if format is None:
# try to derive protocol from file extension
format = format_from_extension(filename)
with file(filename, 'wb') as fp:
self.save_to_f... | [
"def",
"save",
"(",
"self",
",",
"filename",
",",
"format",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"format",
"is",
"None",
":",
"format",
"=",
"format_from_extension",
"(",
"filename",
")",
"with",
"file",
"(",
"filename",
",",
"'wb'",
")",
... | Save the object to file given by filename. | [
"Save",
"the",
"object",
"to",
"file",
"given",
"by",
"filename",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L119-L126 | train |
rwl/pylon | pylon/util.py | _Serializable.load | def load(cls, filename, format=None):
""" Return an instance of the class that is saved in the file with the
given filename in the specified format.
"""
if format is None:
# try to derive protocol from file extension
format = format_from_extension(filename)
... | python | def load(cls, filename, format=None):
""" Return an instance of the class that is saved in the file with the
given filename in the specified format.
"""
if format is None:
# try to derive protocol from file extension
format = format_from_extension(filename)
... | [
"def",
"load",
"(",
"cls",
",",
"filename",
",",
"format",
"=",
"None",
")",
":",
"if",
"format",
"is",
"None",
":",
"format",
"=",
"format_from_extension",
"(",
"filename",
")",
"with",
"file",
"(",
"filename",
",",
"'rbU'",
")",
"as",
"fp",
":",
"o... | Return an instance of the class that is saved in the file with the
given filename in the specified format. | [
"Return",
"an",
"instance",
"of",
"the",
"class",
"that",
"is",
"saved",
"in",
"the",
"file",
"with",
"the",
"given",
"filename",
"in",
"the",
"specified",
"format",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L130-L140 | train |
rwl/pylon | pylon/dc_pf.py | DCPF.solve | def solve(self):
""" Solves a DC power flow.
"""
case = self.case
logger.info("Starting DC power flow [%s]." % case.name)
t0 = time.time()
# Update bus indexes.
self.case.index_buses()
# Find the index of the refence bus.
ref_idx = self._get_refer... | python | def solve(self):
""" Solves a DC power flow.
"""
case = self.case
logger.info("Starting DC power flow [%s]." % case.name)
t0 = time.time()
# Update bus indexes.
self.case.index_buses()
# Find the index of the refence bus.
ref_idx = self._get_refer... | [
"def",
"solve",
"(",
"self",
")",
":",
"case",
"=",
"self",
".",
"case",
"logger",
".",
"info",
"(",
"\"Starting DC power flow [%s].\"",
"%",
"case",
".",
"name",
")",
"t0",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"case",
".",
"index_buses",
... | Solves a DC power flow. | [
"Solves",
"a",
"DC",
"power",
"flow",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dc_pf.py#L66-L95 | train |
rwl/pylon | pylon/dc_pf.py | DCPF._get_reference_index | def _get_reference_index(self, case):
""" Returns the index of the reference bus.
"""
refs = [bus._i for bus in case.connected_buses if bus.type == REFERENCE]
if len(refs) == 1:
return refs [0]
else:
logger.error("Single swing bus required for DCPF.")
... | python | def _get_reference_index(self, case):
""" Returns the index of the reference bus.
"""
refs = [bus._i for bus in case.connected_buses if bus.type == REFERENCE]
if len(refs) == 1:
return refs [0]
else:
logger.error("Single swing bus required for DCPF.")
... | [
"def",
"_get_reference_index",
"(",
"self",
",",
"case",
")",
":",
"refs",
"=",
"[",
"bus",
".",
"_i",
"for",
"bus",
"in",
"case",
".",
"connected_buses",
"if",
"bus",
".",
"type",
"==",
"REFERENCE",
"]",
"if",
"len",
"(",
"refs",
")",
"==",
"1",
"... | Returns the index of the reference bus. | [
"Returns",
"the",
"index",
"of",
"the",
"reference",
"bus",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dc_pf.py#L101-L109 | train |
rwl/pylon | pylon/dc_pf.py | DCPF._get_v_angle_guess | def _get_v_angle_guess(self, case):
""" Make the vector of voltage phase guesses.
"""
v_angle = array([bus.v_angle * (pi / 180.0)
for bus in case.connected_buses])
return v_angle | python | def _get_v_angle_guess(self, case):
""" Make the vector of voltage phase guesses.
"""
v_angle = array([bus.v_angle * (pi / 180.0)
for bus in case.connected_buses])
return v_angle | [
"def",
"_get_v_angle_guess",
"(",
"self",
",",
"case",
")",
":",
"v_angle",
"=",
"array",
"(",
"[",
"bus",
".",
"v_angle",
"*",
"(",
"pi",
"/",
"180.0",
")",
"for",
"bus",
"in",
"case",
".",
"connected_buses",
"]",
")",
"return",
"v_angle"
] | Make the vector of voltage phase guesses. | [
"Make",
"the",
"vector",
"of",
"voltage",
"phase",
"guesses",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dc_pf.py#L115-L120 | train |
rwl/pylon | pylon/dc_pf.py | DCPF._get_v_angle | def _get_v_angle(self, case, B, v_angle_guess, p_businj, iref):
""" Calculates the voltage phase angles.
"""
buses = case.connected_buses
pv_idxs = [bus._i for bus in buses if bus.type == PV]
pq_idxs = [bus._i for bus in buses if bus.type == PQ]
pvpq_idxs = pv_idxs + pq_... | python | def _get_v_angle(self, case, B, v_angle_guess, p_businj, iref):
""" Calculates the voltage phase angles.
"""
buses = case.connected_buses
pv_idxs = [bus._i for bus in buses if bus.type == PV]
pq_idxs = [bus._i for bus in buses if bus.type == PQ]
pvpq_idxs = pv_idxs + pq_... | [
"def",
"_get_v_angle",
"(",
"self",
",",
"case",
",",
"B",
",",
"v_angle_guess",
",",
"p_businj",
",",
"iref",
")",
":",
"buses",
"=",
"case",
".",
"connected_buses",
"pv_idxs",
"=",
"[",
"bus",
".",
"_i",
"for",
"bus",
"in",
"buses",
"if",
"bus",
".... | Calculates the voltage phase angles. | [
"Calculates",
"the",
"voltage",
"phase",
"angles",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dc_pf.py#L126-L159 | train |
rwl/pylon | pylon/dc_pf.py | DCPF._update_model | def _update_model(self, case, B, Bsrc, v_angle, p_srcinj, p_ref, ref_idx):
""" Updates the case with values computed from the voltage phase
angle solution.
"""
iref = ref_idx
base_mva = case.base_mva
buses = case.connected_buses
branches = case.online_branches... | python | def _update_model(self, case, B, Bsrc, v_angle, p_srcinj, p_ref, ref_idx):
""" Updates the case with values computed from the voltage phase
angle solution.
"""
iref = ref_idx
base_mva = case.base_mva
buses = case.connected_buses
branches = case.online_branches... | [
"def",
"_update_model",
"(",
"self",
",",
"case",
",",
"B",
",",
"Bsrc",
",",
"v_angle",
",",
"p_srcinj",
",",
"p_ref",
",",
"ref_idx",
")",
":",
"iref",
"=",
"ref_idx",
"base_mva",
"=",
"case",
".",
"base_mva",
"buses",
"=",
"case",
".",
"connected_bu... | Updates the case with values computed from the voltage phase
angle solution. | [
"Updates",
"the",
"case",
"with",
"values",
"computed",
"from",
"the",
"voltage",
"phase",
"angle",
"solution",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/dc_pf.py#L165-L192 | train |
rwl/pylon | pylon/case.py | Case.getSbus | def getSbus(self, buses=None):
""" Returns the net complex bus power injection vector in p.u.
"""
bs = self.buses if buses is None else buses
s = array([self.s_surplus(v) / self.base_mva for v in bs])
return s | python | def getSbus(self, buses=None):
""" Returns the net complex bus power injection vector in p.u.
"""
bs = self.buses if buses is None else buses
s = array([self.s_surplus(v) / self.base_mva for v in bs])
return s | [
"def",
"getSbus",
"(",
"self",
",",
"buses",
"=",
"None",
")",
":",
"bs",
"=",
"self",
".",
"buses",
"if",
"buses",
"is",
"None",
"else",
"buses",
"s",
"=",
"array",
"(",
"[",
"self",
".",
"s_surplus",
"(",
"v",
")",
"/",
"self",
".",
"base_mva",... | Returns the net complex bus power injection vector in p.u. | [
"Returns",
"the",
"net",
"complex",
"bus",
"power",
"injection",
"vector",
"in",
"p",
".",
"u",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L270-L275 | train |
rwl/pylon | pylon/case.py | Case.sort_generators | def sort_generators(self):
""" Reorders the list of generators according to bus index.
"""
self.generators.sort(key=lambda gn: gn.bus._i) | python | def sort_generators(self):
""" Reorders the list of generators according to bus index.
"""
self.generators.sort(key=lambda gn: gn.bus._i) | [
"def",
"sort_generators",
"(",
"self",
")",
":",
"self",
".",
"generators",
".",
"sort",
"(",
"key",
"=",
"lambda",
"gn",
":",
"gn",
".",
"bus",
".",
"_i",
")"
] | Reorders the list of generators according to bus index. | [
"Reorders",
"the",
"list",
"of",
"generators",
"according",
"to",
"bus",
"index",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L280-L283 | train |
rwl/pylon | pylon/case.py | Case.index_buses | def index_buses(self, buses=None, start=0):
""" Updates the indices of all buses.
@param start: Starting index, typically 0 or 1.
@type start: int
"""
bs = self.connected_buses if buses is None else buses
for i, b in enumerate(bs):
b._i = start + i | python | def index_buses(self, buses=None, start=0):
""" Updates the indices of all buses.
@param start: Starting index, typically 0 or 1.
@type start: int
"""
bs = self.connected_buses if buses is None else buses
for i, b in enumerate(bs):
b._i = start + i | [
"def",
"index_buses",
"(",
"self",
",",
"buses",
"=",
"None",
",",
"start",
"=",
"0",
")",
":",
"bs",
"=",
"self",
".",
"connected_buses",
"if",
"buses",
"is",
"None",
"else",
"buses",
"for",
"i",
",",
"b",
"in",
"enumerate",
"(",
"bs",
")",
":",
... | Updates the indices of all buses.
@param start: Starting index, typically 0 or 1.
@type start: int | [
"Updates",
"the",
"indices",
"of",
"all",
"buses",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L289-L297 | train |
rwl/pylon | pylon/case.py | Case.index_branches | def index_branches(self, branches=None, start=0):
""" Updates the indices of all branches.
@param start: Starting index, typically 0 or 1.
@type start: int
"""
ln = self.online_branches if branches is None else branches
for i, l in enumerate(ln):
l._i = start... | python | def index_branches(self, branches=None, start=0):
""" Updates the indices of all branches.
@param start: Starting index, typically 0 or 1.
@type start: int
"""
ln = self.online_branches if branches is None else branches
for i, l in enumerate(ln):
l._i = start... | [
"def",
"index_branches",
"(",
"self",
",",
"branches",
"=",
"None",
",",
"start",
"=",
"0",
")",
":",
"ln",
"=",
"self",
".",
"online_branches",
"if",
"branches",
"is",
"None",
"else",
"branches",
"for",
"i",
",",
"l",
"in",
"enumerate",
"(",
"ln",
"... | Updates the indices of all branches.
@param start: Starting index, typically 0 or 1.
@type start: int | [
"Updates",
"the",
"indices",
"of",
"all",
"branches",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L300-L308 | train |
rwl/pylon | pylon/case.py | Case.s_supply | def s_supply(self, bus):
""" Returns the total complex power generation capacity.
"""
Sg = array([complex(g.p, g.q) for g in self.generators if
(g.bus == bus) and not g.is_load], dtype=complex64)
if len(Sg):
return sum(Sg)
else:
return ... | python | def s_supply(self, bus):
""" Returns the total complex power generation capacity.
"""
Sg = array([complex(g.p, g.q) for g in self.generators if
(g.bus == bus) and not g.is_load], dtype=complex64)
if len(Sg):
return sum(Sg)
else:
return ... | [
"def",
"s_supply",
"(",
"self",
",",
"bus",
")",
":",
"Sg",
"=",
"array",
"(",
"[",
"complex",
"(",
"g",
".",
"p",
",",
"g",
".",
"q",
")",
"for",
"g",
"in",
"self",
".",
"generators",
"if",
"(",
"g",
".",
"bus",
"==",
"bus",
")",
"and",
"n... | Returns the total complex power generation capacity. | [
"Returns",
"the",
"total",
"complex",
"power",
"generation",
"capacity",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L314-L323 | train |
rwl/pylon | pylon/case.py | Case.s_demand | def s_demand(self, bus):
""" Returns the total complex power demand.
"""
Svl = array([complex(g.p, g.q) for g in self.generators if
(g.bus == bus) and g.is_load], dtype=complex64)
Sd = complex(bus.p_demand, bus.q_demand)
return -sum(Svl) + Sd | python | def s_demand(self, bus):
""" Returns the total complex power demand.
"""
Svl = array([complex(g.p, g.q) for g in self.generators if
(g.bus == bus) and g.is_load], dtype=complex64)
Sd = complex(bus.p_demand, bus.q_demand)
return -sum(Svl) + Sd | [
"def",
"s_demand",
"(",
"self",
",",
"bus",
")",
":",
"Svl",
"=",
"array",
"(",
"[",
"complex",
"(",
"g",
".",
"p",
",",
"g",
".",
"q",
")",
"for",
"g",
"in",
"self",
".",
"generators",
"if",
"(",
"g",
".",
"bus",
"==",
"bus",
")",
"and",
"... | Returns the total complex power demand. | [
"Returns",
"the",
"total",
"complex",
"power",
"demand",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L326-L334 | train |
rwl/pylon | pylon/case.py | Case.reset | def reset(self):
""" Resets the readonly variables for all of the case components.
"""
for bus in self.buses:
bus.reset()
for branch in self.branches:
branch.reset()
for generator in self.generators:
generator.reset() | python | def reset(self):
""" Resets the readonly variables for all of the case components.
"""
for bus in self.buses:
bus.reset()
for branch in self.branches:
branch.reset()
for generator in self.generators:
generator.reset() | [
"def",
"reset",
"(",
"self",
")",
":",
"for",
"bus",
"in",
"self",
".",
"buses",
":",
"bus",
".",
"reset",
"(",
")",
"for",
"branch",
"in",
"self",
".",
"branches",
":",
"branch",
".",
"reset",
"(",
")",
"for",
"generator",
"in",
"self",
".",
"ge... | Resets the readonly variables for all of the case components. | [
"Resets",
"the",
"readonly",
"variables",
"for",
"all",
"of",
"the",
"case",
"components",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L911-L919 | train |
rwl/pylon | pylon/case.py | Case.save_matpower | def save_matpower(self, fd):
""" Serialize the case as a MATPOWER data file.
"""
from pylon.io import MATPOWERWriter
MATPOWERWriter(self).write(fd) | python | def save_matpower(self, fd):
""" Serialize the case as a MATPOWER data file.
"""
from pylon.io import MATPOWERWriter
MATPOWERWriter(self).write(fd) | [
"def",
"save_matpower",
"(",
"self",
",",
"fd",
")",
":",
"from",
"pylon",
".",
"io",
"import",
"MATPOWERWriter",
"MATPOWERWriter",
"(",
"self",
")",
".",
"write",
"(",
"fd",
")"
] | Serialize the case as a MATPOWER data file. | [
"Serialize",
"the",
"case",
"as",
"a",
"MATPOWER",
"data",
"file",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L925-L929 | train |
rwl/pylon | pylon/case.py | Case.load_psat | def load_psat(cls, fd):
""" Returns a case object from the given PSAT data file.
"""
from pylon.io.psat import PSATReader
return PSATReader().read(fd) | python | def load_psat(cls, fd):
""" Returns a case object from the given PSAT data file.
"""
from pylon.io.psat import PSATReader
return PSATReader().read(fd) | [
"def",
"load_psat",
"(",
"cls",
",",
"fd",
")",
":",
"from",
"pylon",
".",
"io",
".",
"psat",
"import",
"PSATReader",
"return",
"PSATReader",
"(",
")",
".",
"read",
"(",
"fd",
")"
] | Returns a case object from the given PSAT data file. | [
"Returns",
"a",
"case",
"object",
"from",
"the",
"given",
"PSAT",
"data",
"file",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L960-L964 | train |
rwl/pylon | pylon/case.py | Case.save_rst | def save_rst(self, fd):
""" Save a reStructuredText representation of the case.
"""
from pylon.io import ReSTWriter
ReSTWriter(self).write(fd) | python | def save_rst(self, fd):
""" Save a reStructuredText representation of the case.
"""
from pylon.io import ReSTWriter
ReSTWriter(self).write(fd) | [
"def",
"save_rst",
"(",
"self",
",",
"fd",
")",
":",
"from",
"pylon",
".",
"io",
"import",
"ReSTWriter",
"ReSTWriter",
"(",
"self",
")",
".",
"write",
"(",
"fd",
")"
] | Save a reStructuredText representation of the case. | [
"Save",
"a",
"reStructuredText",
"representation",
"of",
"the",
"case",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L967-L971 | train |
rwl/pylon | pylon/case.py | Case.save_csv | def save_csv(self, fd):
""" Saves the case as a series of Comma-Separated Values.
"""
from pylon.io.excel import CSVWriter
CSVWriter(self).write(fd) | python | def save_csv(self, fd):
""" Saves the case as a series of Comma-Separated Values.
"""
from pylon.io.excel import CSVWriter
CSVWriter(self).write(fd) | [
"def",
"save_csv",
"(",
"self",
",",
"fd",
")",
":",
"from",
"pylon",
".",
"io",
".",
"excel",
"import",
"CSVWriter",
"CSVWriter",
"(",
"self",
")",
".",
"write",
"(",
"fd",
")"
] | Saves the case as a series of Comma-Separated Values. | [
"Saves",
"the",
"case",
"as",
"a",
"series",
"of",
"Comma",
"-",
"Separated",
"Values",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L974-L978 | train |
rwl/pylon | pylon/case.py | Case.save_excel | def save_excel(self, fd):
""" Saves the case as an Excel spreadsheet.
"""
from pylon.io.excel import ExcelWriter
ExcelWriter(self).write(fd) | python | def save_excel(self, fd):
""" Saves the case as an Excel spreadsheet.
"""
from pylon.io.excel import ExcelWriter
ExcelWriter(self).write(fd) | [
"def",
"save_excel",
"(",
"self",
",",
"fd",
")",
":",
"from",
"pylon",
".",
"io",
".",
"excel",
"import",
"ExcelWriter",
"ExcelWriter",
"(",
"self",
")",
".",
"write",
"(",
"fd",
")"
] | Saves the case as an Excel spreadsheet. | [
"Saves",
"the",
"case",
"as",
"an",
"Excel",
"spreadsheet",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L981-L985 | train |
rwl/pylon | pylon/case.py | Case.save_dot | def save_dot(self, fd):
""" Saves a representation of the case in the Graphviz DOT language.
"""
from pylon.io import DotWriter
DotWriter(self).write(fd) | python | def save_dot(self, fd):
""" Saves a representation of the case in the Graphviz DOT language.
"""
from pylon.io import DotWriter
DotWriter(self).write(fd) | [
"def",
"save_dot",
"(",
"self",
",",
"fd",
")",
":",
"from",
"pylon",
".",
"io",
"import",
"DotWriter",
"DotWriter",
"(",
"self",
")",
".",
"write",
"(",
"fd",
")"
] | Saves a representation of the case in the Graphviz DOT language. | [
"Saves",
"a",
"representation",
"of",
"the",
"case",
"in",
"the",
"Graphviz",
"DOT",
"language",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/case.py#L988-L992 | train |
rwl/pylon | pylon/ac_pf.py | _ACPF.solve | def solve(self):
""" Runs a power flow
@rtype: dict
@return: Solution dictionary with the following keys:
- C{V} - final complex voltages
- C{converged} - boolean value indicating if the solver
converged or not
- C{it... | python | def solve(self):
""" Runs a power flow
@rtype: dict
@return: Solution dictionary with the following keys:
- C{V} - final complex voltages
- C{converged} - boolean value indicating if the solver
converged or not
- C{it... | [
"def",
"solve",
"(",
"self",
")",
":",
"self",
".",
"case",
".",
"reset",
"(",
")",
"b",
",",
"l",
",",
"g",
",",
"_",
",",
"_",
",",
"_",
",",
"_",
"=",
"self",
".",
"_unpack_case",
"(",
"self",
".",
"case",
")",
"self",
".",
"case",
".",
... | Runs a power flow
@rtype: dict
@return: Solution dictionary with the following keys:
- C{V} - final complex voltages
- C{converged} - boolean value indicating if the solver
converged or not
- C{iterations} - the number of ite... | [
"Runs",
"a",
"power",
"flow"
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L94-L166 | train |
rwl/pylon | pylon/ac_pf.py | _ACPF._unpack_case | def _unpack_case(self, case):
""" Returns the contents of the case to be used in the OPF.
"""
base_mva = case.base_mva
b = case.connected_buses
l = case.online_branches
g = case.online_generators
nb = len(b)
nl = len(l)
ng = len(g)
return ... | python | def _unpack_case(self, case):
""" Returns the contents of the case to be used in the OPF.
"""
base_mva = case.base_mva
b = case.connected_buses
l = case.online_branches
g = case.online_generators
nb = len(b)
nl = len(l)
ng = len(g)
return ... | [
"def",
"_unpack_case",
"(",
"self",
",",
"case",
")",
":",
"base_mva",
"=",
"case",
".",
"base_mva",
"b",
"=",
"case",
".",
"connected_buses",
"l",
"=",
"case",
".",
"online_branches",
"g",
"=",
"case",
".",
"online_generators",
"nb",
"=",
"len",
"(",
... | Returns the contents of the case to be used in the OPF. | [
"Returns",
"the",
"contents",
"of",
"the",
"case",
"to",
"be",
"used",
"in",
"the",
"OPF",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L169-L180 | train |
rwl/pylon | pylon/ac_pf.py | _ACPF._index_buses | def _index_buses(self, buses):
""" Set up indexing for updating v.
"""
refs = [bus._i for bus in buses if bus.type == REFERENCE]
# if len(refs) != 1:
# raise SlackBusError
pv = [bus._i for bus in buses if bus.type == PV]
pq = [bus._i for bus in buses if bus.type... | python | def _index_buses(self, buses):
""" Set up indexing for updating v.
"""
refs = [bus._i for bus in buses if bus.type == REFERENCE]
# if len(refs) != 1:
# raise SlackBusError
pv = [bus._i for bus in buses if bus.type == PV]
pq = [bus._i for bus in buses if bus.type... | [
"def",
"_index_buses",
"(",
"self",
",",
"buses",
")",
":",
"refs",
"=",
"[",
"bus",
".",
"_i",
"for",
"bus",
"in",
"buses",
"if",
"bus",
".",
"type",
"==",
"REFERENCE",
"]",
"pv",
"=",
"[",
"bus",
".",
"_i",
"for",
"bus",
"in",
"buses",
"if",
... | Set up indexing for updating v. | [
"Set",
"up",
"indexing",
"for",
"updating",
"v",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L183-L193 | train |
rwl/pylon | pylon/ac_pf.py | _ACPF._initial_voltage | def _initial_voltage(self, buses, generators):
""" Returns the initial vector of complex bus voltages.
The bus voltage vector contains the set point for generator
(including ref bus) buses, and the reference angle of the swing
bus, as well as an initial guess for remaining magnitudes an... | python | def _initial_voltage(self, buses, generators):
""" Returns the initial vector of complex bus voltages.
The bus voltage vector contains the set point for generator
(including ref bus) buses, and the reference angle of the swing
bus, as well as an initial guess for remaining magnitudes an... | [
"def",
"_initial_voltage",
"(",
"self",
",",
"buses",
",",
"generators",
")",
":",
"Vm",
"=",
"array",
"(",
"[",
"bus",
".",
"v_magnitude",
"for",
"bus",
"in",
"buses",
"]",
")",
"Va",
"=",
"array",
"(",
"[",
"bus",
".",
"v_angle",
"*",
"(",
"pi",
... | Returns the initial vector of complex bus voltages.
The bus voltage vector contains the set point for generator
(including ref bus) buses, and the reference angle of the swing
bus, as well as an initial guess for remaining magnitudes and
angles. | [
"Returns",
"the",
"initial",
"vector",
"of",
"complex",
"bus",
"voltages",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L196-L216 | train |
rwl/pylon | pylon/ac_pf.py | NewtonPF._one_iteration | def _one_iteration(self, F, Ybus, V, Vm, Va, pv, pq, pvpq):
""" Performs one Newton iteration.
"""
J = self._build_jacobian(Ybus, V, pv, pq, pvpq)
# Update step.
dx = -1 * spsolve(J, F)
# dx = -1 * linalg.lstsq(J.todense(), F)[0]
# Update voltage vector.
... | python | def _one_iteration(self, F, Ybus, V, Vm, Va, pv, pq, pvpq):
""" Performs one Newton iteration.
"""
J = self._build_jacobian(Ybus, V, pv, pq, pvpq)
# Update step.
dx = -1 * spsolve(J, F)
# dx = -1 * linalg.lstsq(J.todense(), F)[0]
# Update voltage vector.
... | [
"def",
"_one_iteration",
"(",
"self",
",",
"F",
",",
"Ybus",
",",
"V",
",",
"Vm",
",",
"Va",
",",
"pv",
",",
"pq",
",",
"pvpq",
")",
":",
"J",
"=",
"self",
".",
"_build_jacobian",
"(",
"Ybus",
",",
"V",
",",
"pv",
",",
"pq",
",",
"pvpq",
")",... | Performs one Newton iteration. | [
"Performs",
"one",
"Newton",
"iteration",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L265-L287 | train |
rwl/pylon | pylon/ac_pf.py | NewtonPF._build_jacobian | def _build_jacobian(self, Ybus, V, pv, pq, pvpq):
""" Returns the Jacobian matrix.
"""
pq_col = [[i] for i in pq]
pvpq_col = [[i] for i in pvpq]
dS_dVm, dS_dVa = self.case.dSbus_dV(Ybus, V)
J11 = dS_dVa[pvpq_col, pvpq].real
J12 = dS_dVm[pvpq_col, pq].real
... | python | def _build_jacobian(self, Ybus, V, pv, pq, pvpq):
""" Returns the Jacobian matrix.
"""
pq_col = [[i] for i in pq]
pvpq_col = [[i] for i in pvpq]
dS_dVm, dS_dVa = self.case.dSbus_dV(Ybus, V)
J11 = dS_dVa[pvpq_col, pvpq].real
J12 = dS_dVm[pvpq_col, pq].real
... | [
"def",
"_build_jacobian",
"(",
"self",
",",
"Ybus",
",",
"V",
",",
"pv",
",",
"pq",
",",
"pvpq",
")",
":",
"pq_col",
"=",
"[",
"[",
"i",
"]",
"for",
"i",
"in",
"pq",
"]",
"pvpq_col",
"=",
"[",
"[",
"i",
"]",
"for",
"i",
"in",
"pvpq",
"]",
"... | Returns the Jacobian matrix. | [
"Returns",
"the",
"Jacobian",
"matrix",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L325-L344 | train |
rwl/pylon | pylon/ac_pf.py | FastDecoupledPF._evaluate_mismatch | def _evaluate_mismatch(self, Ybus, V, Sbus, pq, pvpq):
""" Evaluates the mismatch.
"""
mis = (multiply(V, conj(Ybus * V)) - Sbus) / abs(V)
P = mis[pvpq].real
Q = mis[pq].imag
return P, Q | python | def _evaluate_mismatch(self, Ybus, V, Sbus, pq, pvpq):
""" Evaluates the mismatch.
"""
mis = (multiply(V, conj(Ybus * V)) - Sbus) / abs(V)
P = mis[pvpq].real
Q = mis[pq].imag
return P, Q | [
"def",
"_evaluate_mismatch",
"(",
"self",
",",
"Ybus",
",",
"V",
",",
"Sbus",
",",
"pq",
",",
"pvpq",
")",
":",
"mis",
"=",
"(",
"multiply",
"(",
"V",
",",
"conj",
"(",
"Ybus",
"*",
"V",
")",
")",
"-",
"Sbus",
")",
"/",
"abs",
"(",
"V",
")",
... | Evaluates the mismatch. | [
"Evaluates",
"the",
"mismatch",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L444-L452 | train |
rwl/pylon | pylon/ac_pf.py | FastDecoupledPF._p_iteration | def _p_iteration(self, P, Bp_solver, Vm, Va, pvpq):
""" Performs a P iteration, updates Va.
"""
dVa = -Bp_solver.solve(P)
# Update voltage.
Va[pvpq] = Va[pvpq] + dVa
V = Vm * exp(1j * Va)
return V, Vm, Va | python | def _p_iteration(self, P, Bp_solver, Vm, Va, pvpq):
""" Performs a P iteration, updates Va.
"""
dVa = -Bp_solver.solve(P)
# Update voltage.
Va[pvpq] = Va[pvpq] + dVa
V = Vm * exp(1j * Va)
return V, Vm, Va | [
"def",
"_p_iteration",
"(",
"self",
",",
"P",
",",
"Bp_solver",
",",
"Vm",
",",
"Va",
",",
"pvpq",
")",
":",
"dVa",
"=",
"-",
"Bp_solver",
".",
"solve",
"(",
"P",
")",
"Va",
"[",
"pvpq",
"]",
"=",
"Va",
"[",
"pvpq",
"]",
"+",
"dVa",
"V",
"=",... | Performs a P iteration, updates Va. | [
"Performs",
"a",
"P",
"iteration",
"updates",
"Va",
"."
] | 916514255db1ae1661406f0283df756baf960d14 | https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/ac_pf.py#L479-L488 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.