%load_ext autoreload
%autoreload 2
import qiskit_metal as metal
from qiskit_metal import designs, draw
from qiskit_metal import MetalGUI, Dict

design = designs.DesignPlanar()
design.overwrite_enabled = True
gui = MetalGUI(design)

from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket

q1options = dict(
    connection_pads=dict(  # pin connectors
        a = dict(loc_W=+1,loc_H=+1), 
        b = dict(loc_W=-1,loc_H=+1),
        c = dict(loc_W=+1,loc_H=-1),
        d = dict(loc_W=-1,loc_H=-1)
    )
)

q1 = TransmonPocket(design, options = q1options)  # this line only creates the object in memory and executes its __init__(), but does not "implement"

gui.rebuild()  # this updates the QComponent tables by running make()
gui.autoscale()

q1.default_options

q1.options

design.rename_component(q1.id,'Q1')

q1.options.pos_x='-1.5mm'

q2 = design.copy_qcomponent(q1, 'Q2')
q2.options.pos_x='1.5mm'

from qiskit_metal.qlibrary.tlines.meandered import RouteMeander

options = Dict(
    total_length = '8mm',
    pin_inputs = Dict(
        start_pin = Dict(
            component = 'Q1',
            pin = 'a'),
        end_pin = Dict(
            component = 'Q2',
            pin = 'b')),
)

cpw = RouteMeander(design, options=options)
gui.rebuild()
gui.autoscale()

cpw.options.fillet = '90um'
cpw.options.lead.start_straight = '90um'

gui.rebuild()
gui.autoscale()

design.net_info

design.delete_component('Q2')
cpw.delete()

design.net_info

# from qiskit_metal.qlibrary.user_components.my429_qcomponents import MyQComponent1
import sys
sys.path.append('../../resources')
from my429_qcomponents import MyQComponent1

myQC = MyQComponent1(design, 'myQC')

gui.rebuild()  # this is need to actually make() the component
gui.autoscale()

options = Dict(
    total_length = '4mm',
    pin_inputs = Dict(
        start_pin = Dict(
            component = 'Q1',
            pin = 'a'),
        end_pin = Dict(
            component = myQC.name,
            pin = 'in')),
    fillet = '90um',
    lead = Dict(
        start_straight = '90um')
)

cpw = RouteMeander(design, options=options)
gui.rebuild()
gui.autoscale()

cpw.delete()
myQC.delete()

# from qiskit_metal.qlibrary.user_components.my429_qcomponents import MyQComponent2
from my429_qcomponents import MyQComponent2

opt_myqc = Dict(width='1mm', height='0.01mm', pos_x='0.1mm')
myQC = MyQComponent2(design, 'myQC', options=opt_myqc)

cpw = RouteMeander(design, options=options)
gui.rebuild()  # this is need to actually make() the component
gui.autoscale()

myQC.options

cpw.delete()
myQC.delete()

opt_myqc.gap = '8um'
opt_myqc.height = '20um'
# from qiskit_metal.qlibrary.user_components.my429_qcomponents import MyQComponent4
from my429_qcomponents import MyQComponent4

myQC = MyQComponent4(design, options=opt_myqc) #opt_myqc defined earlier

options = Dict(
    total_length = '4mm',
    pin_inputs = Dict(
        start_pin = Dict(
            component = 'Q1',
            pin = 'a'),
        end_pin = Dict(
            component = myQC.name, #updating this
            pin = 'in')),
    fillet = '90um',
    lead = Dict(
        start_straight = '90um')
)

cpw = RouteMeander(design, options=options)
gui.rebuild()  # this is need to actually make() the component
gui.autoscale()

myQC.options