Bounding Box Wrapper

This example demonstrates the various features of the qtcad.builder.Builder.wrap_in_bbox and qtcad.builder.Builder.extrude_mask_bbox operations using an Xmon coupler layout.

Introduction

The qtcad.builder.Builder.wrap_in_bbox method wraps the entire model or a specific group in a bounding box with a designated padding. This can be useful, for example, when wrapping a device in a surrounding dielectric such as air.

Similarly, qtcad.builder.Builder.extrude_mask_bbox allows for extruding the bounding box of a mask directly.

First, we import the required module.

from qtcad.builder import Builder

Base Model Factory

We define a helper function to instantiate a qtcad.builder.Builder, load the layout of the Xmon coupler, and extrude the metal layer. This allows us to demonstrate different wrapping features from a clean baseline.

The layout contains three physical groups: "ground_plane", "xmon", and "coupler".

def make_xmon_base() -> Builder:
    return (
        Builder(name="xmon_coupler", length_unit_exponent=-6)
        .load_layout("./layouts/xmon_coupler.oas", cell_name="TOP")
        .set_mesh_size(50)
        .use_mask("layer_1")
        .extrude(0.1)
    )

Case 1: Wrapping the Entire Model

To wrap the entire model, we use fill_mode() to ensure physical groups inherit intersecting regions, set the active group name to "wrapper_all", and call wrap_in_bbox() with a 3-tuple representing the padding in the x, y, and z directions.

Builder.wrap_in_bbox(padding: float | tuple[float, float] | tuple[float, float, float] = 0, group: str | list[str] | Callable[[PhysicalGroup], bool] | None = None, nowarn: bool = False) Self

Wrap the group or the entire model (if group is None) in a bounding box with the given padding. The name of the resulting volume must be set with set_group_name. If padding is a single value, it is applied to all three dimensions. If it is a 3-tuple, the values are applied to the x, y and z dimensions respectively. If it is a 2-tuple, the values are applied to the x and y dimensions to create a surface.

Parameters:
  • padding – The padding to add to the bounding box. Can be a single value or a 3-tuple for x, y and z padding.

  • group – The group to wrap in a bounding box. If None, the entire model is wrapped. See get_group for details on the allowed types.

  • nowarn – If True, do not warn if the fragmentation mode is not FragmentationMode.FILL.

builder_all = (
    make_xmon_base()
    .fill_mode()
    .set_group_name("wrapper_all")
    .wrap_in_bbox(padding=(200, 200, 300))
)
[16:05:12] INFO     Loading layout from cache                           misc.py:266
                    /home/hiro/.cache/qtcad/builder/layout_0c2da1173d2c
                    53e07f68cbc3f4f40f623c28c12516346fa5282b274d97d4cb3
                    5_TOP_name_None_-6.pkl
           INFO     Adding mask 'layer_1' from cache                   masks.py:814
           INFO     Using mask 'layer_1' (implicitly selecting      _builder.py:849
                    shapes [Polygon 0 'coupler', Polygon 1 'xmon',
                    Polygon 2 'ground_plane'])
           INFO     Extruding shape 0 from mask 'layer_1' with     _builder.py:3050
                    name 'coupler' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'coupler'
           INFO     Extruding shape 1 from mask 'layer_1' with     _builder.py:3050
                    name 'xmon' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'xmon'
           INFO     Extruding shape 2 from mask 'layer_1' with     _builder.py:3050
                    name 'ground_plane' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'ground_plane'
[16:05:13] INFO     Setting z-coordinate to 0.1                     _builder.py:951
           INFO     Wrapping model in bounding box from            _builder.py:1278
                    [-553.5000001 -540.0000001 -300.0000001] to
                    [580.5000001 540.0000001 300.1000001].
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'wrapper_all'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_all_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_all_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_all_top'
           INFO     Identifying potential intersections...        fragmenter.py:295
           INFO     Fragmenting...                                fragmenter.py:325

We view the resulting model from a side view and save it as a PNG.

builder_all.view(
    save="figs/xmon_wrapped_all.png",
    angles=(-45, 0, 45),
    volume_labels=True,
    surfaces=True,
)
wrap in bbox
           INFO     Saving figure                                  _builder.py:2129

<qtcad.builder.builder.Builder object at 0x7c1aee899550>

Case 2: Wrapping a Specific Group

Rather than wrapping the entire model, we can wrap a single specific physical group. Here, we wrap only the coupler line ("coupler") in a local bounding box named "wrapper_coupler".

builder_coupler = (
    make_xmon_base()
    .fill_mode()
    .set_group_name("wrapper_coupler")
    .wrap_in_bbox(padding=(50, 50, 20), group="coupler")
)
[16:05:14] INFO     Loading layout from cache                           misc.py:266
                    /home/hiro/.cache/qtcad/builder/layout_0c2da1173d2c
                    53e07f68cbc3f4f40f623c28c12516346fa5282b274d97d4cb3
                    5_TOP_name_None_-6.pkl
           INFO     Adding mask 'layer_1' from cache                   masks.py:814
           INFO     Using mask 'layer_1' (implicitly selecting      _builder.py:849
                    shapes [Polygon 0 'coupler', Polygon 1 'xmon',
                    Polygon 2 'ground_plane'])
           INFO     Extruding shape 0 from mask 'layer_1' with     _builder.py:3050
                    name 'coupler' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'coupler'
           INFO     Extruding shape 1 from mask 'layer_1' with     _builder.py:3050
                    name 'xmon' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'xmon'
           INFO     Extruding shape 2 from mask 'layer_1' with     _builder.py:3050
                    name 'ground_plane' by 0.1 at z=0
[16:05:15] INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'ground_plane'
           INFO     Setting z-coordinate to 0.1                     _builder.py:951
           INFO     Wrapping group 'coupler' in bounding box with  _builder.py:1262
                    padding (50, 50, 20)
           INFO     Wrapping model in bounding box from [          _builder.py:1278
                    55.9999999 -103.5000001  -20.0000001] to
                    [241.0000001 103.5000001  20.1000001].
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'wrapper_coupler'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_coupler_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_coupler_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_coupler_top'
           INFO     Identifying potential intersections...        fragmenter.py:295
           INFO     Fragmenting...                                fragmenter.py:325

Viewing the model with the local coupler wrapper.

builder_coupler.view(
    save="figs/xmon_wrapped_coupler.png",
    angles=(-45, 0, 45),
    volume_labels=True,
    surfaces=True,
)
wrap in bbox
           INFO     Saving figure                                  _builder.py:2129

<qtcad.builder.builder.Builder object at 0x7c1a73d8dd10>

Case 3: Wrapping a List of Specific Groups

The group argument also accepts a list of physical group names. Here, we wrap both the "xmon" and "coupler" in a single bounding box named "wrapper_active".

builder_active = (
    make_xmon_base()
    .fill_mode()
    .set_group_name("wrapper_active")
    .wrap_in_bbox(padding=(100, 100, 50), group=["xmon", "coupler"])
)
[16:05:16] INFO     Loading layout from cache                           misc.py:266
                    /home/hiro/.cache/qtcad/builder/layout_0c2da1173d2c
                    53e07f68cbc3f4f40f623c28c12516346fa5282b274d97d4cb3
                    5_TOP_name_None_-6.pkl
           INFO     Adding mask 'layer_1' from cache                   masks.py:814
           INFO     Using mask 'layer_1' (implicitly selecting      _builder.py:849
                    shapes [Polygon 0 'coupler', Polygon 1 'xmon',
                    Polygon 2 'ground_plane'])
           INFO     Extruding shape 0 from mask 'layer_1' with     _builder.py:3050
                    name 'coupler' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'coupler'
           INFO     Extruding shape 1 from mask 'layer_1' with     _builder.py:3050
                    name 'xmon' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'xmon'
           INFO     Extruding shape 2 from mask 'layer_1' with     _builder.py:3050
                    name 'ground_plane' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'ground_plane'
           INFO     Setting z-coordinate to 0.1                     _builder.py:951
           INFO     Wrapping group '['xmon', 'coupler']' in        _builder.py:1262
                    bounding box with padding (100, 100, 50)
           INFO     Wrapping model in bounding box from            _builder.py:1278
                    [-250.0000001 -250.0000001  -50.0000001] to
                    [291.0000001 250.0000001  50.1000001].
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'wrapper_active'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_active_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_active_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_active_top'
           INFO     Identifying potential intersections...        fragmenter.py:295
           INFO     Fragmenting...                                fragmenter.py:325

Viewing the model with the combined active components wrapper.

builder_active.view(
    save="figs/xmon_wrapped_active.png",
    angles=(-45, 0, 45),
    volume_labels=True,
    surfaces=True,
)
wrap in bbox
           INFO     Saving figure                                  _builder.py:2129

<qtcad.builder.builder.Builder object at 0x7c1a78c55090>

Case 4: Wrapping in a 2D Bounding Surface

If a 3D bounding box is not desired, we can wrap the active device components in a 2D bounding surface using wrap_in_bbox_surface().

Builder.wrap_in_bbox_surface(padding: float | tuple[float, float], group: str | list[str] | Callable[[PhysicalGroup], bool] | None = None) Self

Create a bounding surface around the group with the given padding. The name of the resulting surface must be set with set_group_name. If padding is a single value, it is applied to both x and y dimensions. If it is a 2-tuple, the values are applied to the x and y dimensions respectively.

Parameters:
  • padding – The padding to add to the bounding box. Can be a single value or a 2-tuple for x and y padding.

  • group – The group to wrap in a bounding box. Must be specified. See get_group for details on the allowed types.

We wrap only the "xmon" group in a 2D bounding surface at the central plane (z = 5) with 150 padding named "wrapper_surface".

builder_surf = (
    make_xmon_base()
    .set_z(5)
    .set_group_name("wrapper_surface")
    .wrap_in_bbox_surface(padding=150, group="xmon")
)
[16:05:18] INFO     Loading layout from cache                           misc.py:266
                    /home/hiro/.cache/qtcad/builder/layout_0c2da1173d2c
                    53e07f68cbc3f4f40f623c28c12516346fa5282b274d97d4cb3
                    5_TOP_name_None_-6.pkl
           INFO     Adding mask 'layer_1' from cache                   masks.py:814
           INFO     Using mask 'layer_1' (implicitly selecting      _builder.py:849
                    shapes [Polygon 0 'coupler', Polygon 1 'xmon',
                    Polygon 2 'ground_plane'])
           INFO     Extruding shape 0 from mask 'layer_1' with     _builder.py:3050
                    name 'coupler' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'coupler'
           INFO     Extruding shape 1 from mask 'layer_1' with     _builder.py:3050
                    name 'xmon' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'xmon'
           INFO     Extruding shape 2 from mask 'layer_1' with     _builder.py:3050
                    name 'ground_plane' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'ground_plane'
           INFO     Setting z-coordinate to 0.1                     _builder.py:951
           INFO     Setting z-coordinate to 5                       _builder.py:951
           INFO     Wrapping group 'xmon' in bounding box with     _builder.py:1262
                    padding (150, 150, 0)
           INFO     Wrapping model in bounding box from [-3.e+02   _builder.py:1278
                    -3.e+02 -1.e-07] to [3.000000e+02 3.000000e+02
                    1.000001e-01].
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_surface'
           INFO     Identifying potential intersections...        fragmenter.py:295

Viewing the model with the 2D bounding surface wrapper.

builder_surf.view(
    save="figs/xmon_wrapped_surface.png",
    angles=(-45, 0, 45),
    volume_labels=True,
    surfaces=True,
)
wrap in bbox
           INFO     Saving figure                                  _builder.py:2129

<qtcad.builder.builder.Builder object at 0x7c1a78d974d0>

Case 5: Extruding a Mask Bounding Box

Finally, we demonstrate the extrude_mask_bbox() operation. This method extrudes the bounding box of a specified mask (or the current mask if none is specified) by a given height.

Builder.extrude_mask_bbox(height: float, mask: int | str | Mask | Callable[[Mask], bool] | None = None) Self

[🏗️ Operation] Extrude the bounding box of the given mask (or the current mask if mask is None) by height and take the intersection with the model.

Parameters:
  • height – The height by which to extrude the bounding box.

  • mask – The mask to use. If None, the current mask will be used.

builder_extrude_bbox = (
    make_xmon_base()
    .set_z(0)
    .set_group_name("wrapper_mask")
    .extrude_mask_bbox(height=-200, mask="layer_1")
)
[16:05:19] INFO     Loading layout from cache                           misc.py:266
                    /home/hiro/.cache/qtcad/builder/layout_0c2da1173d2c
                    53e07f68cbc3f4f40f623c28c12516346fa5282b274d97d4cb3
                    5_TOP_name_None_-6.pkl
           INFO     Adding mask 'layer_1' from cache                   masks.py:814
           INFO     Using mask 'layer_1' (implicitly selecting      _builder.py:849
                    shapes [Polygon 0 'coupler', Polygon 1 'xmon',
                    Polygon 2 'ground_plane'])
           INFO     Extruding shape 0 from mask 'layer_1' with     _builder.py:3050
                    name 'coupler' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'coupler_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'coupler'
           INFO     Extruding shape 1 from mask 'layer_1' with     _builder.py:3050
                    name 'xmon' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'xmon_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'xmon'
           INFO     Extruding shape 2 from mask 'layer_1' with     _builder.py:3050
                    name 'ground_plane' by 0.1 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'ground_plane_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'ground_plane'
           INFO     Setting z-coordinate to 0.1                     _builder.py:951
           INFO     Setting z-coordinate to 0                       _builder.py:951
           INFO     Using mask 'layer_1' (implicitly selecting      _builder.py:849
                    shapes [Polygon 0 'coupler', Polygon 1 'xmon',
                    Polygon 2 'ground_plane'])
           INFO     Extruding shape 3 from mask 'layer_1' with     _builder.py:3050
                    name 'layer_1_bbox' by -200 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_mask_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_mask_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2834
                    with name 'wrapper_mask_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2834
                    with name 'wrapper_mask'
           INFO     Identifying potential intersections...        fragmenter.py:295
           INFO     Fragmenting...                                fragmenter.py:325
[16:05:20] INFO     Setting z-coordinate to -200                    _builder.py:951
           INFO     Removing shape 3 'layer_1_bbox' from mask 1        masks.py:693
                    'layer_1'.

Viewing the model with the extruded mask bounding box.

builder_extrude_bbox.view(
    save="figs/xmon_extrude_mask_bbox.png",
    angles=(-45, 0, 45),
    volume_labels=True,
    surfaces=True,
)
wrap in bbox
           INFO     Saving figure                                  _builder.py:2129

<qtcad.builder.builder.Builder object at 0x7c1a78d95590>

Total running time of the script: (0 minutes 8.341 seconds)

Gallery generated by Sphinx-Gallery