### Install SQcircuit via pip Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/installation.rst.txt Instructions to install the SQcircuit library using the pip Python package manager. ```bash pip install SQcircuit ``` -------------------------------- ### Install SQcircuit via Pip Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/installation.rst Instructions to install the SQcircuit library using pip, the Python package manager. This is a common method for Python package installation. ```bash pip install SQcircuit ``` -------------------------------- ### Install and Upgrade SQcircuit using pip Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/installation.html Instructions to install the SQcircuit library using the pip Python package manager, including how to upgrade to the latest version. ```Python pip install SQcircuit ``` ```Python pip install SQcircuit -U ``` -------------------------------- ### Clone SQcircuit Examples Repository Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples.rst.txt Users can clone the Jupyter notebooks containing all the SQcircuit examples to their local system for direct execution and exploration. ```Shell git clone https://github.com/stanfordLINQS/SQcircuit-examples ``` -------------------------------- ### Clone SQcircuit Examples Repository Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples.html Instructions for users to clone the Jupyter notebook examples of SQcircuit to their local system from the official GitHub repository. This command downloads all the example notebooks. ```Shell git clone https://github.com/stanfordLINQS/SQcircuit-examples ``` -------------------------------- ### Install SQcircuit via Conda Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/installation.rst.txt Instructions to install the SQcircuit library using the Conda package manager for Python versions 3.6 and above. ```bash conda install -c conda-forge sqcircuit ``` -------------------------------- ### Install and Update SQcircuit using Conda Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/installation.html Instructions to install the SQcircuit library using the Conda package manager, including how to update to the latest version from the conda-forge channel. ```Conda conda install -c conda-forge sqcircuit ``` ```Conda conda update -c conda-forge sqcircuit ``` -------------------------------- ### SQcircuit General Requirements and Dependencies Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/installation.rst Lists the minimum required versions for Python and its open-source library dependencies that SQcircuit relies on for proper functionality. These packages must be installed in your environment. ```APIDOC Package | Version | Details Python | 3.6+ | Version 3.6 and higher is supported. NumPy | 1.20.0+ | Not tested on lower versions. SciPy | 1.7.0+ | Not tested on lower versions. QuTiP | 4.6+ | Quantum operators are defined in QuTip objects. IPython | 7.0+ | Not tested on lower versions. ``` -------------------------------- ### Import SQcircuit Library Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/quick_tutorial.rst This snippet demonstrates how to import the SQcircuit library into a Python script after installation, making its functionalities available for circuit simulations. ```python # import the SQcircuit library import SQcircuit as sq ``` -------------------------------- ### Upgrade SQcircuit via pip Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/installation.rst.txt Command to upgrade an existing SQcircuit installation to the latest version using pip. ```bash pip install SQcircuit -U ``` -------------------------------- ### Clone SQcircuit Examples Repository Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/examples.rst Users can clone the Jupyter notebook examples for the SQcircuit library to their local system using this Git command. This repository contains various examples demonstrating the library's functionalities, from simple qubits to complex superconducting circuits. ```Shell git clone https://github.com/stanfordLINQS/SQcircuit-examples ``` -------------------------------- ### Update SQcircuit via Conda Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/installation.rst.txt Command to update an existing SQcircuit installation to the latest version using Conda. ```bash conda update -c conda-forge sqcircuit ``` -------------------------------- ### Enable Sphinx Read the Docs Navigation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/guides/guides.html Initializes the navigation functionality provided by the Sphinx Read the Docs theme upon document load, enhancing user experience. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Install SQcircuit via Conda Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/installation.rst Instructions to install the SQcircuit library using the Conda package manager for Python versions 3.6 and above. This command adds the 'conda-forge' channel and installs 'sqcircuit'. ```bash conda install -c conda-forge sqcircuit ``` -------------------------------- ### Upgrade SQcircuit via Pip Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/installation.rst Instructions to upgrade the SQcircuit library to its latest version using pip. The '-U' flag ensures an upgrade to the newest available package. ```bash pip install SQcircuit -U ``` -------------------------------- ### Get Loop Description with All Flux Distribution Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/guides/loop_dist.ipynb This example shows how to create an SQcircuit `Circuit` instance with the `flux_dist` option set to 'all'. It then calls the `loop_description()` method to display the external flux distribution, which is expected to be equal among elements due to the initial setup with equal capacitors. ```python cr = sq.Circuit(elements, flux_dist='all') cr.loop_description() ``` -------------------------------- ### Update SQcircuit via Conda Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/installation.rst Instructions to update the SQcircuit library to its latest version using the Conda package manager. This ensures you have the most recent features and bug fixes. ```bash conda update -c conda-forge sqcircuit ``` -------------------------------- ### Get Loop Description with Inductors Flux Distribution Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/guides/loop_dist.ipynb This example illustrates how to initialize an SQcircuit `Circuit` with `flux_dist` set to 'inductors'. It then calls `loop_description()` to show the resulting external flux distribution, demonstrating the behavior when inductor capacitors are prioritized. ```python cr = sq.Circuit(elements, flux_dist="inductors") cr.loop_description() ``` -------------------------------- ### Configure MathJax for Documentation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/guides/guides.html Configures MathJax to render inline and escaped LaTeX equations within the documentation, ignoring specific HTML classes and processing others. ```JavaScript window.MathJax = {"tex": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true}, "options": {"ignoreHtmlClass": "tex2jax_ignore|mathjax_ignore|document", "processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}} ``` -------------------------------- ### Import SQcircuit Library Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/quick_tutorial.rst.txt Import the necessary SQcircuit library into your Python script to begin working with quantum circuits. ```python # import the SQcircuit library import SQcircuit as sq ``` -------------------------------- ### Initialize OpenAIModel Class Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/kite.ipynb.txt This snippet documents the constructor for the OpenAIModel class. It details the required parameters for initializing an instance of the model, including the model name and an optional provider. ```APIDOC OpenAIModel: __init__(model_name: str, provider: str = 'openai') model_name: The name of the OpenAI model to use provider: The provider to use (defaults to 'openai') ``` -------------------------------- ### Define Circuit Topology with SQcircuit Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/quick_tutorial.rst.txt Construct the circuit topology by creating a dictionary that maps edges to lists of circuit elements. This dictionary is then passed to the `sq.Circuit` class to define the complete circuit. ```python # dictionary that contains the list of all elements at each edge elements = {(0, 1): [CJ, JJ], (0, 2): [L], (0, 3): [C], (1, 2): [C], (1, 3): [L], (2, 3): [CJ, JJ]} # define the circuit cr = sq.Circuit(elements) ``` -------------------------------- ### Enable Sphinx Read the Docs Theme Navigation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/apidoc.html Initializes the navigation functionality for the Sphinx Read the Docs theme using jQuery, ensuring the sidebar navigation is enabled. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Importing SQcircuit and Essential Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/kite.ipynb.txt This snippet imports the necessary Python libraries for circuit simulation and plotting. It includes `SQcircuit` for quantum circuit analysis, `numpy` for numerical operations, and `matplotlib.pyplot` for data visualization. ```python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Enable Sphinx Read the Docs Theme Navigation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/search.html This JavaScript snippet initializes and activates the navigation system for documentation built with the Sphinx Read the Docs theme. It ensures that the sidebar navigation elements are interactive, allowing users to expand and collapse sections. This enhances user experience by providing dynamic navigation through the documentation. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Get Gradient of Eigenvectors Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/circuit.html Returns the gradient of the eigenvectors with respect to circuit elements (Capacitor, Inductor, Junction) or loops, formatted as a `qutip.Qobj`. ```APIDOC get_partial_vec(el: Union[Element, Loop], m: int, epsilon: float = 1e-12) Description: Return the gradient of the eigenvectors with respect to elements or loop as qutip.Qobj format. Parameters: el (Union[Element, Loop]): Element of a circuit that can be either Capacitor, Inductor, Junction, or Loop. m (int): Integer specifies the eigenvalue. for example m=0 specifies the ground state and m=1 specifies the first excited state. Return type: Qobj Returns: Partial derivative of the mth eigenvector, with respect to el. ``` -------------------------------- ### Import SQcircuit Library Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/quick_tutorial.html This snippet shows how to import the SQcircuit library into a Python script, aliasing it as 'sq' for convenience. ```Python import SQcircuit as sq ``` -------------------------------- ### Get State Dimensions for Qutip.Qobj Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html This internal method returns the state dimensions relevant for `Qutip.Qobj` objects, derived from the circuit's mode configuration. ```APIDOC SQcircuit.Circuit._get_state_dims(self) -> List[list] Returns: List[list]: The state dimensions. ``` -------------------------------- ### Import SQcircuit and Core Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/fluxonium.html Imports necessary libraries: `SQcircuit` for circuit simulation, `numpy` for numerical operations, and `matplotlib.pyplot` for plotting. ```Python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Import SQcircuit and Related Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/zeropi_qubit.ipynb.txt This snippet imports the necessary Python libraries: SQcircuit for quantum circuit simulations, Matplotlib for plotting, and NumPy for numerical operations, setting up the environment for circuit analysis. ```python import SQcircuit as sq import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### Get Inductor Key (API) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/elements.html Returns a unique identifier tuple for the inductor, composed of the edge it belongs to, a reference to the inductor object itself, and its inductive element index. ```APIDOC def get_key(self, edge, B_idx, *_): """Return the inductor key. Parameters ---------- edge: Edge that element is part of. B_idx: The inductive element index """ ``` -------------------------------- ### Get Operator Dimensions for Qutip.Qobj Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html This internal method returns the operator dimensions relevant for `Qutip.Qobj` objects, based on the circuit's internal mode structure. ```APIDOC SQcircuit.Circuit._get_op_dims(self) -> List[list] Returns: List[list]: The operator dimensions. ``` -------------------------------- ### Get External Flux Distribution Description Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html This method prints out the external flux distribution over inductive elements. It can optionally return the description as a string for testing purposes. ```APIDOC SQcircuit.Circuit.loop_description(self, _test: bool = False) -> Optional[str] Parameters: _test (bool, optional): If True, returns the entire description as a string. Use only for testing the function. Defaults to False. Returns: Optional[str]: The text of the external flux distribution, if `_test` is `True`. ``` -------------------------------- ### Import SQcircuit and Related Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/examples/kite.ipynb This snippet imports the necessary Python libraries: `SQcircuit` for circuit simulation, `numpy` for numerical operations, and `matplotlib.pyplot` for plotting, which are essential for defining, analyzing, and visualizing the quantum circuit. ```python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Enable Sphinx Read the Docs Theme Navigation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/index.html This jQuery snippet initializes and enables the navigation functionality provided by the Sphinx Read the Docs theme. It ensures that interactive elements of the navigation, such as the sidebar and its collapsible sections, are active and responsive for users browsing the documentation. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### SQcircuit.Circuit.coord_transform - Get Coordinate Transformation Matrix Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/circuit.html Returns the transformation matrix for the circuit's coordinates as an ndarray. This transformation can be retrieved for either charge or flux variables. ```APIDOC SQcircuit.Circuit.coord_transform(var_type: str) var_type: The type of the variables that can be either "charge" or "flux". Returns: Matrix giving coordinate transformation for var_type coordinates. Return Type: ndarray ``` -------------------------------- ### SQcircuit.Circuit.coupling_op - Get Coupling Operator Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/circuit.html Returns the capacitive or inductive coupling operator between specified circuit nodes. The operator is returned in `qutip.Qobj` format, suitable for quantum calculations. ```APIDOC SQcircuit.Circuit.coupling_op(ctype: str, nodes: Tuple[int, int]) ctype: Coupling type which is either "capacitive" or "inductive". nodes: A tuple of circuit nodes to which we want to couple. Returns: Coupling operator of type ctype between nodes in nodes. Return Type: Qobj ``` -------------------------------- ### Import SQcircuit and Essential Libraries in Python Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/fluxonium.ipynb.txt This snippet imports the necessary Python libraries for quantum circuit simulations: `SQcircuit` for defining and analyzing circuits, `numpy` for numerical operations, and `matplotlib.pyplot` for data visualization. ```Python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### SQcircuit.Circuit.eig_phase_coord - Get Eigenvector Phase Coordinates Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/circuit.html Returns the phase coordinate representations of the eigenvectors as an ndarray. This function allows evaluation of the wavefunction for a specific eigenvector index over a provided grid of phase values. ```APIDOC SQcircuit.Circuit.eig_phase_coord(k: int, grid: Sequence[ndarray]) k: The eigenvector index. For example, we set it to 0 for the ground state and 1 for the first excited state. grid: A list that contains the range of values of phase φ for which we want to evaluate the wavefunction. Returns: Phase coordinate representation of the k'th eigenvector over the values of φ provided in grid. Return Type: ndarray ``` -------------------------------- ### Python: Get SQcircuit Eigenfrequencies (efreqs) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html The `efreqs` property returns the eigenfrequencies of the SQcircuit in the chosen frequency unit. It asserts that the circuit has been diagonalized and returns frequencies as a `ndarray` or `Tensor` depending on the SQcircuit engine. ```Python @property def efreqs(self) -> Union[ndarray, Tensor]: """Eigenfrequencies in the chosen frequency unit for SQcircuit. If the SQcircuit engine is ``PyTorch``, the efreqs will be in ``Tensor`` format; otherwise, they will be in ``ndarray`` format.""" assert len(self._efreqs) != 0, "Please diagonalize the circuit first." return self._efreqs / (2 * np.pi * unt.get_unit_freq()) ``` -------------------------------- ### Import SQcircuit and Related Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/examples/fluxonium.ipynb This snippet imports the necessary Python libraries: `SQcircuit` for quantum circuit simulations, `numpy` for numerical operations, and `matplotlib.pyplot` for plotting results. These are fundamental dependencies for the subsequent circuit analysis. ```python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Define Circuit Topology using a Dictionary Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/quick_tutorial.rst After defining all individual components, the circuit's topology is described by creating a `Circuit` object. This is done by providing a Python dictionary that maps edges (represented as tuples) to lists of components connected between those nodes. ```python # dictionary that contains the list of all elements at each edge elements = {(0, 1): [CJ, JJ], (0, 2): [L], (0, 3): [C], (1, 2): [C], (1, 3): [L], (2, 3): [CJ, JJ]} # define the circuit cr = sq.Circuit(elements) ``` -------------------------------- ### Configure Default Element Units in SQcircuit Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/guides/units.rst.txt Illustrates how to set default units for specific circuit elements such as capacitors, inductors, and Josephson junctions using functions like `sq.set_unit_cap()`, `sq.set_unit_ind()`, and `sq.set_unit_JJ()`. The example shows setting capacitor units to femtofarads. ```Python # capacitors in GHz default unit C1 = sq.Capacitor(10) C2 = sq.Capacitor(12) sq.set_unit_cap("fF") # capacitors in fF default unit C3 = sq.Capacitor(3) C4 = sq.Capacitor(4) ``` -------------------------------- ### Get Capacitance for Flux Distribution in SQcircuit Junction Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/elements.html This method returns the capacitance value based on the specified flux distribution type. It provides different capacitance values for 'all', 'junctions', or 'inductors' flux distributions. ```Python def get_cap_for_flux_dist(self, flux_dist): if flux_dist == 'all': return self.cap.get_value() elif flux_dist == "junctions": return VerySmallCap().get_value() elif flux_dist == "inductors": return VeryLargeCap().get_value() ``` -------------------------------- ### Define Circuit Topology with Elements Dictionary Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/quick_tutorial.html This code defines the circuit's topology by creating a Python dictionary where keys represent edges and values are lists of circuit elements connected to those edges. This dictionary is then passed to the `sq.Circuit` class to instantiate the circuit. ```Python elements = {(0, 1): [CJ, JJ], (0, 2): [L], (0, 3): [C], (1, 2): [C], (1, 3): [L], (2, 3): [CJ, JJ]} cr = sq.Circuit(elements) ``` -------------------------------- ### Get Gradient of Eigen Angular Frequency Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/circuit.html Returns the gradient of the eigen angular frequency with respect to circuit elements (Capacitor, Inductor, Junction) or loops, formatted as a `qutip.Qobj`. It can optionally subtract the ground state frequency. ```APIDOC get_partial_omega(el: Union[Capacitor, Inductor, Junction, Loop], m: int, subtract_ground: bool = True, _B_idx: Optional[int] = None) Description: Return the gradient of the eigen angular frequency with respect to elements or loop as qutip.Qobj format. Parameters: el (Union[Capacitor, Inductor, Junction, Loop]): Element of a circuit that can be either Capacitor, Inductor, Junction, or Loop. m (int): Integer specifies the eigenvalue. for example m=0 specifies the ground state and m=1 specifies the first excited state. subtract_ground (bool): If True, it subtracts the ground state frequency from the desired frequency. _B_idx (Optional[int]): Optional integer to indicate which row of the B matrix (per-element external flux distribution) to use. This specifies which JJ of the circuit to consider specifically (ex. for critical current noise calculation). Return type: float Returns: Partial derivative of eigenfrequency m with respect to el, in units of angular frequency. ``` -------------------------------- ### Python Documentation Project Dependencies Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/requirements.txt This snippet lists the Python packages and their minimum versions required to build the Sphinx documentation for the sqcircuit project. These dependencies include Sphinx itself, a popular theme (sphinx_rtd_theme), notebook integration (nbsphinx), and extensions for automatic documentation generation from type hints (sphinxcontrib-napoleon, sphinx_autodoc_typehints, autodoc). Pandoc is also listed, likely for document conversion. ```Python sphinx>=3 sphinx_rtd_theme nbsphinx sphinxcontrib-napoleon sphinx_autodoc_typehints autodoc pandoc ``` -------------------------------- ### Get Inductor Capacitance for Flux Distribution Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/elements.html Retrieves the effective capacitance value of the inductor based on the specified flux distribution context. It returns the actual capacitance for 'all', a very large capacitance for 'junctions', and a very small capacitance for 'inductors'. ```python def get_cap_for_flux_dist(self, flux_dist): if flux_dist == 'all': return self.cap.get_value() elif flux_dist == "junctions": return VeryLargeCap().get_value() elif flux_dist == "inductors": return VerySmallCap().get_value() ``` -------------------------------- ### Importing SQcircuit and Related Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/kite.html This snippet imports the necessary Python libraries: SQcircuit for circuit simulation, NumPy for numerical operations, and Matplotlib for plotting, which are foundational for the subsequent circuit analysis. ```Python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Importing Libraries for SQcircuit Analysis Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/doctrees/nbsphinx/examples/flux_qubit.ipynb This snippet imports the necessary Python libraries: `SQcircuit` for quantum circuit simulations, `numpy` for numerical operations, and `matplotlib.pyplot` for plotting results. These are fundamental for setting up the simulation environment. ```python # Setup import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Get Isolated Charge Operator Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html This internal method returns the charge operator for a specific isolated mode, normalized by the square root of hbar. An 'isolated' operator is not part of the general tensor product states of the overall system. ```APIDOC SQcircuit.Circuit._charge_op_isolated(self, i: int) -> Qobj Parameters: i (int): Index of the mode (starts from zero for the first mode). Returns: Qobj: The isolated charge operator for the `i`th mode. ``` -------------------------------- ### Define Inductive Loop for Zero-Pi Qubit Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/quick_tutorial.rst For circuits with inductive loops, such as the zero-pi qubit, an inductive loop object must be defined. This example creates a `Loop` object with a flux bias set at its frustration point, which can be adjusted later using the `set_flux()` method. ```python # inductive loop of zero-pi qubit with flux bias at its frustration point. loop1 = sq.Loop(value=0.5) ``` -------------------------------- ### Get and apply first coordinate transformation for diagonalization (Python) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html Calculates and applies the first coordinate transformation (S1, R1) that simultaneously diagonalizes the capacitance and susceptance matrices. It handles cases where there are no inductors in the circuit and adjusts singular locations. ```Python def _get_and_apply_transformation_1(self) -> Tuple[ndarray, ndarray]: """Get and apply the first transformation of the coordinates that simultaneously diagonalizes the capacitance and susceptance matrices. Returns ---------- A tuple of the (S1, R1) matrices. """ cMatRoot = sqrtm(sqf.numpy(self.C)) cMatRootInv = np.linalg.inv(cMatRoot) lMatRoot = sqrtm(sqf.numpy(self.L)) V, D, U = np.linalg.svd(lMatRoot @ cMatRootInv) # the case that there is not any inductor in the circuit if np.max(D) == 0: D = np.diag(np.eye(self.n)) singLoc = list(range(0, self.n)) else: # find the number of singularity in the circuit lEig, _ = np.linalg.eig(sqf.numpy(self.L)) numSing = len(lEig[lEig / np.max(lEig) < ACC["sing_mode_detect"]]) singLoc = list(range(self.n - numSing, self.n)) D[singLoc] = np.max(D) # build S1 and R1 matrix S1 = cMatRootInv @ U.T @ np.diag(np.sqrt(D)) R1 = np.linalg.inv(S1).T self._apply_transformation(S1, R1) self.lTrans[singLoc, singLoc] = 0 return S1, R1 ``` -------------------------------- ### Get Loop Description with Junctions Flux Distribution Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/guides/loop_dist.ipynb This snippet demonstrates configuring an SQcircuit `Circuit` with `flux_dist` set to 'junctions', which is the default behavior. It then retrieves and displays the loop description, illustrating how SQcircuit handles external flux distribution when prioritizing junction capacitors. ```python cr = sq.Circuit(elements, flux_dist="junctions") cr.loop_description() ``` -------------------------------- ### Enable Sphinx Read the Docs Navigation with jQuery Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/index.html This JavaScript snippet initializes the Sphinx Read the Docs theme's navigation functionality, enabling interactive navigation elements on the page. It ensures that the theme's dynamic navigation features are active upon document load. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Initialize Python Environment and Define Physical Constants Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/flux_qubit.ipynb.txt This snippet imports necessary libraries like SQcircuit, NumPy, and Matplotlib, and defines fundamental physical constants (e.g., Planck's constant, electron charge, flux quantum) and circuit parameters (e.g., Josephson energy, charging energy) based on a reference paper. These constants are crucial for subsequent calculations of circuit element values. ```Python # Setup import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` ```Python # Fundamental constants h = 6.626e-34 GHz = 1e9 e0 = 1.602e-19 phi0 = h/(2*e0) phi0_red = phi0/2/np.pi # Circuit parameters in paper's convention EJ = 50.0 * GHz * h EC = 1.0 * GHz * h αQ = 0.63 βQ = 0.15 κQ = 0.00 σQ = 0.00 ``` ```Python # Pre-convert to explicit circuit elements for checking values L_val = βQ*(phi0_red**2/EJ)*(1/(1+κQ) + 1/(1-κQ) + 1/αQ) C1_val = (e0**2/(2*EC))*(1+κQ) C2_val = (e0**2/(2*EC))*(1-κQ) C3_val = (e0**2/(2*EC))*(αQ) JJ1_val = EJ/h*(1+κQ) JJ2_val = EJ/h*(1-κQ) JJ3_val = EJ/h*(αQ) ``` -------------------------------- ### Python: Get SQcircuit Gradient Elements (parameters_elems) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html The `parameters_elems` property returns a list of the actual `Element` or `Loop` objects within the circuit that are set to require gradient computation. This provides direct references to the components whose values are being optimized. ```Python @property def parameters_elems(self) -> List[Union[Element, Loop]]: """The elements in the circuit which require gradient. """ return list(self._parameters.keys()) ``` -------------------------------- ### Python: Get SQcircuit Truncation Numbers (trunc_nums) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html The `trunc_nums` property returns a list of truncation numbers for each mode in the circuit. For harmonic modes, it's `N` (Hilbert space 0 to N-1), and for charge modes, it's `N` (Hilbert space -(N-1) to (N-1)). ```Python @property def trunc_nums(self) -> List[int]: """List of truncation numbers of the circuit. For harmonic modes, these are N where the Hilbert space is 0, 1, …, (N-1) and for charge modes these are N where the Hilbert space is -(N-1), …, 0, …, (N-1). """ trunc_nums = [] for i in range(self.n): if self._is_charge_mode(i): trunc_nums.append(int((self.m[i] + 1)/2)) else: trunc_nums.append(self.m[i]) return trunc_nums ``` -------------------------------- ### Load Search Index for Sphinx Documentation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/search.html This JavaScript snippet is responsible for loading the search index file, typically named 'searchindex.js', into the documentation page. Once loaded, it enables the full-text search functionality, allowing users to efficiently find information across the SQcircuit documentation. This is a crucial component for the search feature to work correctly. ```JavaScript jQuery(function() { Search.loadIndex("searchindex.js"); }); ``` -------------------------------- ### Python: Get SQcircuit Parameter Gradients (parameters_grad) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html The `parameters_grad` property returns the gradients of the tensors managed by the `parameters` property. If all gradients are non-`None`, they are returned as a stacked `Tensor`; otherwise, a list of individual `Optional[Tensor]` values is returned. This requires optimization mode to be active. ```Python @property def parameters_grad(self) -> Union[List[Optional[Tensor]], Tensor]: """Return the gradients of the tensors in ``.parameters``. If all values are not ``None``, it is returned as a stacked ``Tensor``, otherwise as a list of individual values. """ raise_optim_error_if_needed() grad_list = [] for val in self.parameters: grad_list.append(val.grad) if None in grad_list: return grad_list return torch.stack(grad_list).detach().clone() ``` -------------------------------- ### Import SQcircuit and Essential Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/doctrees/nbsphinx/examples/kite.ipynb This snippet imports the necessary Python libraries: `SQcircuit` for circuit simulations, `numpy` for numerical operations, and `matplotlib.pyplot` for plotting. ```Python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Import SQcircuit and Related Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/doctrees/nbsphinx/examples/zeropi_qubit.ipynb Imports necessary Python libraries: `SQcircuit` for circuit simulation, `matplotlib.pyplot` for plotting, and `numpy` for numerical operations. ```Python import SQcircuit as sq import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### Configure Default Units for SQcircuit Elements Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/guides/units.html Illustrates how to set default units for specific element types in SQcircuit, such as capacitors, inductors, and Josephson junctions, using functions like `sq.set_unit_cap()`, `sq.set_unit_ind()`, and `sq.set_unit_JJ()`. The example shows how to define capacitors in the default gigahertz unit and then switch to femtofarads for subsequent capacitor definitions. ```Python # capacitors in GHz default unit C1 = sq.Capacitor(10) C2 = sq.Capacitor(12) sq.set_unit_cap("fF") # capacitors in fF default unit C3 = sq.Capacitor(3) C4 = sq.Capacitor(4) ``` -------------------------------- ### Set Truncation Numbers for Circuit Modes (Python) Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/flux_qubit.html This snippet demonstrates how to set the truncation numbers for each circuit mode using the `set_trunc_nums()` method. This step is crucial for defining the size of the Hilbert space and must be performed before diagonalizing the circuit. The example sets specific truncation numbers for harmonic and charge modes. ```python # Set truncation numbers, desired eigenvalues, and flux sweep n1 = 1 # harmonic [see cr.description()] n2 = 6 # charge [see cr.description()] n3 = 6 # charge [see cr.description()] cr1.set_trunc_nums([n1, n2, n3]) n_eig = 7 n_ext = 300 phi_ext = np.linspace(0.0, 1.0, n_ext) ``` -------------------------------- ### Import SQcircuit and Related Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/examples/zeropi_qubit.ipynb Imports necessary Python libraries for quantum circuit simulation, numerical operations, and plotting. This includes SQcircuit for circuit definition and analysis, Matplotlib for visualization, and NumPy for numerical computations. ```python import SQcircuit as sq import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### SQcircuit.Capacitor Class API Reference Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/apidoc/elements.html Documents the `Capacitor` class, which encapsulates properties of a capacitor. It details the constructor parameters such as value, unit, gradient tracking, quality factor, fabrication error, and an optional ID string. It also includes properties like `value_unit` and `requires_grad`, and methods for setting and getting the capacitor's value. ```APIDOC Class: SQcircuit.Capacitor Bases: Element Description: Class that contains the capacitor properties. Constructor: __init__(_value_, _unit=None_, _requires_grad=False_, _Q='default'_, _error=0_, _id_str=None_) Parameters: value (float): The value of the capacitor. unit (Optional[str]): The unit of input value. If "THz", "GHz", etc., value specifies charging energy. If "fF", "pF", etc., value specifies capacitance in farad. If None, default unit is "GHz". requires_grad (bool): Specifies whether autograd should record operations (PyTorch specific). Q (Union[Any, Callable[[float], float]]): Quality factor of dielectric (one over tangent loss). Can be float or function of angular frequency. error (float): Fabrication error in percentage. id_str (Optional[str]): ID string for the capacitor. Properties: value_unit: 'F' requires_grad: bool Methods: set_value(_v_, _u='F'_, _e=0.0_) Description: Set the value for the capacitor. Parameters: v (float): The value of the element. u (str): The unit of input value. e (float): The fabrication error in percentage. Returns: None get_value(_u='F'_) Description: Return the value of the element in specified unit. Parameters: u (str): The unit of input value. Default is "F". Returns: Union[float, Tensor] ``` -------------------------------- ### Define Circuit Components: Capacitors, Inductors, and Junctions Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/quick_tutorial.rst This section shows how to define individual circuit components using SQcircuit's dedicated classes: `Capacitor`, `Inductor`, and `Junction`. It specifies their values, units (GHz by default), and associates inductive elements with their respective loops. ```python # capacitors C = sq.Capacitor(value =0.15, unit="GHz") CJ = sq.Capacitor(value=10, unit="GHz") # inductors L = sq.Inductor(value=0.13, unit="GHz", loops = [loop1]) # JJs JJ = sq.Junction(value=5, unit="GHz", loops=[loop1]) ``` -------------------------------- ### Display External Flux Distribution for 'all' Elements in SQcircuit Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/guides/loop_dist.ipynb.txt This example shows how to construct a `Circuit` object in SQcircuit with the `flux_dist` option set to `'all'`, which automatically assigns external fluxes to junctions and inductors based on their capacitors. The `loop_description()` method is then used to display the calculated distribution. Since equal capacitors were assigned to all inductive elements, the flux is expected to be equally distributed among them. ```Python cr = sq.Circuit(elements, flux_dist='all') cr.loop_description() ``` -------------------------------- ### API Method: SQcircuit.Circuit.description Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html The `description` method provides a comprehensive printout of the circuit's Hamiltonian, mode characteristics (harmonic or charge), Hamiltonian parameters, and external flux values. It constructs a symbolic Hamiltonian stored in `self.descrip_vars['H']`. The output format can be controlled to be Latex or plain text, suitable for Jupyter notebooks or Python terminals. ```APIDOC SQcircuit.Circuit.description( self, tp: Optional[str] = None, _test: bool = False, ) -> Optional[str]: Description: Print out Hamiltonian and a listing of the modes (whether they are harmonic or charge modes with the frequency for each harmonic mode), Hamiltonian parameters, and external flux values. Constructs a symbolic Hamiltonian, which is stored in `.descrip_vars['H']`. Parameters: tp: Type: Optional[str] Default: None Description: If `None` prints out the output as Latex if SQcircuit is running in a Jupyter notebook and as text if SQcircuit is running in Python terminal. If `tp` is `"ltx"`, the output is in Latex format, and if `tp` is `"txt"` the output is in text format. _test: Type: bool Default: False Description: if True, return the entire description as string text (use only for testing the function). Returns: Type: Optional[str] Description: The text of the description as a string, if `_test` is `True`. ``` -------------------------------- ### Generate SQcircuit Energy Spectrum by Sweeping External Flux Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/zeropi_qubit.ipynb.txt This example illustrates generating the energy spectrum of a superconducting circuit by sweeping an external magnetic flux. It initializes a range of flux values using `numpy.linspace`, then iteratively applies each flux to `loop1` via `set_flux()`. For each flux, the circuit is diagonalized using `zrpi.diag()` to obtain eigenfrequencies, which are stored in a 2D NumPy array `spec`. ```Python # external flux for sweeping over phi = np.linspace(0,1,100) # spectrum of the circuit n_eig=5 spec = np.zeros((n_eig, len(phi))) for i in range(len(phi)): # set the external flux for the loop loop1.set_flux(phi[i]) # diagonlize the circuit spec[:, i], _ = zrpi.diag(n_eig) ``` -------------------------------- ### Enable Sphinx Read the Docs Theme Navigation Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/genindex.html A JavaScript snippet that initializes and enables the navigation functionality provided by the Sphinx Read the Docs theme. It ensures the navigation sidebar is interactive upon document load. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Import SQcircuit and Essential Libraries Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/flux_qubit.html Imports necessary libraries for numerical operations (NumPy), plotting (Matplotlib), and the SQcircuit framework to begin quantum circuit simulations. ```Python import SQcircuit as sq import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Calculate Qubit Frequency from Eigenfrequencies Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/quick_tutorial.rst.txt Obtain the first two eigenfrequencies and eigenvectors of the circuit using the `diag` method. The qubit frequency is then calculated as the difference between these two eigenfrequencies. ```python # get the first two eigenfrequencies and eigenvectors efreqs, evecs = cr.diag(n_eig=2) # print the qubit frequency print("qubit frequency:", efreqs[1]-efreqs[0]) ``` -------------------------------- ### SQcircuit Circuit description Method Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/genindex.html Provides a textual description of the circuit's structure and components. ```APIDOC SQcircuit.Circuit.description() (method) ``` -------------------------------- ### Import Essential Libraries for SQcircuit Analysis Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/zeropi_qubit.html This snippet imports the necessary Python libraries for superconducting circuit analysis: `SQcircuit` for circuit modeling, `matplotlib.pyplot` for data visualization, and `numpy` for numerical operations. ```Python import SQcircuit as sq import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### Displaying Kite Circuit Description and Hamiltonian Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/kite.html This code calls the `description()` method on the `kite` circuit object. This method provides a detailed output including the circuit's Hamiltonian, a list of its modes (harmonic or charge), their frequencies, and prefactors for Josephson junction terms, aiding in understanding the circuit's properties before diagonalization. The output includes the Hamiltonian expression and details for each mode. ```Python kite.description() ``` -------------------------------- ### Display Fluxonium Circuit Hamiltonian and Modes Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/examples/fluxonium.html Calls the `description()` method on the `Circuit` object to print the Hamiltonian, mode types (harmonic/charge), and frequencies, providing insight into the circuit's structure before diagonalization. ```Python cr.description() ``` -------------------------------- ### Calculate Qubit Frequency from Eigenfrequencies Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/quick_tutorial.rst This snippet demonstrates how to obtain the eigenfrequencies and eigenvectors of the circuit using the `diag` method. The qubit frequency is then calculated as the difference between the first two eigenfrequencies, providing a key characteristic of the quantum system. ```python # get the first two eigenfrequencies and eigenvectors efreqs, evecs = cr.diag(n_eig=2) # print the qubit frequency print("qubit frequency:", efreqs[1]-efreqs[0]) ``` -------------------------------- ### SQcircuit.Circuit Class API Reference Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_modules/SQcircuit/circuit.html API documentation for the `Circuit` class in SQcircuit, which is central to building Hamiltonians and performing various analyses on superconducting circuits. It details the class's purpose, initialization parameters, and the attributes it manages. ```APIDOC class Circuit: description: Class that contains circuit properties and builds the Hamiltonian using the theory discussed in the original SQcircuit paper. Provides methods to calculate: - Eigenvalues and eigenvectors - Phase coordinate representation of eigenvectors - Coupling operators - Matrix elements - Decoherence rates - Gradients of Hamiltonian, eigenvalues/vectors , and Decoherence __init__(self, elements: Dict[Tuple[int, int], List[Element]], flux_dist: str = 'junctions') -> None: parameters: elements: A dictionary that contains the circuit's elements at each edge of the circuit. flux_dist: Provide the method of distributing the external fluxes. If "flux_dist" is "all", SQcircuit assign the external fluxes based on the capacitor of each inductive element (This option is necessary for time-dependent external fluxes). If "flux_dist" is "inductor" SQcircuit finds the external flux distribution by assuming the capacitor of the inductors are much smaller than the junction capacitors, If "flux_dist" is "junction" it is the other way around. attributes_initialized: self.elements: OrderedDict of circuit elements. self.flux_dist: Method of distributing external fluxes ("junctions", "inductors", or "all"). self.loops: List of circuit inductive loops. self.n: Number of nodes without ground. self.countJJnoInd: Number of branches containing JJ without parallel inductor. self.elem_keys: Dictionary mapping element types (Inductor, Junction) to their keys. self._parameters: OrderedDict of parameters for optimization. ``` -------------------------------- ### Describing the SQcircuit Hamiltonian and Modes Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/_build/html/_sources/examples/kite.ipynb.txt This snippet calls the `description()` method on the `kite` circuit object. This method provides a detailed overview of the circuit's Hamiltonian, lists its modes (harmonic or charge), their frequencies in GHz, and the prefactors in the Josephson junction part of the Hamiltonian. This information is crucial for understanding the circuit's properties before performing diagonalization. ```python kite.description() ``` -------------------------------- ### Define and Assemble Kite Circuit Components Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/examples/kite.ipynb This snippet defines all the individual components of the Kite circuit, including capacitors, inductors, and Josephson junctions, using `SQcircuit` classes with specified parameters and associated loops. It then organizes these elements into a dictionary representing the circuit's topology and finally instantiates the `sq.Circuit` object, `kite`, which prepares the circuit for diagonalization. ```python C = sq.Capacitor(2.5) CJ = sq.Capacitor(6.6) JJ1 = sq.Junction(5.9, loops =[loop1]) JJ2 = sq.Junction(5.9, loops =[loop1, loop2]) l1 = sq.Inductor(0.36, loops =[loop1]) l2 = sq.Inductor(0.36, loops =[loop1, loop2]) L = sq.Inductor(0.23, loops=[loop2]) elements = { (0, 1): [l1], (0, 2): [l2], (0, 3): [L, C], (1, 3): [JJ1, CJ], (2, 3): [JJ2, CJ] } kite = sq.Circuit(elements) ``` -------------------------------- ### Display Circuit Hamiltonian and Mode Description Source: https://github.com/stanfordlinqs/sqcircuit-doc/blob/main/docs/source/examples/kite.ipynb This code calls the `description()` method on the `kite` circuit object. This method provides detailed insights into the circuit by printing its Hamiltonian, listing the types of modes (harmonic or charge), their frequencies, and the prefactors for the Josephson junction part of the Hamiltonian, aiding in understanding mode decoupling. ```python kite.description() ```