init
cosy
¶
T = TypeVar('T', bound=Hashable)
module-attribute
¶
__all__ = ['DSL', 'Literal', 'Var', 'Subtypes', 'Type', 'Omega', 'Constructor', 'Arrow', 'Intersection', 'Synthesizer', 'SolutionSpace']
module-attribute
¶
Arrow
dataclass
¶
Source code in src/cosy/types.py
free_vars: set[str] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
is_omega: bool = field(init=False, compare=False)
class-attribute
instance-attribute
¶
organized: set[Type] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
size: int = field(init=False, compare=False)
class-attribute
instance-attribute
¶
source: Type = field(init=True)
class-attribute
instance-attribute
¶
target: Type = field(init=True)
class-attribute
instance-attribute
¶
__init__(source: Type, target: Type, *, is_omega: bool, size: int, organized: set[Type], free_vars: set[str]) -> None
¶
__post_init__() -> None
¶
__str__() -> str
¶
subst(groups: Mapping[str, str], substitution: dict[str, Any]) -> Type
¶
Source code in src/cosy/types.py
CoSy
¶
Source code in src/cosy/__init__.py
component_specifications: Mapping[T, Specification] = component_specifications
instance-attribute
¶
parameter_space: ParameterSpace | None = parameter_space
class-attribute
instance-attribute
¶
taxonomy: Taxonomy | None = taxonomy if taxonomy is not None else {}
class-attribute
instance-attribute
¶
__init__(component_specifications: Mapping[T, Specification], parameter_space: ParameterSpace | None = None, taxonomy: Taxonomy | None = None) -> None
¶
Source code in src/cosy/__init__.py
solve(query: Type, max_count: int = 100) -> Iterable[Any]
¶
Solves the given query by constructing a solution space and enumerating and interpreting the resulting trees.
:param query: The query to solve. :param max_count: The maximum number of trees to enumerate. :return: An iterable of interpreted trees.
Source code in src/cosy/__init__.py
Constructor
dataclass
¶
Source code in src/cosy/types.py
arg: Type = field(default=Omega(), init=True)
class-attribute
instance-attribute
¶
free_vars: set[str] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
is_omega: bool = field(init=False, compare=False)
class-attribute
instance-attribute
¶
name: str = field(init=True)
class-attribute
instance-attribute
¶
organized: set[Type] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
size: int = field(init=False, compare=False)
class-attribute
instance-attribute
¶
__init__(name: str, arg: Type = Omega(), *, is_omega: bool, size: int, organized: set[Type], free_vars: set[str]) -> None
¶
__post_init__() -> None
¶
__str__() -> str
¶
subst(groups: Mapping[str, str], substitution: dict[str, Any]) -> Type
¶
DSL
¶
A domain-specific language (DSL) to define component specifications.
This class provides a interface for defining specifications in a declarative manner. It allows users to specify the name and group of each parameter, as well as filter.
Examples:
DSL() .Parameter("x", int) .Parameter("y", int, lambda vars: vars["x"] + 1) .Parameter("z", str) .ParameterConstraint(lambda vars: len(vars["z"]) == vars["x"] + vars["y"]) .Suffix(
constructs a specification for a function with three parameters: - x
: an integer - y
: an integer, the value of which is x
+ 1 - z
: a string, whose length is equal to x
+ y
The Suffix
method specifies the function, which uses the variables x
, y
, and z
.
Source code in src/cosy/dsl.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
__init__() -> None
¶
argument(name: str, specification: Type) -> DSL
¶
Introduce a new variable.
group
is a Type
, and an instance will be generated for each tree, satisfying the specification given by the type. Since this can only be done in the enumeration step, you can only use these variables in predicates, that themselves belong to variables whose group
is a Type
.
:param name: The name of the new variable. :type name: str :param specification: The type of the variable. :type specification: Type :return: The DSL object. :rtype: DSL
Source code in src/cosy/dsl.py
constraint(constraint: Callable[[Mapping[str, Any]], bool]) -> DSL
¶
Constraint on the previously defined parameter variables and argument variables.
:param constraint: A constraint deciding, if the currently chosen values are valid. The values of variables are passed by a dictionary, where the keys are the names of the variables and the values are the corresponding values. :type constraint: Callable[[Mapping[str, Any]], bool] :return: The DSL object. :rtype: DSL
Source code in src/cosy/dsl.py
parameter(name: str, group: str, candidates: Callable[[dict[str, Any]], Sequence[Any]] | None = None) -> DSL
¶
Introduce a new parameter variable.
group
is a string, and an instance of this specification will be generated for each valid literal in the corresponding literal group. You can use this variable as Var(name) in all Type
s, after the introduction and in all predicates. Optionally, you can specify a sequence of candidate values, that will be used to generate the literals. This sequence is parameterized by the values of previously defined literal variables. This is useful, if you want to restrict the values of a variable to a subset of the values in the corresponding literal group.
:param name: The name of the new variable. :type name: str :param group: The group of the variable. :type group: str :param candidates: Parameterized sequence of candidate values, that will be used to generate the literals. :type candidates: Callable[[dict[str, Any]], Sequence[Any]] | None :return: The DSL object. :rtype: DSL
Source code in src/cosy/dsl.py
parameter_constraint(constraint: Callable[[Mapping[str, Any]], bool]) -> DSL
¶
Constraint on the previously defined parameter variables.
:param constraint: A constraint deciding, if the currently chosen parameter values are valid. The values of variables are passed by a dictionary, where the keys are the names of the parameter variables and the values are the corresponding values. :type constraint: Callable[[Mapping[str, Any]], bool] :return: The DSL object. :rtype: DSL
Source code in src/cosy/dsl.py
suffix(suffix: Type) -> Specification
¶
Constructs the final specification wrapping the given Type
suffix
.
:param suffix: The wrapped type. :type suffix: Type :return: The constructed specification. :rtype: Abstraction | Type
Source code in src/cosy/dsl.py
Intersection
dataclass
¶
Source code in src/cosy/types.py
free_vars: set[str] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
is_omega: bool = field(init=False, compare=False)
class-attribute
instance-attribute
¶
left: Type = field(init=True)
class-attribute
instance-attribute
¶
organized: set[Type] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
right: Type = field(init=True)
class-attribute
instance-attribute
¶
size: int = field(init=False, compare=False)
class-attribute
instance-attribute
¶
__init__(left: Type, right: Type, *, is_omega: bool, size: int, organized: set[Type], free_vars: set[str]) -> None
¶
__post_init__() -> None
¶
__str__() -> str
¶
subst(groups: Mapping[str, str], substitution: dict[str, Any]) -> Type
¶
Source code in src/cosy/types.py
Literal
dataclass
¶
Source code in src/cosy/types.py
free_vars: set[str] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
group: str
instance-attribute
¶
is_omega: bool = field(init=False, compare=False)
class-attribute
instance-attribute
¶
organized: set[Type] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
size: int = field(init=False, compare=False)
class-attribute
instance-attribute
¶
value: Any
instance-attribute
¶
__init__(value: Any, group: str, *, is_omega: bool, size: int, organized: set[Type], free_vars: set[str]) -> None
¶
__post_init__() -> None
¶
__str__() -> str
¶
Omega
dataclass
¶
Source code in src/cosy/types.py
free_vars: set[str] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
is_omega: bool = field(init=False, compare=False)
class-attribute
instance-attribute
¶
organized: set[Type] = field(init=False, compare=False)
class-attribute
instance-attribute
¶
size: int = field(init=False, compare=False)
class-attribute
instance-attribute
¶
__init__(*, is_omega: bool, size: int, organized: set[Type], free_vars: set[str]) -> None
¶
__post_init__() -> None
¶
SolutionSpace
¶
Source code in src/cosy/solution_space.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
__getitem__(nonterminal: NT) -> deque[RHSRule[NT, T, G]]
¶
__init__(rules: dict[NT, deque[RHSRule[NT, T, G]]] | None = None) -> None
¶
add_rule(nonterminal: NT, terminal: T, arguments: tuple[Argument, ...], predicates: tuple[Callable[[dict[str, Any]], bool], ...]) -> None
¶
as_tuples() -> Iterable[tuple[NT, deque[RHSRule[NT, T, G]]]]
¶
contains_tree(start: NT, tree: Tree[T]) -> bool
¶
Check if the solution space contains a given tree
derivable from start
.
Source code in src/cosy/solution_space.py
enumerate_trees(start: NT, max_count: int | None = None, max_bucket_size: int | None = None) -> Iterable[Tree[T]]
¶
Enumerate terms as an iterator efficiently - all terms are enumerated, no guaranteed term order.
Source code in src/cosy/solution_space.py
get(nonterminal: NT) -> deque[RHSRule[NT, T, G]] | None
¶
nonterminals() -> Iterable[NT]
¶
prune() -> SolutionSpace[NT, T, G]
¶
Keep only productive rules.
Source code in src/cosy/solution_space.py
Subtypes
¶
Source code in src/cosy/subtypes.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
taxonomy = self._transitive_closure(self._reflexive_closure(taxonomy))
instance-attribute
¶
__init__(taxonomy: Taxonomy)
¶
check_subtype(subtype: Type, supertype: Type, groups: Mapping[str, str], substitutions: Mapping[str, Literal]) -> bool
¶
Decides whether subtype <= supertype with respect to intersection type subtyping.
Source code in src/cosy/subtypes.py
infer_substitution(subtype: Type, path: Type, groups: Mapping[str, str]) -> dict[str, Any] | None
¶
Infers a unique substitution S such that S(subtype) <= path where path is closed. Returns None or Ambiguous is no solution exists or multiple solutions exist respectively.
Source code in src/cosy/subtypes.py
Synthesizer
¶
Source code in src/cosy/synthesizer.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
literals: ParameterSpace = {} if parameter_space is None else dict(parameter_space.items())
instance-attribute
¶
repository: tuple[tuple[C, CombinatorInfo], ...] = tuple((c, Synthesizer._function_types(self.literals, ty)) for (c, ty) in component_specifications.items())
instance-attribute
¶
subtypes = Subtypes(taxonomy if taxonomy is not None else {})
instance-attribute
¶
__init__(component_specifications: Mapping[C, Specification], parameter_space: ParameterSpace | None = None, taxonomy: Taxonomy | None = None)
¶
Source code in src/cosy/synthesizer.py
construct_solution_space(*targets: Type) -> SolutionSpace[Type, C, str]
¶
Constructs a logic program in the current environment for the given target types.
Source code in src/cosy/synthesizer.py
construct_solution_space_rules(*targets: Type) -> Generator[tuple[Type, RHSRule]]
¶
Generate logic program rules for the given target types.
Source code in src/cosy/synthesizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|