<jupyter_start><jupyter_text>Analyzing and tuning a transmon qubit with a resonatorWe will showcase two methods (EPR amd LOM) to analyze the same design. Specifically, we will use here the `advanced` methods to run the simulations and analysis, which directly contorl renderers and external packages. Please refer to the tutorial notebooks 4.1 and 4.2 to follow the `suggested` flow to run the analysis.  Index Transmon & resonator design1. Prepare the single transmon qubit layout in qiskit-metal.  Transmon & resonator analysis using EPR method1. Set-up and run a finite element simulate to extract the eigenmode. 1. Display EM fields to inspect quality of the setup. 1. Identify junction parameters for the EPR analysis. 1. Run EPR analysis on single eigenmode. 1. Get qubit freq and anharmonicity. 1. Calculate EPR of substrate.   Transmon & resonator analysis using LOM method1. Calculate the capacitance matrix. 1. Execute analysis on extracted LOM.   PrerequisiteYou need to have a working local installation of Ansys.Also you will need the following directives and inports.<jupyter_code>%load_ext autoreload
%autoreload 2

import qiskit_metal as metal
from qiskit_metal import designs, draw
from qiskit_metal import MetalGUI, Dict, Headings
import pyEPR as epr<jupyter_output><empty_output><jupyter_text>1. Create the Qbit designFix the design dimensions that you intend to reflect in the design rendering. Note that the design size extends from the origin into the first quadrant.<jupyter_code>design = designs.DesignPlanar({}, True)
design.chips.main.size['size_x'] = '2mm'
design.chips.main.size['size_y'] = '2mm'

gui = MetalGUI(design)<jupyter_output><empty_output><jupyter_text>Create a single transmon with one readout resonator. Please refer to the notebook tutorials 4.11 ad 4.12 if you're not familiar with the code in the cell below.<jupyter_code>from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket
from qiskit_metal.qlibrary.terminations.open_to_ground import OpenToGround
from qiskit_metal.qlibrary.tlines.meandered import RouteMeander

design.delete_all_components()

q1 = TransmonPocket(design, 'Q1', options = dict(
    pad_width = '425 um', 
    pocket_height = '650um',
    connection_pads=dict(
        readout = dict(loc_W=+1,loc_H=+1, pad_width='200um')
    )))
otg = OpenToGround(design, 'open_to_ground', options=dict(pos_x='1.75mm',  pos_y='0um', orientation='0'))
readout = RouteMeander(design, 'readout',  Dict(
            total_length='6 mm',
            hfss_wire_bonds = True,
            fillet='90 um',
            lead = dict(start_straight='100um'),
            pin_inputs=Dict(
                start_pin=Dict(component='Q1', pin='readout'),
                end_pin=Dict(component='open_to_ground', pin='open')), ))

gui.rebuild()
gui.autoscale()<jupyter_output><empty_output><jupyter_text>2. Analyze the transmon & resonator using the Eigenmode-EPR methodIn this section we will use a semi-manual (advanced) analysis flow. Please refer to tutorial 4.2 for the `suggested` method. As illustrated, the methods are equivalent, but the advanced method allows you to directly override some renderer-specific settings. Finite Element Eigenmode Analysis SetupSelect the analysis you intend to run from the `qiskit_metal.analyses` collection.Select the design to analyze and the tool to use for any external simulation.<jupyter_code>from qiskit_metal.analyses.quantization import EPRanalysis
eig_qres = EPRanalysis(design, "hfss")<jupyter_output><empty_output><jupyter_text>For the Eigenmode simulation portion, you can either:1. Use the `eig_qres` user-friendly methods (see tutorial 4.2)2. Control directly the simulation tool from the tool's GUI (outside metal - see specific vendor instructions)3. Use the renderer methodsIn this section we show the advanced method (method 3).The renderer can be reached from the analysis class. Let's give it a shorter alias.<jupyter_code>hfss = eig_qres.sim.renderer<jupyter_output><empty_output><jupyter_text>Now we connect to the tool using the unified command.<jupyter_code>hfss.start()<jupyter_output><empty_output><jupyter_text>The previous command is supposed to open ansys (if closed), create a new project and finally connect this notebook to it.If for any reason the previous cell failed, please try the manual path described in the next three cells:1. uncomment and execute only **one** of the lines in the first cell.1. uncomment and execute the second cell.1. uncomment and execute only **one** of the lines in the third cell.<jupyter_code># hfss.open_ansys()   # this opens Ansys 2021 R2 if present
# hfss.open_ansys(path_var='ANSYSEM_ROOT211')
# hfss.open_ansys(path='C:\Program Files\AnsysEM\AnsysEM21.1\Win64')
# hfss.open_ansys(path='../../../Program Files/AnsysEM/AnsysEM21.1/Win64')
# hfss.new_ansys_project()
# hfss.connect_ansys()
# hfss.connect_ansys('C:\\project_path\\', 'Project1')  # will open a saved project before linking the Jupyter session<jupyter_output><empty_output><jupyter_text>Execute simulation and verify convergenceCreate and activate an eigenmode design called "TransmonReadout".<jupyter_code>hfss.activate_ansys_design("TransmonReadout", 'eigenmode')  # use new_ansys_design() to force creation of a blank design<jupyter_output><empty_output><jupyter_text>Render everything inlcuding the qubit and resonator in Metal, to "TransmonReadout" design in Ansys.<jupyter_code>hfss.render_design(['Q1', 'readout', 'open_to_ground'], [])
hfss.save_screenshot()<jupyter_output><empty_output><jupyter_text>Set the convergence parameters and junction properties in the Ansys design. Then run the analysis and plot the convergence.Note that we seek 2 eigenmodes - one with stronger fields near the transmon, the other with stronger fields near the resonator.<jupyter_code># Analysis properties
setup = hfss.pinfo.setup
setup.n_modes = 2
setup.passes = 10
print(f"""
Number of eigenmodes to find             = {setup.n_modes}
Number of simulation passes              = {setup.passes}
Convergence freq max delta percent diff  = {setup.delta_f}
""")

pinfo = hfss.pinfo
pinfo.design.set_variable('Lj', '10 nH')
pinfo.design.set_variable('Cj', '0 fF')

setup.analyze()<jupyter_output><empty_output><jupyter_text>To plot the results you can use the `plot_convergences()` method from the `eig_qres.sim` object. The method will read the data from the variables local to the `eig_qres.sim` object, so we first need to assign the simulation results to these two variables. let's do both (assignment and plotting) in the next cell.<jupyter_code>eig_qres.sim.convergence_t, eig_qres.sim.convergence_f, _ = hfss.get_convergences()
eig_qres.sim.plot_convergences()<jupyter_output><empty_output><jupyter_text>Plot the EM field for inspectionDisplay the Ansys modeler window and plot the E-field on the chip's surface.<jupyter_code>hfss.modeler._modeler.ShowWindow()
hfss.plot_fields('main')
hfss.save_screenshot()<jupyter_output><empty_output><jupyter_text>Delete the newly created E-field plot before moving on.<jupyter_code>hfss.clear_fields(['Mag_E1'])<jupyter_output><empty_output><jupyter_text>To look at the second eigenmode created, we use the following command, and then plot the corresponding E-field.<jupyter_code>hfss.set_mode(2, "Setup")
hfss.modeler._modeler.ShowWindow()
hfss.plot_fields('main')
hfss.save_screenshot()<jupyter_output><empty_output><jupyter_text>We delete this design to prepare for further analysis.<jupyter_code>hfss.clear_fields(['Mag_E1'])<jupyter_output><empty_output><jupyter_text>EPR AnalysisIn the `suggested` (tutorial 4.2) flow, we would now prepare the setup using `eig_qres.setup` and run the analysis with `eig_qres.run_epr()`. Notice that this method requires previous set of the `eig_qres` variables `convergence_t` and `convergence_f` like we did a thee cells earlier.However we here exemplify the advanced approach, which is Ansys-specific since it uses the pyEPR module methods directly. SetupIdentify the non-linear (Josephson) junctions in the model. You will need to list the junctions in the epr setup.In this case there's only one junction, namely 'jj'. Let's see what we need to change in the default setup.<jupyter_code>pinfo = hfss.pinfo
pinfo.junctions['jj'] = {'Lj_variable': 'Lj', 'rect': 'JJ_rect_Lj_Q1_rect_jj', 
                             'line': 'JJ_Lj_Q1_rect_jj_',  'Cj_variable': 'Cj'}
pinfo.validate_junction_info() # Check that valid names of variables and objects have been supplied
pinfo.dissipative['dielectrics_bulk'] = ['main'] # Dissipative elements: specify<jupyter_output><empty_output><jupyter_text>Execute the energy distribution analysisExecute microwave analysis on eigenmode solutions.<jupyter_code>eprd = epr.DistributedAnalysis(pinfo)<jupyter_output><empty_output><jupyter_text>Find the electric and magnetic energy stored in the substrate and the system as a whole.<jupyter_code>ℰ_elec = eprd.calc_energy_electric()
ℰ_elec_substrate = eprd.calc_energy_electric(None, 'main')
ℰ_mag = eprd.calc_energy_magnetic()

print(f"""
ℰ_elec_all       = {ℰ_elec}
ℰ_elec_substrate = {ℰ_elec_substrate}
EPR of substrate = {ℰ_elec_substrate / ℰ_elec * 100 :.1f}%

ℰ_mag_all       = {ℰ_mag}
ℰ_mag % of ℰ_elec_all  = {ℰ_mag / ℰ_elec * 100 :.1f}%
""")<jupyter_output><empty_output><jupyter_text>Run EPR analysisPerform EPR analysis for all modes and variations.<jupyter_code>eprd.do_EPR_analysis()

# 4a. Perform Hamiltonian spectrum post-analysis, building on mw solutions using EPR
epra = epr.QuantumAnalysis(eprd.data_filename)
epra.analyze_all_variations(cos_trunc = 8, fock_trunc = 7)

# 4b. Report solved results
swp_variable = 'Lj' # suppose we swept an optimetric analysis vs. inductance Lj_alice
epra.plot_hamiltonian_results(swp_variable=swp_variable)
epra.report_results(swp_variable=swp_variable, numeric=True)<jupyter_output><empty_output><jupyter_text>Release Ansys session<jupyter_code>eig_qres.sim.close()<jupyter_output><empty_output><jupyter_text>3. Analyze the transmon using the LOM methodIn this section we will use a semi-manual (advanced) analysis flow. Please refer to tutorial 4.1 for the `suggested` method. As illustrated, the methods are equivalent, but the advanced method allows you to directly override some renderer-specific settings. Capacitance matrix extraction SetupSelect the analysis you intend to run from the `qiskit_metal.analyses` collection.Select the design to analyze and the tool to use for any external simulation.<jupyter_code>from qiskit_metal.analyses.quantization import LOManalysis
c2 = LOManalysis(design, "q3d")<jupyter_output><empty_output><jupyter_text>For the capacitive simulation portion, you can either:1. Use the `c2` user-friendly methods (see tutorial 4.1)2. Control directly the simulation tool from the tool's GUI (outside metal - see specific vendor instructions)3. Use the renderer methodsIn this section we show the advanced method (method 3).The renderer can be reached from the analysis class. Let's give it a shorter alias.<jupyter_code>q3d = c2.sim.renderer<jupyter_output><empty_output><jupyter_text>Now we connect to the simulation tool, similarly to what we have done for the eigenmode analysis.<jupyter_code>q3d.start()<jupyter_output><empty_output><jupyter_text>If the simulator is already open, the line above will simply connect to the open session, project and design. Execute simulation and verify convergenceCreate and activate a q3d design called "TransmonResonator_q3d".<jupyter_code>q3d.activate_ansys_design("TransmonResonator_q3d", 'capacitive')<jupyter_output><empty_output><jupyter_text>Next, we render the exisitng design to Ansys Q3D for analysis. To ensure that the readout is insulated from the ground plane, we set the 'readout' pin of Q1 to have an open termination.<jupyter_code>q3d.render_design(['Q1'], [('Q1','readout')])<jupyter_output><empty_output><jupyter_text>Execute the capacitance extraction and verify converengence. This cell analyzes the default setup.<jupyter_code>q3d.analyze_setup("Setup")<jupyter_output><empty_output><jupyter_text>This simulation had 4 nets, the two charge islands of the floating transmon, the readout coupler, and the ground, resulting in a 4x4 capacitance matrix. Output is of type DataFrame.<jupyter_code>c2.sim.capacitance_matrix, c2.sim.units = q3d.get_capacitance_matrix()
c2.sim.capacitance_all_passes, _ = q3d.get_capacitance_all_passes()
c2.sim.capacitance_matrix<jupyter_output><empty_output><jupyter_text>LOM AnalysisNow we provide the junction lumped element values, and complete the analysis by plotting the convergence. This is the same steps used in the `suggested` flow from tutorial 4.1.<jupyter_code>c2.setup.junctions=Dict(Lj=12.31, Cj=2)
c2.setup.freq_readout = 7.0
c2.setup.freq_bus = []

c2.run_lom()
c2.lumped_oscillator_all<jupyter_output><empty_output><jupyter_text>And plot the convergence.<jupyter_code>c2.plot_convergence();
c2.plot_convergence_chi()<jupyter_output><empty_output><jupyter_text>Release the simulator and close the analysis.<jupyter_code>c2.sim.close()<jupyter_output><empty_output><jupyter_text>(optional) close the GUI.<jupyter_code># gui.main_window.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08612294583079733, 'fraction_numerical': 0.011944613511868533, 'mean_word_length': 6.082435344827586, 'pattern_counts': {'":': 0, '<': 125, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '31', 'dir': 'jupyter-structured-clean-dedup', 'id': '90833', 'license': 'Apache-2.0', 'n_tokens_mistral': 4343, 'n_tokens_neox': 4118, 'n_words': 1290, 'path': 'tutorials/4 Analysis/B. Advanced - Direct use of the renderers/4.13 Analyze transmon and resonator.ipynb', 'repo_name': 'camponogaraviera/qiskit-metal', 'size': '13144'}