optiwindnet.db ============== .. py:module:: optiwindnet.db Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/optiwindnet/db/migrate/index Package Contents ---------------- .. py:class:: Machine(*args, **kwargs) Bases: :py:obj:`BaseModel` .. py:attribute:: id Primary key. .. py:attribute:: name Unique hostname/FQDN of the generating machine. .. py:attribute:: attrs System attributes and specifications dictionary. .. py:class:: Method(*args, **kwargs) Bases: :py:obj:`BaseModel` .. py:attribute:: digest SHA256 hash of funhash and JSON-serialized options. .. py:attribute:: solver_name Name of the solver/algorithm family. .. py:attribute:: funname Name of the optimization function. .. py:attribute:: options Dictionary of function parameters. .. py:attribute:: timestamp UTC timestamp of creation. .. py:attribute:: funfile Source filename containing the optimization function. .. py:attribute:: funhash SHA256 hash of the function bytecode. .. py:class:: NodeSet(*args, **kwargs) Bases: :py:obj:`BaseModel` .. py:attribute:: digest SHA256 hash of `VertexC` coordinates array in `.npy` format. .. py:attribute:: name Unique name of the wind farm location. .. py:attribute:: T Number of non-root nodes (wind turbines). .. py:attribute:: R Number of root nodes (substations). .. py:attribute:: B Number of border-only vertices. .. py:attribute:: VertexC 2D coordinates array in UTM, shape (T + B + R, 2). .. py:attribute:: constraint_groups Sizes of each polygon group (first boundary CCW, then obstacles CW). .. py:attribute:: constraint_vertices Concatenated indices into VertexC for constraint polygons. .. py:attribute:: landscape_angle Rotation angle of the landscape layout in radians. .. py:class:: RouteSet(*args, **kwargs) Bases: :py:obj:`BaseModel` .. py:attribute:: id Primary key. .. py:attribute:: handle Standardized wind farm location identifier. .. py:attribute:: T Number of non-root nodes (turbines). .. py:attribute:: R Number of root nodes (substations). .. py:attribute:: capacity Cable capacity (maximum turbine load). .. py:attribute:: length Total cable network length. .. py:attribute:: runtime Optimization runtime in seconds. .. py:attribute:: feeders_per_root List specifying number of feeders per root substation. .. py:attribute:: C Number of contour nodes. .. py:attribute:: D Number of detour nodes. .. py:attribute:: creator Short identifier of the routeset origin. .. py:attribute:: detextra length = (1+detextra)*undetoured. :type: Relative length increase due to detour .. py:attribute:: num_diagonals Number of diagonal crossing structures. .. py:attribute:: tentative List of vertex pairs representing tentative edges. .. py:attribute:: rogue List of vertex pairs representing rogue/invalid edges. .. py:attribute:: timestamp UTC timestamp of creation. .. py:attribute:: misc Dictionary of extra metadata and solver metrics. .. py:attribute:: clone2prime List of length C + D mapping cloned nodes back to original nodes. .. py:attribute:: edges Terse tree encoding where edges[i] is the target of node i. .. py:attribute:: nodes Foreign key link to the layout NodeSet. .. py:attribute:: method Foreign key link to the Method used. .. py:attribute:: machine Foreign key link to the generating Machine. .. py:function:: database_connection(filepath: str, create_db: bool = False, timeout: int = _DEFAULT_SQLITE_TIMEOUT) Open the sqlite database for the duration of a context block. :param filepath: path to database file :param create_db: True → create a new file if it does not exist :param timeout: seconds to wait for a locked database to be released :Yields: Connected SqliteDatabase object (Peewee) .. py:function:: open_database(filepath: str, create_db: bool = False, timeout: int = _DEFAULT_SQLITE_TIMEOUT) -> peewee.SqliteDatabase Opens the sqlite database v3 file specified in ``filepath``. :param filepath: path to database file :param create_db: True → create a new file if it does not exist :param timeout: seconds to wait for a locked database to be released :returns: SqliteDatabase object (Peewee) .. py:function:: G_by_method(G: networkx.Graph, method: optiwindnet.db.model.Method) -> networkx.Graph Fetch from the database a layout for ``G`` by ``method``. ``G`` must be a layout solution with the necessary info in the ``G.graph`` dict. ``method`` is a Method. .. py:function:: G_from_routeset(routeset: optiwindnet.db.model.RouteSet) -> networkx.Graph Translate a RouteSet database entry to a routeset graph. :param routeset: an entry from the database RouteSet table. :returns: Graph G containing the routeset. .. py:function:: Gs_from_attrs(farm: object, methods: optiwindnet.db.model.Method | collections.abc.Sequence[object], capacities: int | collections.abc.Sequence[int]) -> list[tuple[networkx.Graph]] Fetch from the database a list (one per capacity) of tuples (one per method) of layouts. ``farm`` must have the desired NodeSet name in the ``name`` attribute. ``methods`` is a (sequence of) Method instance(s). ``capacities`` is a (sequence of) int(s). .. py:function:: L_from_nodeset(nodeset: optiwindnet.db.model.NodeSet, handle: str | None = None) -> networkx.Graph Translate a NodeSet database entry to a location graph. :param nodeset: an entry from the database NodeSet table. :returns: Graph L containing the positions and location metadata. .. py:function:: store_G(G: networkx.Graph) -> int Store ``G``'s data to a new :class:`RouteSet` record in the database. If the NodeSet or Method are not yet in the database, they will be added. :param G: Graph with the routeset. :returns: Primary key of the newly created RouteSet record.