# This code is part of KQCircuits
# Copyright (C) 2026 IQM Finland Oy
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# https://www.gnu.org/licenses/gpl-3.0.html.
#
# The software distribution should follow IQM trademark policy for open-source software
# (meetiqm.com/iqm-open-source-trademark-policy). IQM welcomes contributions to the code.
# Please see our contribution agreements for individuals (meetiqm.com/iqm-individual-contributor-license-agreement)
# and organizations (meetiqm.com/iqm-organization-contributor-license-agreement).
from kqcircuits.simulations.simulation import Simulation
[docs]
def simulation_from_cell(cell, margin=300, grid_size=1, box=None, ports=None, **kwargs):
"""Returns a Simulation created from an existing cell.
Arguments:
cell: existing top cell for the Simulation
margin: distance (μm) to expand the simulation box (ground plane) around the bounding box of the cell. If the
'box' argument is given, margin is ignored.
grid_size: size of the simulation box will be rounded to this resolution. If the 'box' argument is given, margin
is ignored.
box: the simulation box, or None to defined box from the bounding box of the cell.
ports: optional list of `Port` to assign to the simulation. Pass this when the ports are determined from the
existing geometry, since the default `build` does not add ports.
`**kwargs`: any simulation parameters passed
Returns:
an instance of Simulation subclass
"""
class _Simulation(Simulation):
def build(self):
if ports is not None:
self.ports = ports
if box is None:
box = cell.dbbox().enlarge(margin, margin)
if grid_size > 0:
box.left = round(box.left / grid_size) * grid_size
box.right = round(box.right / grid_size) * grid_size
box.bottom = round(box.bottom / grid_size) * grid_size
box.top = round(box.top / grid_size) * grid_size
return _Simulation(cell.layout(), cell=cell, box=box, **kwargs)