Source code for qdesignoptimizer.utils.chip_generation

"""Tools for creating and configuring basic chips in Qiskit Metal designs."""

import json
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional

from qiskit_metal.designs.design_planar import DesignPlanar

from qdesignoptimizer.utils.names_design_variables import add_design_variables_to_design

if TYPE_CHECKING:
    from qiskit_metal import MetalGUI


[docs] @dataclass class ChipType: """Define physical dimensions and material for a designed chip.""" material: str size_x: str size_y: str size_z: str
[docs] def create_chip_base( chip_name: str, chip_type: ChipType, open_gui: bool = True, design_variables_file: Optional[str] = "design_variables.json", ) -> tuple[DesignPlanar, Optional["MetalGUI"]]: """ Create and return a basic Qiskit Metal planar chip design. Args: chip_name (str): The name to assign to the chip design. chip_type (ChipType): The physical dimensions and material of the chip. open_gui (bool): Whether to open the Qiskit Metal GUI. Defaults to True. design_variables_file (str, optional): If not None, load the design variables from this file after creating the chip. Returns: tuple[DesignPlanar, MetalGUI]: A tuple containing: - The initialized planar design object. - The Metal GUI instance if open_gui is True, otherwise None. Example: >>> chip_dimensions = ChipType(size_x="10mm", size_y="10mm", size_z="0.5mm") >>> design, gui = create_chip_base("my_quantum_chip", chip_dimensions) """ design = DesignPlanar({}, True) design.chip_name = chip_name design.chips.main.material = chip_type.material design.chips.main.size.size_x = chip_type.size_x design.chips.main.size.size_y = chip_type.size_y design.chips.main.size.size_z = chip_type.size_z design.overwrite_enabled = True design.render_mode = "simulate" gui = None if open_gui: # Imported here so that open_gui=False does not require a working Qt stack. # quantum-metal 0.8+ exposes MetalGUI through a module-level __getattr__, # which pylint cannot resolve statically -- hence no-name-in-module. from qiskit_metal import ( # pylint: disable=import-outside-toplevel,no-name-in-module MetalGUI, ) gui = MetalGUI(design) # Hide explicitly rather than toggling: toggle_docks() without an argument # flips whatever state quantum-metal happens to start in, and that starting # state changed in 0.8.x. gui.toggle_docks(True) if design_variables_file is not None: with open(design_variables_file) as in_file: initial_design_variables = json.load(in_file) add_design_variables_to_design(design, initial_design_variables) return design, gui