From 4613e785c5d173be6e0f9bd992c2b6395e21fbc9 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Sat, 14 Oct 2023 08:22:06 -0700 Subject: [PATCH] remove database --- README.md | 3 +- docs/_toc.yml | 3 - docs/notebooks/12_database.py | 105 -------- gplugins/database/README.md | 25 -- gplugins/database/__init__.py | 0 gplugins/database/db_upload.py | 183 -------------- gplugins/database/models.py | 449 --------------------------------- pyproject.toml | 8 - 8 files changed, 1 insertion(+), 775 deletions(-) delete mode 100644 docs/notebooks/12_database.py delete mode 100644 gplugins/database/README.md delete mode 100644 gplugins/database/__init__.py delete mode 100644 gplugins/database/db_upload.py delete mode 100644 gplugins/database/models.py diff --git a/README.md b/README.md index 8120ca5e..f6137ed2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ gdsfactory plugins: -- `database` for simulation and measurement database and dagster for data pipelines. - `devsim` TCAD device simulator. - `meow` Eigen Mode Expansion (EME). - `femwell` Finite Element Method Solver (heaters, modes, TCAD, RF waveguides). @@ -31,7 +30,7 @@ gdsfactory plugins: You can install most plugins with: ``` -pip install "gplugins[database,devsim,femwell,gmsh,schematic,meow,meshwell,ray,sax,tidy3d]" --upgrade +pip install "gplugins[devsim,femwell,gmsh,schematic,meow,meshwell,ray,sax,tidy3d]" --upgrade ``` Or install only the plugins you need with for example `pip install gplugins[schematic,femwell,meow,sax,tidy3d]` from the available plugins. diff --git a/docs/_toc.yml b/docs/_toc.yml index af0abc67..18937abb 100644 --- a/docs/_toc.yml +++ b/docs/_toc.yml @@ -55,9 +55,6 @@ parts: - file: notebooks/11_get_netlist - file: notebooks/11_get_netlist_spice - file: notebooks/path_length_analysis.py - - caption: Validation - chapters: - - file: notebooks/12_database - caption: Workflows chapters: - file: workflow diff --git a/docs/notebooks/12_database.py b/docs/notebooks/12_database.py deleted file mode 100644 index 23fb8def..00000000 --- a/docs/notebooks/12_database.py +++ /dev/null @@ -1,105 +0,0 @@ -# # Database -# -# This notebook shows how to use a database for storing and loading simulation and measurement results. -# -# The interface employs [SQLAlchemy](https://www.sqlalchemy.org/), which is installed if you supplied the `[database]` option during gdsfactory installation. -# -# ``` -# pip install "gplugins[database]" -# ``` -# -# The idea is to store simulation, fabrication and measurement data. -# -# ![database](https://i.imgur.com/6A6Xo8C.jpg) -# -# -# ## Overview -# -# 1. You can create an ad-hoc SQLite database, which will store data in a single file (`database.db` in this case) or use the PostgreSQL web hosted database. -# 2. We add wafer and component data to the database -# 3. We add simulation data to the database - -# + -import gdsfactory as gf -from gdsfactory.generic_tech import get_generic_pdk -from sqlalchemy import create_engine, text -from sqlalchemy.orm import Session - -import gplugins.database.models as gd -from gplugins.database import models as m - -gf.config.rich_output() -PDK = get_generic_pdk() -PDK.activate() - -# + - -engine = create_engine("sqlite:///database.db", echo=True, future=True) -m.metadata.create_all(engine) - -c = gf.components.ring_single(radius=10) - -with Session(engine) as session: - w1 = m.Wafer(name="12", serial_number="ABC") - r1 = m.Reticle(name="sky1", wafer_id=w1.id, wafer=w1) - d1 = m.Die(name="d00", reticle_id=r1.id, reticle=r1) - c1 = m.Component(name=c.name, die_id=d1.id, die=d1) - - component_settings = [] - - for key, value in c.settings.changed.items(): - s = m.ComponentInfo(component=c1, component_id=c1.id, name=key, value=value) - component_settings.append(s) - - for port in c.ports.values(): - s = m.Port( - component=c1, - component_id=c1.id, - port_type=port.port_type, - name=port.name, - orientation=port.orientation, - position=port.center, - ) - component_settings.append(s) - - session.add_all([w1, r1, d1, c1]) - session.add_all(component_settings) - session.commit() -# - - - -# ## Querying the database -# -# In this section, we show different ways to query the database using SQLAlchemy. -# -# Individual rows of a selected model, in this case `Wafer`, from the database are fetched as follows: - -with Session(engine) as session: - # Two ways to do the same thing - for wafer in session.query(gd.Wafer): - print(wafer.name, wafer.serial_number) - - for wafer_name, wafer_serial in session.query( - gd.Wafer.name, gd.Wafer.serial_number - ): - print(wafer_name, wafer_serial) - - # Get the `Wafer` from a child `Reticle` - for reticle in session.query(gd.Reticle).all(): - print(reticle.name, reticle.wafer.name) - -# Manual SQL commands may naturally be used as well. - -# Notice how this is different from session -with engine.connect() as connection: - if engine.dialect.name == "postgresql": - # Using postgresql type casting - cursor = connection.execute(text("SELECT * FROM wafer WHERE name = 12::text")) - else: - cursor = connection.execute(text("SELECT * FROM wafer WHERE name is 12")) - for row in cursor: - print(row) - -# ## Add binary files -# -# We can store measurements simulation results as binary blobs of data in cloud buckets (AWS S3, Google Cloud Storage ...) and index them into our database diff --git a/gplugins/database/README.md b/gplugins/database/README.md deleted file mode 100644 index 74b522db..00000000 --- a/gplugins/database/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Database - -Database is hosted on PlanetScale. -Blobs (gds files, yaml files) are hosted on S3. - -## Environment variables - -The following environment variables need to be set: - -``` -PS_DATABASE=gdslib -PS_HOST=xxx.xxxxxxx.xxxx.xxxxx -PS_USERNAME= -PS_PASSWORD= -PS_SSL_CERT=/etc/ssl/certs/ca-certificates.crt -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -``` - -## Tables - -We currently have the following tables in our PlanetScale database: - -- `GdsFile` (test table, not used in production) -- `Component`: Links a component through a hash to blobs (GDS, settings as yaml) in S3. diff --git a/gplugins/database/__init__.py b/gplugins/database/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/gplugins/database/db_upload.py b/gplugins/database/db_upload.py deleted file mode 100644 index c19991fd..00000000 --- a/gplugins/database/db_upload.py +++ /dev/null @@ -1,183 +0,0 @@ -""" Upload a component / simulation result to the database """ - -import hashlib -import os -import tempfile -from functools import cache - -import boto3 -import boto3.session -import gdsfactory as gf -import numpy as np -import pandas as pd -from sqlmodel import Field, SQLModel, create_engine -from sqlmodel import Session as _Session - - -class Session(_Session): - def safe_add(self, model: SQLModel): - """adds a model to the database, but ignores it if it's already in there.""" - return self.execute(model.__class__.__table__.insert().prefix_with("IGNORE").values([model.dict()])) # type: ignore - - def safe_add_all(self, models: list[SQLModel]): - """adds a model to the database, but ignores it if it's already in there.""" - cls = models[0].__class__ - assert all(model.__class__ is cls for model in models) - return self.execute(cls.__table__.insert().prefix_with("IGNORE").values([model.dict() for model in models])) # type: ignore - - -class Component(SQLModel, table=True): - id: int | None = Field(default=None, primary_key=True) - function_name: str = Field(min_length=1, max_length=20) - module: str = Field(min_length=1, max_length=40) - name: str = Field(min_length=1, max_length=40) - hash: str = Field(min_length=32, max_length=32, unique=True) - - -class Simulation(SQLModel, table=True): - id: int | None = Field(default=None, primary_key=True) - function_name: str = Field(min_length=1, max_length=20) - hash: str = Field(min_length=32, max_length=32, unique=True) - component_hash: str = Field(min_length=32, max_length=32, unique=True) - wavelength: float - port_in: str = Field(min_length=1, max_length=10) - port_out: str = Field(min_length=1, max_length=10) - abs: float - angle: float - - -@cache -def get_database_engine(): - host = os.getenv("PS_HOST", "") - database = os.getenv("PS_DATABASE", "") - username = os.getenv("PS_USERNAME", "") - password = os.getenv("PS_PASSWORD", "") - ssl_ca = os.getenv("PS_SSL_CERT", "") - connection_string = f"mysql+pymysql://{username}:{password}@{host}/{database}" - return create_engine( - connection_string, echo=True, connect_args={"ssl": {"ca": ssl_ca}} - ) - - -@cache -def s3_client(): - return boto3.client("s3") - - -def get_component_hash(component: gf.Component) -> str: - with tempfile.NamedTemporaryFile() as file: - path = os.path.abspath(file.name) - component.write_gds(path) - return hashlib.md5(file.read()).hexdigest() - - -def get_s3_key_from_hash(prefix: str, hash: str, ext: str = "gds") -> str: - return os.path.join(f"{prefix}/{ext}/{hash}.{ext}") - - -def convert_to_db_format(sp: dict) -> pd.DataFrame: - df = pd.DataFrame(sp) - wls = df.pop("wavelengths").values - dfs = [] - for c in df.columns: - port_in, port_out = (p.strip() for p in c.split(",")) - cdf = pd.DataFrame( - { - "wavelength": wls, - "port_in": port_in, - "port_out": port_out, - "abs": np.abs(df[c].values), - "angle": np.angle(df[c].values), - } - ) - dfs.append(cdf) - - return pd.concat(dfs, axis=0) - - -if __name__ == "__main__": - import gplugins.gmeep as gm - - component = gf.components.taper(length=100) - component_yaml = component.to_yaml() - - component_model = Component( - function_name=component.metadata["function_name"], - module=component.metadata["module"], - name=component.name, - hash=get_component_hash(component), - ) - engine = get_database_engine() - with Session(engine) as session: - session.safe_add(component_model) - session.commit() - - s3 = s3_client() - with tempfile.TemporaryDirectory() as tempdir: - component_gds_path = os.path.join(tempdir, f"{component_model.hash}.gds") - component_yaml_path = os.path.join(tempdir, f"{component_model.hash}.yml") - component.write_gds(component_gds_path) - with open(component_yaml_path, "w") as file: - file.write(component_yaml) - - component_key = get_s3_key_from_hash("component", component_model.hash, "gds") - component_yaml_key = get_s3_key_from_hash( - "component", component_model.hash, "yml" - ) - s3.upload_file(component_gds_path, "gdslib", component_key) - s3.upload_file(component_yaml_path, "gdslib", component_yaml_key) - - # with tempfile.TemporaryDirectory() as tmpdir: - tmpdir = "/tmp" - tmppath = gm.write_sparameters_meep_1x1( - component, is_3d=False, dirpath=tmpdir, only_return_filepath_sim_settings=True - ) # TODO: split simulation yaml file generation and actual simulation... - simulation_hash = str(tmppath)[-36:-4] - sp = gm.write_sparameters_meep_1x1(component, is_3d=False, dirpath=tmpdir) - yaml_filename = next(fn for fn in os.listdir(tmpdir) if fn.endswith(".yml")) - yaml_path = os.path.join(tmpdir, yaml_filename) - df = convert_to_db_format(sp) - df["component_hash"] = component_model.hash - df["hash"] = simulation_hash - df["function_name"] = "write_sparameters_meep_1x1" - df = df[ - [ - "function_name", - "hash", - "component_hash", - "wavelength", - "port_in", - "port_out", - "abs", - "angle", - ] - ] - simulation_models = [] - for ( - function_name, - hash, - component_hash, - wavelength, - port_in, - port_out, - abs, - angle, - ) in df.values: - simulation_model = Simulation( - function_name=function_name, - hash=hash, - component_hash=component_hash, - wavelength=wavelength, - port_in=port_in, - port_out=port_out, - abs=abs, - angle=angle, - ) - simulation_models.append(simulation_model) - with Session(engine) as session: - session.safe_add_all(simulation_models) - session.commit() - - s3 = s3_client() - yaml_key = get_s3_key_from_hash("simulation", simulation_hash, "yml") - s3.upload_file(yaml_path, "gdslib", yaml_key) diff --git a/gplugins/database/models.py b/gplugins/database/models.py deleted file mode 100644 index 4ea7a99b..00000000 --- a/gplugins/database/models.py +++ /dev/null @@ -1,449 +0,0 @@ -from sqlalchemy import TIMESTAMP, Column, Float, ForeignKey, Integer, String, text -from sqlalchemy.dialects.mysql import TEXT -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import relationship - -Base = declarative_base() -metadata = Base.metadata - - -class Process(Base): - __tablename__ = "process" - __table_args__ = {"comment": "This table holds all foundry process info."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - name = Column(String(200), nullable=False) - process = Column(String(200), nullable=False) - version = Column(String(50), nullable=False) - type = Column(String(50)) - description = Column(String(200)) - - -class Unit(Base): - __tablename__ = "unit" - __table_args__ = { - "comment": "This table holds all units. A unit is here understood as definite magnitude of a quantity." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - name = Column(String(200), nullable=False) - quantity = Column(String(200), nullable=False) - symbol = Column(String(50), nullable=False) - description = Column(String(200)) - - -class Wafer(Base): - __tablename__ = "wafer" - __table_args__ = {"comment": "This table holds the base definition of a wafer."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - serial_number = Column(String(200), nullable=False) - name = Column(String(200)) - description = Column(String(200)) - - -class ComputedResult(Base): - __tablename__ = "computed_result" - __table_args__ = { - "comment": "This table holds all results obtained after computation/analysis of the raw results contained in the table result." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - name = Column(String(200), nullable=False) - type = Column(String(50), nullable=False) - unit_id = Column(ForeignKey("unit.id"), index=True) - domain_unit_id = Column(ForeignKey("unit.id"), index=True) - value = Column(TEXT, nullable=False) - domain = Column(TEXT) - description = Column(String(200)) - - domain_unit = relationship( - "Unit", primaryjoin="ComputedResult.domain_unit_id == Unit.id" - ) - unit = relationship("Unit", primaryjoin="ComputedResult.unit_id == Unit.id") - - -class Result(Base): - __tablename__ = "result" - __table_args__ = {"comment": "This table holds all results."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - name = Column(String(200), nullable=False) - type = Column(String(50), nullable=False) - unit_id = Column(ForeignKey("unit.id"), index=True) - domain_unit_id = Column(ForeignKey("unit.id"), index=True) - value = Column(TEXT, nullable=False) - domain = Column(TEXT) - description = Column(String(200)) - - domain_unit = relationship("Unit", primaryjoin="Result.domain_unit_id == Unit.id") - unit = relationship("Unit", primaryjoin="Result.unit_id == Unit.id") - - -class Reticle(Base): - __tablename__ = "reticle" - __table_args__ = {"comment": "This table holds the definition of a reticle."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - name = Column(String(200), nullable=False) - position = Column( - String(50), comment="Position of the reticle on the wafer. (ROW, COLUMN)" - ) - size = Column( - String(50), - comment="The size of the reticle (X,Y) having the convention that -Å· points towards the notch/flat of the wafer.", - ) - wafer_id = Column(ForeignKey("wafer.id"), nullable=False, index=True) - description = Column(String(200)) - - wafer = relationship("Wafer") - - -class ComputedResultSelfRelation(Base): - __tablename__ = "computed_result_self_relation" - __table_args__ = { - "comment": "This table holds all computed results self relation. This is used to link computed results together" - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - computed_result1_id = Column( - ForeignKey("computed_result.id"), nullable=False, index=True - ) - computed_result2_id = Column( - ForeignKey("computed_result.id"), nullable=False, index=True - ) - - computed_result1 = relationship( - "ComputedResult", - primaryjoin="ComputedResultSelfRelation.computed_result1_id == ComputedResult.id", - ) - computed_result2 = relationship( - "ComputedResult", - primaryjoin="ComputedResultSelfRelation.computed_result2_id == ComputedResult.id", - ) - - -class Die(Base): - __tablename__ = "die" - __table_args__ = {"comment": "This table holds die definition."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - reticle_id = Column(ForeignKey("reticle.id"), nullable=False, index=True) - name = Column(String(200), nullable=False) - position = Column(String(50)) - size = Column(String(50)) - description = Column(String(200)) - - reticle = relationship("Reticle") - - -class ResultComputedResultRelation(Base): - __tablename__ = "result_computed_result_relation" - __table_args__ = { - "comment": "This table holds the relations in between the results and the computed results." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - result_id = Column(ForeignKey("result.id"), nullable=False, index=True) - computed_result_id = Column( - ForeignKey("computed_result.id"), nullable=False, index=True - ) - - computed_result = relationship("ComputedResult") - result = relationship("Result") - - -class ResultInfo(Base): - __tablename__ = "result_info" - __table_args__ = { - "comment": "This table holds extra information about specific results." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - name = Column(String(200), nullable=False) - value = Column(String(200), nullable=False) - result_id = Column(ForeignKey("result.id"), nullable=False, index=True) - computed_result_id = Column( - ForeignKey("computed_result.id"), nullable=False, index=True - ) - unit_id = Column(ForeignKey("unit.id"), index=True) - description = Column(String(200)) - - computed_result = relationship("ComputedResult") - result = relationship("Result") - unit = relationship("Unit") - - -class ResultProcessRelation(Base): - __tablename__ = "result_process_relation" - __table_args__ = { - "comment": "This table holds all results and simulation result relation." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - result_id = Column(ForeignKey("result.id"), nullable=False, index=True) - process_id = Column(ForeignKey("process.id"), nullable=False, index=True) - - process = relationship("Process") - result = relationship("Result") - - -class ResultSelfRelation(Base): - __tablename__ = "result_self_relation" - __table_args__ = { - "comment": "This table holds all results self relation. This is used to link results together" - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - result1_id = Column(ForeignKey("result.id"), nullable=False, index=True) - result2_id = Column(ForeignKey("result.id"), nullable=False, index=True) - - result1 = relationship( - "Result", primaryjoin="ResultSelfRelation.result1_id == Result.id" - ) - result2 = relationship( - "Result", primaryjoin="ResultSelfRelation.result2_id == Result.id" - ) - - -class Component(Base): - __tablename__ = "component" - __table_args__ = {"comment": "This table holds the definition of components."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - die_id = Column(ForeignKey("die.id"), nullable=False, index=True) - name = Column(String(250), nullable=False) - description = Column(String(200)) - - die = relationship("Die") - - -class Port(Base): - __tablename__ = "port" - __table_args__ = {"comment": "This table holds all ports definition."} - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - component_id = Column(ForeignKey("component.id"), nullable=False, index=True) - name = Column(String(200), server_default=text("''")) - port_type = Column(String(200)) - position = Column(String(50), nullable=False) - orientation = Column(Float(asdecimal=True), nullable=False) - description = Column(String(200)) - - component = relationship("Component") - - -class ComponentInfo(Base): - __tablename__ = "component_info" - __table_args__ = { - "comment": "This table holds information for the component using name/value pairs with optional description." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - component_id = Column(ForeignKey("component.id"), index=True) - die_id = Column(ForeignKey("die.id"), index=True) - port_id = Column(ForeignKey("port.id"), index=True) - reticle_id = Column(ForeignKey("reticle.id"), index=True) - wafer_id = Column(ForeignKey("wafer.id"), index=True) - name = Column(String(200), nullable=False) - value = Column(String(200), nullable=False) - description = Column(String(200)) - - component = relationship("Component") - die = relationship("Die") - port = relationship("Port") - reticle = relationship("Reticle") - wafer = relationship("Wafer") - - -class ResultComponentRelation(Base): - __tablename__ = "result_component_relation" - __table_args__ = { - "comment": "This table holds the relations in between results and components." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - result_id = Column(ForeignKey("result.id"), nullable=False, index=True) - component_id = Column(ForeignKey("component.id"), index=True) - die_id = Column(ForeignKey("die.id"), index=True) - port_id = Column(ForeignKey("port.id"), index=True) - reticle_id = Column(ForeignKey("reticle.id"), index=True) - wafer_id = Column(ForeignKey("wafer.id"), index=True) - - component = relationship("Component") - die = relationship("Die") - port = relationship("Port") - result = relationship("Result") - reticle = relationship("Reticle") - wafer = relationship("Wafer") - - -class RelationInfo(Base): - __tablename__ = "relation_info" - __table_args__ = { - "comment": "This table holds extra information about specific relation." - } - - id = Column(Integer, primary_key=True) - created = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - updated = Column( - TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP") - ) - computed_result_self_relation_id = Column( - ForeignKey("computed_result_self_relation.id"), index=True - ) - result_self_relation_id = Column(ForeignKey("result_self_relation.id"), index=True) - result_process_relation_id = Column( - ForeignKey("result_process_relation.id"), index=True - ) - result_component_relation_id = Column( - ForeignKey("result_component_relation.id"), index=True - ) - result_computed_result_relation_id = Column( - ForeignKey("result_computed_result_relation.id"), index=True - ) - name = Column(String(200), nullable=False) - value = Column(String(200), nullable=False) - description = Column(String(200)) - - computed_result_self_relation = relationship("ComputedResultSelfRelation") - result_component_relation = relationship("ResultComponentRelation") - result_computed_result_relation = relationship("ResultComputedResultRelation") - result_process_relation = relationship("ResultProcessRelation") - result_self_relation = relationship("ResultSelfRelation") - - -if __name__ == "__main__": - import gdsfactory as gf - from sqlalchemy import create_engine - from sqlalchemy.orm import Session - - engine = create_engine("sqlite:///database.db", echo=True, future=True) - metadata.create_all(engine) - - c = gf.components.ring_single(radius=10) - - with Session(engine) as session: - w1 = Wafer(name="12", serial_number="ABC") - r1 = Reticle(name="sky1", wafer_id=w1.id, wafer=w1) - d1 = Die(name="d00", reticle_id=r1.id, reticle=r1) - c1 = Component(name=c.name, die_id=d1.id, die=d1) - - component_settings = [] - - for key, value in c.settings.changed.items(): - s = ComponentInfo(component=c1, component_id=c1.id, name=key, value=value) - component_settings.append(s) - - for port in c.ports.values(): - s = Port( - component=c1, - component_id=c1.id, - port_type=port.port_type, - name=port.name, - orientation=port.orientation, - position=port.center, - ) - component_settings.append(s) - - session.add_all([w1, r1, d1, c1]) - session.add_all(component_settings) - session.commit() diff --git a/pyproject.toml b/pyproject.toml index bc250972..db1ef55c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,13 +27,6 @@ version = "0.8.5" [project.optional-dependencies] dagster = ["dagster", "dagit"] -database = [ - "sqlalchemy", - "sqlalchemy-utils", - # "sqlmodel>=0.0.8,<0.1", - "boto3", - "pymysql" -] dev = [ "pre-commit", "pytest", @@ -144,7 +137,6 @@ addopts = '--tb=short' norecursedirs = [ "extra/*.py", 'gplugins/dagster', - 'gplugins/database', 'gplugins/devsim', 'gplugins/sax/integrations', 'gplugins/tidy3d/tests/tests_sparameters',