docstring
stringlengths
52
499
function
stringlengths
67
35.2k
__index_level_0__
int64
52.6k
1.16M
Returns a TensorFluent for the minimum function. Args: x: The first operand. y: The second operand. Returns: A TensorFluent wrapping the minimum function.
def min(cls, x: 'TensorFluent', y: 'TensorFluent') -> 'TensorFluent': return cls._binary_op(x, y, tf.minimum, tf.float32)
727,773
Returns a TensorFluent for the control op if-then-else. Args: condition: Boolean fluent for the if condition. true_case: Fluent returned in the true clause. false_case: Fluent returned in the false clause. Returns: A TensorFluent wrapping the if-then-els...
def if_then_else(cls, condition: 'TensorFluent', true_case: 'TensorFluent', false_case: 'TensorFluent') -> 'TensorFluent': true = TensorFluent.constant(True, tf.bool) false = TensorFluent.constant(False, tf.bool) ite = (condition == true) * true_case ...
727,774
Returns a TensorFluent for the binary `op` applied to fluents `x` and `y`. Args: x: The first operand. y: The second operand. op: The binary operator. dtype: The output's data type. Returns: A TensorFluent wrapping the binary operator's outpu...
def _binary_op(cls, x: 'TensorFluent', y: 'TensorFluent', op: Callable[[tf.Tensor, tf.Tensor], tf.Tensor], dtype: tf.DType) -> 'TensorFluent': # scope s1 = x.scope.as_list() s2 = y.scope.as_list() scope, perm1, perm2 = TensorFluent...
727,775
Returns a TensorFluent for the unary `op` applied to fluent `x`. Args: x: The input fluent. op: The unary operation. dtype: The output's data type. Returns: A TensorFluent wrapping the unary operator's output.
def _unary_op(cls, x: 'TensorFluent', op: Callable[[tf.Tensor], tf.Tensor], dtype: tf.DType) -> 'TensorFluent': x = x.cast(dtype) t = op(x.tensor) scope = x.scope.as_list() batch = x.batch return TensorFluent(t, scope, batch=batch)
727,776
Returns a TensorFluent for the aggregation `op` applied to fluent `x`. Args: op: The aggregation operation. x: The input fluent. vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the aggregation operator's output.
def _aggregation_op(cls, op: Callable[[tf.Tensor, Optional[Sequence[int]]], tf.Tensor], x: 'TensorFluent', vars_list: List[str]) -> 'TensorFluent': axis = cls._varslist2axis(x, vars_list) t = op(x.tensor, axis) scope = [] for var in x.scope.a...
727,777
Maps the `vars_list` into a list of axis indices corresponding to the `fluent` scope. Args: x: The fluent. vars_list: The list of variables to be aggregated over. Returns: List[int]: a list of axis.
def _varslist2axis(cls, fluent: 'TensorFluent', vars_list: List[str]) -> List[int]: axis = [] for var in vars_list: if var in fluent.scope.as_list(): ax = fluent.scope.index(var) if fluent.batch: ax += 1 axis.append...
727,778
Returns a TensorFluent for the cast operation with given `dtype`. Args: dtype: The output's data type. Returns: A TensorFluent wrapping the cast operation.
def cast(self, dtype: tf.DType) -> 'TensorFluent': if self.dtype == dtype: return self t = tf.cast(self.tensor, dtype) scope = self.scope.as_list() batch = self.batch return TensorFluent(t, scope, batch=batch)
727,779
Returns a TensorFluent for the reshape operation with given `shape`. Args: shape: The output's shape. Returns: A TensorFluent wrapping the reshape operation.
def reshape(self, shape: tf.TensorShape) -> 'TensorFluent': t = tf.reshape(self.tensor, shape) scope = self.scope.as_list() batch = self.batch return TensorFluent(t, scope, batch=batch)
727,780
Returns a TensorFluent for the transpose operation with given `permutation`. Args: permutation: The output's shape permutation. Returns: A TensorFluent wrapping the transpose operation.
def transpose(self, permutation: Optional[List[int]] = None) -> 'TensorFluent': if permutation == []: return self t = tf.transpose(self.tensor, permutation) if permutation != [] else self.tensor scope = self.scope.as_list() batch = self.batch return TensorFlu...
727,781
Returns the TensorFluent for the sum aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the sum aggregation function.
def sum(self, vars_list: List[str]) -> 'TensorFluent': operand = self if operand.dtype == tf.bool: operand = operand.cast(tf.float32) return self._aggregation_op(tf.reduce_sum, operand, vars_list)
727,782
Returns the TensorFluent for the avg aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the avg aggregation function.
def avg(self, vars_list: List[str]) -> 'TensorFluent': operand = self if operand.dtype == tf.bool: operand = operand.cast(tf.float32) return self._aggregation_op(tf.reduce_mean, operand, vars_list)
727,783
Returns the TensorFluent for the prod aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the prod aggregation function.
def prod(self, vars_list: List[str]) -> 'TensorFluent': operand = self if operand.dtype == tf.bool: operand = operand.cast(tf.float32) return self._aggregation_op(tf.reduce_prod, operand, vars_list)
727,784
Returns the TensorFluent for the maximum aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the maximum aggregation function.
def maximum(self, vars_list: List[str]) -> 'TensorFluent': return self._aggregation_op(tf.reduce_max, self, vars_list)
727,785
Returns the TensorFluent for the minimum aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the minimum aggregation function.
def minimum(self, vars_list: List[str]) -> 'TensorFluent': return self._aggregation_op(tf.reduce_min, self, vars_list)
727,786
Returns the TensorFluent for the forall aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the forall aggregation function.
def forall(self, vars_list: List[str]) -> 'TensorFluent': return self._aggregation_op(tf.reduce_all, self, vars_list)
727,787
Returns the TensorFluent for the exists aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the exists aggregation function.
def exists(self, vars_list: List[str]) -> 'TensorFluent': return self._aggregation_op(tf.reduce_any, self, vars_list)
727,788
Returns a TensorFluent for the addition arithmetic operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __add__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.add, tf.float32)
727,789
Returns a TensorFluent for the subtraction arithmetic operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __sub__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.subtract, tf.float32)
727,790
Returns a TensorFluent for the multiplication arithmetic operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __mul__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.multiply, tf.float32)
727,791
Returns a TensorFluent for the division arithmetic operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __truediv__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.divide, tf.float32)
727,792
Returns a TensorFluent for the and logical operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __and__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.logical_and, tf.bool)
727,793
Returns a TensorFluent for the or logical operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __or__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.logical_or, tf.bool)
727,794
Returns a TensorFluent for the xor logical operator. Args: self: The first operand. other: The second operand. Returns: A TensorFluent wrapping the operator's output.
def __xor__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.logical_xor, tf.bool)
727,795
Returns a TensorFluent for the less-than-or-equal relational operator. Args: self: The first operand. other: The second operand.
def __le__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.less_equal, tf.float32)
727,796
Returns a TensorFluent for the less-then relational operator. Args: self: The first operand. other: The second operand.
def __lt__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.less, tf.float32)
727,797
Returns a TensorFluent for the greater-then-or-equal relational operator. Args: self: The first operand. other: The second operand.
def __ge__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.greater_equal, tf.float32)
727,798
Returns a TensorFluent for the greater-than relational operator. Args: self: The first operand. other: The second operand.
def __gt__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.greater, tf.float32)
727,799
Returns a TensorFluent for the equal relational operator. Args: self: The first operand. other: The second operand.
def __eq__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.equal, tf.float32)
727,800
Returns a TensorFluent for the not-equal relational operator. Args: self: The first operand. other: The second operand.
def __ne__(self, other: 'TensorFluent') -> 'TensorFluent': return self._binary_op(self, other, tf.not_equal, tf.float32)
727,801
Helps object methods handle MatrixRequestError. Args: method(function): Object method to be wrapped Method's object must have _handle_request_exception method that deals with specific status codes and errcodes.
def intent(method): def wrapper(self, *args, **kwargs): try: return method(self, *args, **kwargs) except exceptions.MatrixError as e: if isinstance(e.original_exception, matrix_client.errors.MatrixRequestError): self._handle_req...
727,941
Apply the zip operator to a set of variables. This uses the python zip iterator to combine multiple lists of variables such that the nth variable in each list is aligned. Args: variables: The variables object parent: Unused
def iterator_zip(variables: VarType, parent: str = None) -> Iterable[VarMatrix]: logger.debug("Yielding from zip iterator") if isinstance(variables, list): for item in variables: yield list(variable_matrix(item, parent, "zip")) else: yield list(variable_matrix(variables, pa...
728,004
Apply the product operator to a set of variables. This uses the python itertools.product iterator to combine multiple variables such that all possible combinations are generated. This is the default iterator however this is a method of manually specifying the option. Args: variables: The varia...
def iterator_product(variables: VarType, parent: str = None) -> Iterable[VarMatrix]: logger.debug("Yielding from product iterator") if isinstance(variables, list): raise ValueError( f"Product only takes mappings of values, got {variables} of type {type(variables)}" ) yield ...
728,005
This successively appends each element of an array to a single list of values. This takes a list of values and puts all the values generated for each element in the list into a single list of values. It uses the :func:`itertools.chain` function to achieve this. This function is particularly useful for spec...
def iterator_chain(variables: VarType, parent: str = None) -> Iterable[VarMatrix]: logger.debug("Yielding from append iterator") if not isinstance(variables, list): raise ValueError( f"Append keyword only takes a list of arguments, got {variables} of type {type(variables)}" ) ...
728,006
Create a list of values using the :func:`numpy.arange` function. Args: variables: The input variables for the creation of the range parent: The variable for which the values are being generated. Returns: A list of dictionaries mapping the parent to each value.
def iterator_arange(variables: VarType, parent: str) -> Iterable[VarMatrix]: assert parent is not None if isinstance(variables, (int, float)): yield [{parent: i} for i in np.arange(variables)] elif isinstance(variables, dict): if variables.get("stop"): yield [{parent: i} fo...
728,008
Cycle through a list of values a specified number of times Args: variables: The input variables for the creation of the range parent: The variable for which the values are being generated. Returns: A list of dictionaries mapping the parent to each value.
def iterator_cycle(variables: VarType, parent: str) -> Iterable[VarMatrix]: if isinstance(variables, dict): if variables.get("times"): times = int(variables["times"]) del variables["times"] yield list(variable_matrix(variables, parent, "product")) * times e...
728,009
It broadcasts the fluent shapes if any input is in batch mode. It handles input shapes in different modes, expanding its dimensions if necessary. It outputs a tuple with new shapes. If no input shape is in batch mode, return (None, None). If an input shape does not need to be changed, r...
def broadcast(cls, shape1: 'TensorFluentShape', shape2: 'TensorFluentShape') -> Tuple[Reshaping, Reshaping]: reshape_1, reshape_2 = None, None if not (shape1._batch or shape2._batch): return reshape_1, reshape_2 size_1, size_2 = shape1.fluent_size, ...
728,067
Returns a tuple of tensors representing the initial state fluents. Args: batch_size (Optional[int]): The batch size. Returns: Sequence[tf.Tensor]: A tuple of tensors.
def compile_initial_state(self, batch_size: Optional[int] = None) -> Sequence[tf.Tensor]: with self.graph.as_default(): with tf.name_scope('initial_state'): self._initialize_initial_state_fluents() if batch_size is None: return self.initia...
728,117
Returns a tuple of tensors representing the default action fluents. Args: batch_size (int): The batch size. Returns: Sequence[tf.Tensor]: A tuple of tensors.
def compile_default_action(self, batch_size: Optional[int] = None) -> Sequence[tf.Tensor]: with self.graph.as_default(): with tf.name_scope('default_action'): self._initialize_default_action_fluents() if batch_size is None: return self.def...
728,118
Compiles the intermediate and next state fluent CPFs given the current `state` and `action`. Args: state (Sequence[tf.Tensor]): A tuple of state tensors. action (Sequence[tf.Tensor]): A tuple of action tensors. Returns: Tuple[List[TensorFluent], List[TensorF...
def cpfs(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor], noise: Optional[Noise] = None) -> Tuple[List[TensorFluent], List[TensorFluent]]: scope = self.transition_scope(state, action) batch_size = int(state[0].shape[0]) interm_fluents...
728,119
Compiles the reward function given the current `state`, `action` and `next_state`. Args: state (Sequence[tf.Tensor]): A tuple of current state tensors. action (Sequence[tf.Tensor]): A tuple of action tensors. next_state (Sequence[tf.Tensor]): A tuple of next state te...
def reward(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor], next_state: Sequence[tf.Tensor]) -> tf.Tensor: scope = self.reward_scope(state, action, next_state) r = self.compile_reward(scope).tensor with self.graph.as_default(): ...
728,120
Compiles the intermediate and next state fluent CPFs given the current `state` and `action` scope. Args: scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for CPF evaluation. batch_size (Optional[int]): The batch size. Returns: Tuple[List[CPFPa...
def compile_cpfs(self, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[Noise] = None) -> Tuple[List[CPFPair], List[CPFPair]]: interm_fluents = self.compile_intermediate_cpfs(scope, batch_size, noise) ...
728,121
Compiles the intermediate fluent CPFs given the current `state` and `action` scope. Args: scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for CPF evaluation. batch_size (Optional[int]): The batch size. Returns: A list of intermediate fluent C...
def compile_intermediate_cpfs(self, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[Noise] = None) -> List[CPFPair]: interm_fluents = [] with self.graph.as_de...
728,122
Compiles the next state fluent CPFs given the current `state` and `action` scope. Args: scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for CPF evaluation. batch_size (Optional[int]): The batch size. Returns: A list of state fluent CPFs compi...
def compile_state_cpfs(self, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[Noise] = None) -> List[CPFPair]: next_state_fluents = [] with self.graph.as_default(): wit...
728,123
Compiles the reward function given the fluent `scope`. Args: scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for reward evaluation. Returns: A :obj:`rddl2tf.fluent.TensorFluent` representing the reward function.
def compile_reward(self, scope: Dict[str, TensorFluent]) -> TensorFluent: reward_expr = self.rddl.domain.reward with self.graph.as_default(): with tf.name_scope('reward'): return self._compile_expression(reward_expr, scope)
728,124
Compiles the state-action constraints given current `state` and `action` fluents. Args: state (Sequence[tf.Tensor]): The current state fluents. action (Sequence[tf.Tensor]): The action fluents. Returns: A list of :obj:`rddl2tf.fluent.TensorFluent`.
def compile_state_action_constraints(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor]) -> List[TensorFluent]: scope = self.transition_scope(state, action) constraints = [] with self.graph.as_default(): with tf.name_scope('state_action_con...
728,125
Compiles the action preconditions given current `state` and `action` fluents. Args: state (Sequence[tf.Tensor]): The current state fluents. action (Sequence[tf.Tensor]): The action fluents. Returns: A list of :obj:`rddl2tf.fluent.TensorFluent`.
def compile_action_preconditions(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor]) -> List[TensorFluent]: scope = self.action_precondition_scope(state, action) preconds = [] with self.graph.as_default(): with tf.name_scope('action_precond...
728,126
Compiles the state invarints given current `state` fluents. Args: state (Sequence[tf.Tensor]): The current state fluents. Returns: A list of :obj:`rddl2tf.fluent.TensorFluent`.
def compile_state_invariants(self, state: Sequence[tf.Tensor]) -> List[TensorFluent]: scope = self.state_invariant_scope(state) invariants = [] with self.graph.as_default(): with tf.name_scope('state_invariants'): for p in self.rddl.domain.invaria...
728,127
Combines the action preconditions into an applicability checking op. Args: state (Sequence[tf.Tensor]): The current state fluents. action (Sequence[tf.Tensor]): The action fluents. Returns: A boolean tensor for checking if `action` is application in `state`.
def compile_action_preconditions_checking(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor]) -> tf.Tensor: with self.graph.as_default(): with tf.name_scope('action_preconditions_checking'): preconds = self.compile_action_preconditions(stat...
728,128
Compiles all actions bounds for the given `state`. Args: state (Sequence[tf.Tensor]): The current state fluents. Returns: A mapping from action names to a pair of :obj:`rddl2tf.fluent.TensorFluent` representing its lower and upper bounds.
def compile_action_bound_constraints(self, state: Sequence[tf.Tensor]) -> Dict[str, Bounds]: scope = self.action_precondition_scope(state) lower_bounds = self.rddl.domain.action_lower_bound_constraints upper_bounds = self.rddl.domain.action_upper_bound_constraints ...
728,129
Returns a partial scope with current state-fluents. Args: state_fluents (Sequence[tf.Tensor]): The current state fluents. Returns: A mapping from state fluent names to :obj:`rddl2tf.fluent.TensorFluent`.
def state_scope(self, state_fluents: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]: return dict(zip(self.rddl.domain.state_fluent_ordering, state_fluents))
728,131
Returns a partial scope with current action-fluents. Args: action_fluents (Sequence[tf.Tensor]): The action fluents. Returns: A mapping from action fluent names to :obj:`rddl2tf.fluent.TensorFluent`.
def action_scope(self, action_fluents: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]: return dict(zip(self.rddl.domain.action_fluent_ordering, action_fluents))
728,132
Returns a partial scope with current next state-fluents. Args: next_state_fluents (Sequence[tf.Tensor]): The next state fluents. Returns: A mapping from next state fluent names to :obj:`rddl2tf.fluent.TensorFluent`.
def next_state_scope(self, next_state_fluents: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]: return dict(zip(self.rddl.domain.next_state_fluent_ordering, next_state_fluents))
728,133
Returns the complete transition fluent scope for the current `state` and `action` fluents. Args: state (Sequence[tf.Tensor]): The current state fluents. action (Sequence[tf.Tensor]): The action fluents. Returns: A mapping from fluent names to :obj:`rddl2tf.f...
def transition_scope(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]: scope = {} scope.update(self.non_fluents_scope()) scope.update(self.state_scope(state)) scope.update(self.action_scope(action)) return scope
728,134
Returns the complete reward fluent scope for the current `state`, `action` fluents, and `next_state` fluents. Args: state (Sequence[tf.Tensor]): The current state fluents. action (Sequence[tf.Tensor]): The action fluents. next_state (Sequence[tf.Tensor]): The next st...
def reward_scope(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor], next_state: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]: scope = {} scope.update(self.non_fluents_scope()) scope.update(self.state_scope(sta...
728,135
Returns the state invariant fluent scope for the current `state`. Args: state (Sequence[tf.Tensor]): The current state fluents. Returns: A mapping from fluent names to :obj:`rddl2tf.fluent.TensorFluent`.
def state_invariant_scope(self, state: Sequence[tf.Tensor]): scope = {} scope.update(self.non_fluents_scope()) scope.update(self.state_scope(state)) return scope
728,136
Compile the expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size (Optional[size]): The ba...
def _compile_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tensor]] = None) -> TensorFluent: etype2compiler = { ...
728,142
Compile a constant expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL constant expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size (Optiona...
def _compile_constant_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tensor]] = None) -> Tenso...
728,143
Compile a pvariable expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL pvariable expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size (Optio...
def _compile_pvariable_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tensor]] = None) -> ...
728,144
Compile an arithmetic expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL arithmetic expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size (Op...
def _compile_arithmetic_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tensor]] = None...
728,146
Compile a function expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL function expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size (Optiona...
def _compile_function_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tensor]] = None) -> Tenso...
728,147
Compile a control flow expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL control flow expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size ...
def _compile_control_flow_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tenso...
728,148
Compile an aggregation expression `expr` into a TensorFluent in the given `scope` with optional batch size. Args: expr (:obj:`rddl2tf.expr.Expression`): A RDDL aggregation expression. scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope. batch_size (...
def _compile_aggregation_expression(self, expr: Expression, scope: Dict[str, TensorFluent], batch_size: Optional[int] = None, noise: Optional[List[tf.Tensor]] =...
728,149
Instantiates Event instance. Args: json(dict): Event json from homeserver. Api(func): Creates api for calling homeserver.
def __init__(self, json, Api): self.json = json self.Api = Api self.type = json["type"] self.content = json["content"] self.timestamp = json["origin_server_ts"] self.id = json["room_id"] if "sender" in json: self.mxid = json["sender"] ...
728,163
Instantiates EventStream instance. Args: json(list): List from deserializing txn from homeserver. Api(func): Generates http api when passed identity=mxid.
def __init__(self, json, Api): self.json = json self._index = 0 self.Api = Api
728,166
Instantiates MatrixRoom object. Args: room_id(str): Matrix room id (e.g. !1234567:example.com) api(MatrixASHttpAPI): Api for calls to the server.
def __init__(self, room_id, api): self.room_id = room_id self.api = api
728,168
Instantiates MatrixUser object. Args: mxid(str): User id (e.g. @me:example.createRoom) Api(func): Generates api for calls to the server.
def __init__(self, mxid, Api): self.mxid = mxid self.user_api = Api(identity=mxid) self.api = Api() self._rooms = {}
728,173
Lists the container groups in the specified resource group. Arguments: aci_client {azure.mgmt.containerinstance.ContainerInstanceManagementClient} -- An authenticated container instance management client. resource_group {azure.mgmt.resource.resources.models.Resource...
def list_container_groups(self, resource_group_name): print("Listing container groups in resource group '{0}'...".format(resource_group_name)) container_groups = self.client.container_groups.list_by_resource_group(resource_group_name) for container_group in container_groups: ...
728,886
List the blobs/files inside a container/share_name. Args: container_or_share_name(str): Name of the container/share_name where we want to list the blobs/files. container(bool): flag to know it you are listing files or blobs. account(str): The name of the storage account.
def list(self, container_or_share_name, container=None, account=None): key = self.storage_client.storage_accounts.list_keys(self.resource_group_name, account).keys[0].value if container: bs = BlockBlobService(account_name=account, account_key=key) container_list = [] ...
728,966
Sign a remote file to distribute. The azure url format is https://myaccount.blob.core.windows.net/mycontainer/myblob. Args: remote_file(str): The blob that we want to sign.
def generate_url(self, remote_file): parse_url = _parse_url(remote_file) key = self.storage_client.storage_accounts.list_keys(self.resource_group_name, parse_url.account).keys[0].value if parse_url.file_type == 'blob': bs = BlockBlobService(account_name=parse_url.account, ac...
728,967
Delete file from the cloud. The azure url format is https://myaccount.blob.core.windows.net/mycontainer/myblob. Args: remote_file(str): The path of the file to be deleted. Raises: :exc:`~..OsmosisError`: if the file is not uploaded correctly.
def delete(self, remote_file): if 'core.windows.net' not in remote_file: self.logger.error("Source or destination must be a azure storage url (format " "https://myaccount.blob.core.windows.net/mycontainer/myblob") raise OsmosisError parse_ur...
728,968
Copy file from a path to another path. The azure url format is https://myaccount.blob.core.windows.net/mycontainer/myblob. Args: source_path(str): The path of the file to be copied. dest_path(str): The destination path where the file is going to be allocated. Raises: ...
def copy(self, source_path, dest_path, account=None, group_name=None): if 'core.windows.net' not in source_path and 'core.windows.net' not in dest_path: self.logger.error("Source or destination must be a azure storage url (format " "https://myaccount.blob.core....
728,969
Sends details about a Python to the log, specifically its ``repr()`` representation, and all of its attributes with their name, value, and type. Args: obj: object to debug log_level: log level to use; default is ``logging.DEBUG``
def debug_object(obj, log_level: int = logging.DEBUG) -> None: msgs = ["For {o!r}:".format(o=obj)] for attrname in dir(obj): attribute = getattr(obj, attrname) msgs.append("- {an!r}: {at!r}, of type {t!r}".format( an=attrname, at=attribute, t=type(attribute))) log.log(log_le...
729,627
Does the interval contain a momentary time? Args: time: the ``datetime.datetime`` to check inclusive: use inclusive rather than exclusive range checks?
def contains(self, time: datetime.datetime, inclusive: bool = True) -> bool: if inclusive: return self.start <= time <= self.end else: return self.start < time < self.end
729,680
Is this interval contained within the other? Args: other: the :class:`Interval` to check inclusive: use inclusive rather than exclusive range checks?
def within(self, other: "Interval", inclusive: bool = True) -> bool: if not other: return False if inclusive: return self.start >= other.start and self.end <= other.end else: return self.start > other.start and self.end < other.end
729,681
Creates the :class:`IntervalList`. Args: intervals: optional list of :class:`Interval` objects to incorporate into the :class:`IntervalList` no_overlap: merge intervals that overlap (now and on subsequent addition)? no_contiguous: if ``no_over...
def __init__(self, intervals: List[Interval] = None, no_overlap: bool = True, no_contiguous: bool = True) -> None: # DO NOT USE intervals=[] in the function signature; that's the route # to a mutable default and a huge amount of confusion as se...
729,692
Makes and returns a copy of the :class:`IntervalList`. The ``no_overlap``/``no_contiguous`` parameters can be changed. Args: no_overlap: merge intervals that overlap (now and on subsequent addition)? no_contiguous: if ``no_overlap`` is set, merge intervals that a...
def copy(self, no_overlap: bool = None, no_contiguous: bool = None) -> "IntervalList": if no_overlap is None: no_overlap = self.no_overlap if no_contiguous is None: no_contiguous = self.no_contiguous return IntervalList(self.intervals, no_overlap=no_...
729,694
Called by :meth:`remove_overlap`. Removes the first overlap found. Args: also_remove_contiguous: treat contiguous (as well as overlapping) intervals as worthy of merging? Returns: bool: ``True`` if an overlap was removed; ``False`` otherwise
def _remove_overlap_sub(self, also_remove_contiguous: bool) -> bool: # Returns for i in range(len(self.intervals)): for j in range(i + 1, len(self.intervals)): first = self.intervals[i] second = self.intervals[j] if also_remove_contigu...
729,697
Merges any overlapping intervals. Args: also_remove_contiguous: treat contiguous (as well as overlapping) intervals as worthy of merging?
def remove_overlap(self, also_remove_contiguous: bool = False) -> None: overlap = True while overlap: overlap = self._remove_overlap_sub(also_remove_contiguous) self._sort()
729,698
Do any of the intervals overlap? Args: test_overlap: if ``True``, test for overlapping intervals; if ``False``, test for contiguous intervals.
def _any_overlap_or_contiguous(self, test_overlap: bool) -> bool: for i in range(len(self.intervals)): for j in range(i + 1, len(self.intervals)): first = self.intervals[i] second = self.intervals[j] if test_overlap: test =...
729,699
Fetches a Git repository, unless we have it already. Args: prettyname: name to display to user url: URL directory: destination directory branch: repository branch commit: repository commit tag clone_options: additional options to pass to ``git clone`` run_fun...
def git_clone(prettyname: str, url: str, directory: str, branch: str = None, commit: str = None, clone_options: List[str] = None, run_func: Callable[[List[str]], Any] = None) -> bool: run_func = run_func or subprocess.check_call clone_options = clone_...
729,772
Run a command and returns its stdout. Args: args: the command-line arguments env: the operating system environment to use encoding: the encoding to use for ``stdout`` Returns: the command's ``stdout`` output
def fetch(args: List[str], env: Dict[str, str] = None, encoding: str = sys.getdefaultencoding()) -> str: stdout, _ = run(args, env=env, capture_stdout=True, echo_stdout=False, encoding=encoding) log.debug(stdout) return stdout
729,776
Dumps some connection info, as an SQL comment. Obscures passwords. Args: engine: the SQLAlchemy :class:`Engine` to dump metadata information from fileobj: the file-like object (default ``sys.stdout``) to write information to
def dump_connection_info(engine: Engine, fileobj: TextIO = sys.stdout) -> None: meta = MetaData(bind=engine) writeline_nl(fileobj, sql_comment('Database info: {}'.format(meta)))
729,777
Sends schema-creating DDL from the metadata to the dump engine. This makes ``CREATE TABLE`` statements. Args: metadata: SQLAlchemy :class:`MetaData` dialect_name: string name of SQL dialect to generate DDL in fileobj: file-like object to send DDL to checkfirst: if ``True``, use ...
def dump_ddl(metadata: MetaData, dialect_name: str, fileobj: TextIO = sys.stdout, checkfirst: bool = True) -> None: # http://docs.sqlalchemy.org/en/rel_0_8/faq.html#how-can-i-get-the-create-table-drop-table-output-as-a-string # noqa # http://stackoverflow.com/questio...
729,778
Makes a new SQLAlchemy mapper for an existing table. See http://www.tylerlesmann.com/2009/apr/27/copying-databases-across-platforms-sqlalchemy/ Args: table: SQLAlchemy :class:`Table` object Returns: a :class:`DeclarativeMeta` class
def quick_mapper(table: Table) -> Type[DeclarativeMeta]: # noqa # noinspection PyPep8Naming Base = declarative_base() class GenericMapper(Base): __table__ = table # noinspection PyTypeChecker return GenericMapper
729,779
Reads a table from the database, and writes SQL to replicate the table's data to the output ``fileobj``. Args: engine: SQLAlchemy :class:`Engine` table_name: name of the table fileobj: file-like object to write to wheredict: optional dictionary of ``{column_name: value}`` to use...
def dump_table_as_insert_sql(engine: Engine, table_name: str, fileobj: TextIO, wheredict: Dict[str, Any] = None, include_ddl: bool = False, multirow: bool = False) -> None: ...
729,782
Reads an entire database and writes SQL to replicate it to the output file-like object. Args: engine: SQLAlchemy :class:`Engine` fileobj: file-like object to write to include_ddl: if ``True``, include the DDL to create the table as well multirow: write multi-row ``INSERT`` state...
def dump_database_as_insert_sql(engine: Engine, fileobj: TextIO = sys.stdout, include_ddl: bool = False, multirow: bool = False) -> None: for tablename in get_table_names(engine): dump_table_as_insert_sql( ...
729,783
Takes a SQLAlchemy ORM object, and writes ``INSERT`` SQL to replicate it to the output file-like object. Args: engine: SQLAlchemy :class:`Engine` obj: SQLAlchemy ORM object to write fileobj: file-like object to write to
def dump_orm_object_as_insert_sql(engine: Engine, obj: object, fileobj: TextIO) -> None: # literal_query = make_literal_query_fn(engine.dialect) insp = inspect(obj) # insp: an InstanceState # http://docs.sqlalchemy.org/en/latest/or...
729,784
Writes bulk ``INSERT`` preamble (start=True) or end (start=False). For MySQL, this temporarily switches off autocommit behaviour and index/FK checks, for speed, then re-enables them at the end and commits. Args: dialect_name: SQLAlchemy dialect name (see :class:`SqlaDialectName`) fileobj: ...
def bulk_insert_extras(dialect_name: str, fileobj: TextIO, start: bool) -> None: lines = [] if dialect_name == SqlaDialectName.MYSQL: if start: lines = [ "SET autocommit=0;", "SET unique_checks=0;", ...
729,785
Converts a list of lists into a flat list. Args: x: list of lists Returns: flat list As per http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python
def flatten_list(x: List[Any]) -> List[Any]: # noqa return [item for sublist in x for item in sublist]
729,838
Returns a list of all the unique elements in the input list. Args: seq: input list Returns: list of unique elements As per http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-whilst-preserving-order
def unique_list(seq: Iterable[Any]) -> List[Any]: # noqa seen = set() seen_add = seen.add return [x for x in seq if not (x in seen or seen_add(x))]
729,839
Yield successive ``n``-sized chunks from ``l``. Args: l: input list n: chunk size Yields: successive chunks of size ``n``
def chunks(l: List[Any], n: int) -> Iterable[List[Any]]: for i in range(0, len(l), n): yield l[i:i + n]
729,840
Used to create :data:`UNICODE_CATEGORY_STRINGS`. Args: srclist: list of integers or hex range strings like ``"0061-007A"`` Returns: a string with all characters described by ``srclist``: either the character corresponding to the integer Unicode character number, or all characte...
def _unicode_def_src_to_str(srclist: List[Union[str, int]]) -> str: charlist = [] # type: List[str] for src in srclist: if isinstance(src, int): charlist.append(chr(src)) else: # Range like "0041-005A" first, last = [int(x, 16) for x in src.split("-")] ...
729,845
As per https://stackoverflow.com/questions/33560364/python-windows-parsing-command-lines-with-shlex. Multi-platform variant of ``shlex.split()`` for command-line splitting. For use with ``subprocess``, for ``argv`` injection etc. Using fast REGEX. Args: s: string to split ...
def cmdline_split(s: str, platform: Union[int, str] = 'this') -> List[str]: # noqa if platform == 'this': platform = (sys.platform != 'win32') # RNC: includes 64-bit Windows if platform == 1: # POSIX re_cmd_lex = r # noqa elif platform == 0: # Windows/CMD re_cmd_lex = r # ...
729,882
Retrieves a string value from a parser. Args: parser: instance of :class:`ConfigParser` section: section name within config file option: option (variable) name within that section default: value to return if option is absent Returns: string value Raises: Va...
def get_config_string_option(parser: ConfigParser, section: str, option: str, default: str = None) -> str: if not parser.has_section(section): raise ValueError("config missing section: " + section) return parser....
729,891
Reads config options and writes them as attributes of ``obj``, with attribute names as per ``options``. Args: obj: the object to modify parser: instance of :class:`ConfigParser` section: section name within config file options: option (variable) names within that section ...
def read_config_string_options(obj: Any, parser: ConfigParser, section: str, options: Iterable[str], default: str = None) -> None: # enforce_str removed; ConfigParser always returns strin...
729,892
Retrieves a multi-line string value from a parser as a list of strings (one per line, ignoring blank lines). Args: parser: instance of :class:`ConfigParser` section: section name within config file option: option (variable) name within that section default: value to return if op...
def get_config_multiline_option(parser: ConfigParser, section: str, option: str, default: List[str] = None) -> List[str]: default = default or [] if not parser.has_section(section): raise ValueError("con...
729,893
Retrieves a boolean value from a parser. Args: parser: instance of :class:`ConfigParser` section: section name within config file option: option (variable) name within that section default: value to return if option is absent Returns: string value Raises: V...
def get_config_bool_option(parser: ConfigParser, section: str, option: str, default: bool = None) -> bool: if not parser.has_section(section): raise ValueError("config missing section: " + section) return parser.getboo...
729,895
Fetch parameter from ``configparser`` ``.INI`` file. Args: config: :class:`ConfigParser` object section: section name within config file param: name of parameter within section fn: function to apply to string parameter (e.g. ``int``) default: default value Returns: ...
def get_config_parameter(config: ConfigParser, section: str, param: str, fn: Callable[[Any], Any], default: Any) -> Any: try: value = fn(config.get(section, param)) except (TypeError, ValueError, NoO...
729,896
Get Boolean parameter from ``configparser`` ``.INI`` file. Args: config: :class:`ConfigParser` object section: section name within config file param: name of parameter within section default: default value Returns: parameter value, or default
def get_config_parameter_boolean(config: ConfigParser, section: str, param: str, default: bool) -> bool: try: value = config.getboolean(section, param) except (TypeError, ValueError, NoOptionError): ...
729,897
Get ``loglevel`` parameter from ``configparser`` ``.INI`` file, e.g. mapping ``'debug'`` to ``logging.DEBUG``. Args: config: :class:`ConfigParser` object section: section name within config file param: name of parameter within section default: default value Returns: ...
def get_config_parameter_loglevel(config: ConfigParser, section: str, param: str, default: int) -> int: try: value = config.get(section, param).lower() if value == "debug": return l...
729,898