.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples\07-Circuit\Circuit_Transient.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_07-Circuit_Circuit_Transient.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_07-Circuit_Circuit_Transient.py:


Circuit: transient analysis and eye plot
----------------------------------------
This example shows how you can use PyAEDT to create a circuit design,
run a Nexxim time-domain simulation, and create an eye diagram.

.. GENERATED FROM PYTHON SOURCE LINES 8-11

Perform required imports
~~~~~~~~~~~~~~~~~~~~~~~~
Perform required imports.

.. GENERATED FROM PYTHON SOURCE LINES 11-17

.. code-block:: Python


    import os
    from matplotlib import pyplot as plt
    import numpy as np
    import pyaedt








.. GENERATED FROM PYTHON SOURCE LINES 18-21

Set AEDT version
~~~~~~~~~~~~~~~~
Set AEDT version.

.. GENERATED FROM PYTHON SOURCE LINES 21-24

.. code-block:: Python


    aedt_version = "2024.1"








.. GENERATED FROM PYTHON SOURCE LINES 25-30

Set non-graphical mode
~~~~~~~~~~~~~~~~~~~~~~
Set non-graphical mode, ``"PYAEDT_NON_GRAPHICAL"`` is needed to generate
documentation only.
You can set ``non_graphical`` either to ``True`` or ``False``.

.. GENERATED FROM PYTHON SOURCE LINES 30-33

.. code-block:: Python


    non_graphical = False








.. GENERATED FROM PYTHON SOURCE LINES 34-37

Launch AEDT with Circuit
~~~~~~~~~~~~~~~~~~~~~~~~
Launch AEDT 2023 R2 in graphical mode with Circuit.

.. GENERATED FROM PYTHON SOURCE LINES 37-44

.. code-block:: Python


    cir = pyaedt.Circuit(projectname=pyaedt.generate_unique_project_name(),
                         specified_version=aedt_version,
                         new_desktop_session=True,
                         non_graphical=non_graphical
                         )





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 7204 is still running
      _warn("subprocess %s is still running" % self.pid,
    C:\actions-runner\_work\pyaedt\pyaedt\.venv\lib\site-packages\pyaedt\generic\settings.py:383: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'>
      self._logger = val




.. GENERATED FROM PYTHON SOURCE LINES 45-48

Read IBIS file
~~~~~~~~~~~~~~
Read an IBIS file and place a buffer in the schematic.

.. GENERATED FROM PYTHON SOURCE LINES 48-52

.. code-block:: Python


    ibis = cir.get_ibis_model_from_file(os.path.join(cir.desktop_install_dir, 'buflib', 'IBIS', 'u26a_800.ibs'))
    ibs = ibis.buffers["DQ_u26a_800"].insert(0, 0)








.. GENERATED FROM PYTHON SOURCE LINES 53-56

Place ideal transmission line
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Place an ideal transmission line in the schematic and parametrize it.

.. GENERATED FROM PYTHON SOURCE LINES 56-60

.. code-block:: Python


    tr1 = cir.modeler.components.components_catalog["Ideal Distributed:TRLK_NX"].place("tr1")
    tr1.parameters["P"] = "50mm"








.. GENERATED FROM PYTHON SOURCE LINES 61-64

Create resistor and ground
~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a resistor and ground in the schematic.

.. GENERATED FROM PYTHON SOURCE LINES 64-68

.. code-block:: Python


    res = cir.modeler.components.create_resistor(name="R1", value="1Meg")
    gnd1 = cir.modeler.components.create_gnd()








.. GENERATED FROM PYTHON SOURCE LINES 69-72

Connect elements
~~~~~~~~~~~~~~~~
Connect elements in the schematic.

.. GENERATED FROM PYTHON SOURCE LINES 72-77

.. code-block:: Python


    tr1.pins[0].connect_to_component(ibs.pins[0])
    tr1.pins[1].connect_to_component(res.pins[0])
    res.pins[1].connect_to_component(gnd1.pins[0])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    (True, <pyaedt.modeler.circuits.object3dcircuit.CircuitComponent object at 0x0000022601018730>, <pyaedt.modeler.circuits.object3dcircuit.CircuitComponent object at 0x000002260101BDF0>)



.. GENERATED FROM PYTHON SOURCE LINES 78-81

Place probe
~~~~~~~~~~~
Place a probe and rename it to ``Vout``.

.. GENERATED FROM PYTHON SOURCE LINES 81-89

.. code-block:: Python


    pr1 = cir.modeler.components.components_catalog["Probes:VPROBE"].place("vout")
    pr1.parameters["Name"] = "Vout"
    pr1.pins[0].connect_to_component(res.pins[0])
    pr2 = cir.modeler.components.components_catalog["Probes:VPROBE"].place("Vin")
    pr2.parameters["Name"] = "Vin"
    pr2.pins[0].connect_to_component(ibs.pins[0])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    (True, <pyaedt.modeler.circuits.object3dcircuit.CircuitComponent object at 0x0000022601018160>, <pyaedt.modeler.circuits.object3dcircuit.CircuitComponent object at 0x000002260101AEF0>)



.. GENERATED FROM PYTHON SOURCE LINES 90-93

Create setup and analyze
~~~~~~~~~~~~~~~~~~~~~~~~
Create a transient analysis setup and analyze it.

.. GENERATED FROM PYTHON SOURCE LINES 93-98

.. code-block:: Python


    trans_setup = cir.create_setup(name="TransientRun", setup_type="NexximTransient")
    trans_setup.props["TransientData"] = ["0.01ns", "200ns"]
    cir.analyze_setup("TransientRun")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 99-104

Create report outside AEDT
~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a report outside AEDT using the ``get_solution_data`` method. This
method allows you to get solution data and plot it outside AEDT without needing
a UI.

.. GENERATED FROM PYTHON SOURCE LINES 104-111

.. code-block:: Python


    report = cir.post.create_report("V(Vout)", domain="Time")
    if not non_graphical:
        report.add_cartesian_y_marker(0)
    solutions = cir.post.get_solution_data(domain="Time")
    solutions.plot("V(Vout)")




.. image-sg:: /examples/07-Circuit/images/sphx_glr_Circuit_Transient_001.png
   :alt: Simulation Results Plot
   :srcset: /examples/07-Circuit/images/sphx_glr_Circuit_Transient_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

    <Figure size 2000x1000 with 1 Axes>



.. GENERATED FROM PYTHON SOURCE LINES 112-117

Create report inside AEDT
~~~~~~~~~~~~~~~~~~~~~~~~~
Create a report inside AEDT using the ``new_report`` object. This object is
fully customizable and usable with most of the reports available in AEDT.
The standard report is the main one used in Circuit and Twin Builder.

.. GENERATED FROM PYTHON SOURCE LINES 117-136

.. code-block:: Python


    new_report = cir.post.reports_by_category.standard("V(Vout)")
    new_report.domain = "Time"
    new_report.create()
    if not non_graphical:
        new_report.add_limit_line_from_points([60, 80], [1, 1], "ns", "V")
        vout = new_report.traces[0]
        vout.set_trace_properties(trace_style=vout.LINESTYLE.Dot, width=2, trace_type=vout.TRACETYPE.Continuous,
                                  color=(0, 0, 255))
        vout.set_symbol_properties(style=vout.SYMBOLSTYLE.Circle, fill=True, color=(255, 255, 0))
        ll = new_report.limit_lines[0]
        ll.set_line_properties(style=ll.LINESTYLE.Solid, width=4, hatch_above=True, violation_emphasis=True, hatch_pixels=2,
                               color=(0, 0, 255))
    new_report.time_start = "20ns"
    new_report.time_stop = "100ns"
    new_report.create()
    sol = new_report.get_solution_data()
    sol.plot()




.. image-sg:: /examples/07-Circuit/images/sphx_glr_Circuit_Transient_002.png
   :alt: Simulation Results Plot
   :srcset: /examples/07-Circuit/images/sphx_glr_Circuit_Transient_002.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

    <Figure size 2000x1000 with 1 Axes>



.. GENERATED FROM PYTHON SOURCE LINES 137-140

Create eye diagram inside AEDT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create an eye diagram inside AEDT using the ``new_eye`` object. 

.. GENERATED FROM PYTHON SOURCE LINES 140-146

.. code-block:: Python


    new_eye = cir.post.reports_by_category.eye_diagram("V(Vout)")
    new_eye.unit_interval = "1e-9s"
    new_eye.time_stop = "100ns"
    new_eye.create()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 147-151

Create eye diagram outside AEDT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create the same eye diagram outside AEDT using Matplotlib and the
``get_solution_data`` method.

.. GENERATED FROM PYTHON SOURCE LINES 151-178

.. code-block:: Python


    unit_interval = 1
    offset = 0.25
    tstop = 200
    tstart = 0
    t_steps = []
    i = tstart + offset
    while i < tstop:
        i += 2 * unit_interval
        t_steps.append(i)

    t = [[i for i in solutions.intrinsics["Time"] if k - 2 * unit_interval < i <= k] for k in
         t_steps]
    ys = [[i / 1000 for i, j in zip(solutions.data_real(), solutions.intrinsics["Time"]) if
           k - 2 * unit_interval < j <= k] for k in t_steps]
    fig, ax = plt.subplots(sharex=True)
    cellst = np.array([])
    cellsv = np.array([])
    for a, b in zip(t, ys):
        an = np.array(a)
        an = an - an.mean()
        bn = np.array(b)
        cellst = np.append(cellst, an)
        cellsv = np.append(cellsv, bn)
    plt.plot(cellst.T, cellsv.T, zorder=0)
    plt.show()




.. image-sg:: /examples/07-Circuit/images/sphx_glr_Circuit_Transient_003.png
   :alt: Circuit Transient
   :srcset: /examples/07-Circuit/images/sphx_glr_Circuit_Transient_003.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 179-182

Release AEDT
~~~~~~~~~~~~
Release AEDT.

.. GENERATED FROM PYTHON SOURCE LINES 182-184

.. code-block:: Python

    cir.save_project()
    cir.release_desktop()




.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True




.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (1 minutes 3.982 seconds)


.. _sphx_glr_download_examples_07-Circuit_Circuit_Transient.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: Circuit_Transient.ipynb <Circuit_Transient.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: Circuit_Transient.py <Circuit_Transient.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_