### Setting Qibotn Backend with qutensornet (Python) Source: https://github.com/qiboteam/qibotn/blob/main/doc/source/getting-started/quickstart.rst Configures Qibo to use the `qibotn` backend with the `qutensornet` platform, utilizing the Quimb library for CPU-based tensor network simulations. This setup requires a predefined `runcard` dictionary (e.g., `computation_settings`) to specify simulation options. ```python qibo.set_backend( backend="qibotn", platform="qutensornet", runcard=computation_settings ) ``` -------------------------------- ### Installing QiboTN from Source via Git and Poetry (Shell) Source: https://github.com/qiboteam/qibotn/blob/main/doc/source/getting-started/installation.rst Provides a sequence of shell commands to clone the QiboTN source repository from GitHub, change the current directory to the newly cloned project folder, and install all project dependencies using the Poetry package manager. This requires both Git and Poetry to be installed and accessible in the system's PATH. ```Shell git clone https://github.com/qiboteam/qibotn.git cd qibotn poetry install ``` -------------------------------- ### Executing Basic Qibotn Circuit Simulation (Python) Source: https://github.com/qiboteam/qibotn/blob/main/doc/source/getting-started/quickstart.rst Shows a full example of setting up the `runcard` and `qutensornet` backend, constructing a simple two-qubit circuit with Hadamard gates, executing it, and printing the resulting dense state vector. Demonstrates the basic workflow for circuit simulation with Qibotn and Quimb. ```python import qibo from qibo import Circuit, gates # Set the runcard computation_settings = { "MPI_enabled": False, "MPS_enabled": False, "NCCL_enabled": False, "expectation_enabled": False, } # Set the quimb backend qibo.set_backend( backend="qibotn", platform="qutensornet", runcard=computation_settings ) # Construct the circuit with two qubits c = Circuit(2) # Apply Hadamard gates on first and second qubit c.add(gates.H(0)) c.add(gates.H(1)) # Execute the circuit and obtain the final state result = c() # Print the final state print(result.state()) ``` -------------------------------- ### Installing qibotn for contribution via poetry Source: https://github.com/qiboteam/qibotn/blob/main/README.md Outlines the steps to set up qibotn for development and contribution, involving cloning the repository and installing dependencies using the Poetry tool. ```sh git clone https://github.com/qiboteam/qibotn.git cd qibotn poetry install ``` -------------------------------- ### Setting Qibotn Backend with cutensornet (Python) Source: https://github.com/qiboteam/qibotn/blob/main/doc/source/getting-started/quickstart.rst Configures Qibo to use the `qibotn` backend with the `cutensornet` platform, leveraging the cuQuantum library for GPU-accelerated tensor network simulations. This setup requires a predefined `runcard` dictionary (e.g., `computation_settings`) to specify simulation options. ```python qibo.set_backend( backend="qibotn", platform="cutensornet", runcard=computation_settings ) ``` -------------------------------- ### Installing qibotn via pip Source: https://github.com/qiboteam/qibotn/blob/main/README.md Provides the command to install the qibotn library and its core dependencies using the pip package manager, suitable for users. ```sh pip install qibotn ``` -------------------------------- ### Simulating Large Circuit with Quantum Matcha Tea (Python) Source: https://github.com/qiboteam/qibotn/blob/main/doc/source/getting-started/quickstart.rst Illustrates how to use Qibotn with the `qmatchatea` platform for simulating larger circuits, such as a 40-qubit GHZ state. It demonstrates constructing the backend, customizing device/precision settings, configuring tensor network simulation parameters (like bond dimension), executing the circuit with shots, and printing outcome probabilities and frequencies. ```python # We need Qibo to setup the circuit and the backend from qibo import Circuit, gates from qibo.models.encodings import ghz_state from qibo.backends import construct_backend # We need Quantum Matcha Tea to customize the tensor network simulation from qmatchatea import QCConvergenceParameters # Set the number of qubits nqubits = 40 # Construct a circuit preparing a Quantum Fourier Transform circuit = ghz_state(nqubits) # Construct the backend backend = construct_backend(backend="qibotn", platform="qmatchatea") # Customize the low-level backend preferences according to Qibo's formalism backend.set_device("/CPU:1") backend.set_precision("double") # Customize the tensor network simulation itself backend.configure_tn_simulation( ansatz = "MPS", convergence_params = QCConvergenceParameters(max_bond_dimension=50, cut_ratio=1e-6) ) # Execute the tensor network simulation outcome = backend.execute_circuit( circuit = circuit, nshots=1024, ) # Print some results print(outcome.probabilities()) # Should print something like: {'0000000000000000000000000000000000000000': 0.5000000000000001, '1111111111111111111111111111111111111111': 0.5000000000000001} print(outcome.frequencies()) # Should print something like: {'0000000000000000000000000000000000000000': 488, '1111111111111111111111111111111111111111': 536} ``` -------------------------------- ### Examples of qibotn computation settings configurations Source: https://github.com/qiboteam/qibotn/blob/main/README.md Provides two additional examples of the `computation_settings` dictionary: one configured for computing the expectation value of a specific Pauli string, and another set up for dense vector computation using multi-node execution via MPI. ```py # Expectation computation with specific Pauli String pattern computation_settings = { "MPI_enabled": False, "MPS_enabled": False, "NCCL_enabled": False, "expectation_enabled": { "pauli_string_pattern": "IXZ", }, } # Dense vector computation using multi node through MPI computation_settings = { "MPI_enabled": True, "MPS_enabled": False, "NCCL_enabled": False, "expectation_enabled": False, } ``` -------------------------------- ### Launching a multi-node qibotn job via MPI Source: https://github.com/qiboteam/qibotn/blob/main/README.md Illustrates a command line instruction using `mpirun` to execute a Python script (`test.py`) that uses qibotn in a multi-node environment. The example specifies running on 4 processes distributed across nodes listed in a hostfile. ```sh mpirun -n 4 -hostfile $node_list python test.py ``` -------------------------------- ### Defining Qibotn Runcard Settings (Python) Source: https://github.com/qiboteam/qibotn/blob/main/doc/source/getting-started/quickstart.rst Creates a Python dictionary `computation_settings` to configure Qibotn backend behavior, including enabling/disabling MPI, MPS, NCCL, and expectation value calculations. This dictionary serves as the `runcard` input for `qibo.set_backend` calls. ```python computation_settings = { "MPI_enabled": False, "MPS_enabled": False, "NCCL_enabled": False, "expectation_enabled": { "pauli_string_pattern": "IXZ", }, } ``` -------------------------------- ### Accessing Shot-Based Outcome Properties Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Accesses and prints various results from the `outcome` object after execution with measurement shots. It shows how to get the frequencies obtained from the shots, the calculated probabilities, and the statevector (available because `return_array=True`). ```python # Frequencies and probabilities print(f"Frequencies:\n {outcome.frequencies()}\n") print(f"Probabilities:\n {outcome.probabilities()}\n") print(f"State:\n {outcome.state()}\n") # Only if return_array = True ``` -------------------------------- ### Computing Expectation Value Qibo Default Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Computes the expectation value of the same symbolic Hamiltonian using Qibo's default backend (typically Qibojit). This is done by first simulating the circuit to get the statevector and then using the Hamiltonian's `.expectation()` method on that statevector for comparison. ```python # Try with Qibo (which is by default using the Qibojit backend) hamiltonian = hamiltonians.SymbolicHamiltonian(form) hamiltonian.expectation(circuit().state()) ``` -------------------------------- ### Configuring qibotn backend and executing a Qibo circuit Source: https://github.com/qiboteam/qibotn/blob/main/README.md Demonstrates how to configure Qibo to use the 'qibotn' backend with the 'cutensornet' platform, define computation settings, build a simple quantum circuit with H gates, execute it, and print the resulting state vector. ```py import numpy as np from qibo import Circuit, gates import qibo # Below shows how to set the computation_settings # Note that for MPS_enabled and expectation_enabled parameters the accepted inputs are boolean or a dictionary with the format shown below. # If computation_settings is not specified, the default setting is used in which all booleans will be False. # This will trigger the dense vector computation of the tensornet. computation_settings = { "MPI_enabled": False, "MPS_enabled": { "qr_method": False, "svd_method": { "partition": "UV", "abs_cutoff": 1e-12, }, }, "NCCL_enabled": False, "expectation_enabled": False, } qibo.set_backend( backend="qibotn", platform="cutensornet", runcard=computation_settings ) # cuQuantum # qibo.set_backend(backend="qibotn", platform="qutensornet", runcard=computation_settings) #quimb # Construct the circuit c = Circuit(2) # Add some gates c.add(gates.H(0)) c.add(gates.H(1)) # Execute the circuit and obtain the final state result = c() print(result.state()) ``` -------------------------------- ### Instantiating Parametric Quantum Circuit Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Creates an instance of the parametric quantum circuit using the `build_circuit` function with the previously defined number of qubits and 3 layers. It then visualizes the circuit structure using the `.draw()` method. ```python circuit = build_circuit(nqubits=nqubits, nlayers=3) circuit.draw() ``` -------------------------------- ### Importing Qibo and Libraries Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Imports necessary Python libraries for scientific computing (numpy, scipy) and the Qibo quantum simulation framework. This includes core Qibo modules, gates, hamiltonians, and the function to construct backends. ```python import time import numpy as np from scipy import stats import qibo from qibo import Circuit, gates, hamiltonians from qibo.backends import construct_backend ``` -------------------------------- ### Configuring QiboTN Backend Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Constructs and configures the QiboTN backend specifically targeting the 'qmatchatea' platform. It sets the number of qubits for the simulation domain and initializes the NumPy random seed for reproducible random number generation used later in parameter setting. ```python # construct qibotn backend qmatcha_backend = construct_backend(backend="qibotn", platform="qmatchatea") # set number of qubits nqubits = 4 # set numpy random seed np.random.seed(42) ``` -------------------------------- ### Executing Quantum Circuit Basic Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Executes the quantum circuit using the configured `qmatcha_backend` with default simulation options. The result, containing probabilities or state information based on default settings and the backend's capabilities, is stored in the `outcome` variable, and its attributes are printed. ```python # Simple execution (defaults) outcome = qmatcha_backend.execute_circuit(circuit=circuit) # Print outcome vars(outcome) ``` -------------------------------- ### Executing Circuit with Shots and Parameters Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Executes the circuit again, this time simulating measurements by specifying `nshots=1024`. It also sets `prob_type` to 'E', defines a `prob_threshold`, and requests the statevector via `return_array=True`. The outcome's attributes are then printed. ```python # Execution with a specific probability type # We use here "E", which is cutting some of the components if under a threshold outcome = qmatcha_backend.execute_circuit( circuit=circuit, nshots=1024, prob_type="E", prob_threshold=0.05, return_array=True ) # Print outcome vars(outcome) ``` -------------------------------- ### Preparing Circuit for Expectation Value Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Re-displays the quantum circuit and assigns a new set of random parameters to its gates. This ensures the circuit prepares a different quantum state, for which the expectation value of an observable will be computed next. ```python # We are going to compute the expval of an Hamiltonian # On the state prepared by the following circuit circuit.draw() circuit.set_parameters( np.random.randn(len(circuit.get_parameters())) ) ``` -------------------------------- ### Configuring QMatcha Tea TN Simulation Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Customizes the tensor network simulation settings for the `qmatcha_backend`. It specifies the tensor network `ansatz` as 'MPS', sets the `max_bond_dimension` to 10, and defines a `cut_ratio` of 1e-6 for tensor network approximation during execution. ```python # Customization of the tensor network simulation in the case of qmatchatea # Here we use only some of the possible arguments qmatcha_backend.configure_tn_simulation( ansatz="MPS", max_bond_dimension=10, cut_ratio=1e-6, ) ``` -------------------------------- ### Executing Circuit with Probabilities and State Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Executes the circuit specifying a non-default `prob_type` ('G') and a `prob_threshold` of 0.3 for probability calculation. It also explicitly requests the reconstruction of the final statevector by setting `return_array=True`. The resulting outcome's attributes are printed. ```python # Execution with a specific probability type # We use here "G", which is cutting some of the components if under a threshold # We also retrieve the statevector outcome = qmatcha_backend.execute_circuit( circuit=circuit, prob_type="G", prob_threshold=0.3, return_array=True, ) # Print outcome vars(outcome) ``` -------------------------------- ### Importing Qibo Symbolic Operators Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Imports symbolic representations of Pauli operators (Z and X) from the `qibo.symbols` module. These symbols are used to construct quantum observables or Hamiltonians in a user-friendly way. ```python from qibo.symbols import Z, X ``` -------------------------------- ### Defining Parametric Quantum Circuit Function Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Defines a Python function `build_circuit` that generates a layered parametric quantum circuit. Each layer consists of single-qubit RY and RZ gates on all qubits, followed by entangling CNOT gates between adjacent qubits in a circular pattern. The circuit includes a final measurement layer. ```python def build_circuit(nqubits, nlayers): """Construct a parametric quantum circuit.""" circ = Circuit(nqubits) for _ in range(nlayers): for q in range(nqubits): circ.add(gates.RY(q=q, theta=0.)) circ.add(gates.RZ(q=q, theta=0.)) [circ.add(gates.CNOT(q%nqubits, (q+1)%nqubits) for q in range(nqubits))] circ.add(gates.M(*range(nqubits))) return circ ``` -------------------------------- ### Setting Random Circuit Parameters Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Assigns random numerical values to the parameters of the parametric gates (initially set to 0) within the constructed quantum circuit. The parameters are sampled uniformly from the range [-pi, pi] and assigned to the circuit using `set_parameters`. ```python # Setting random parameters circuit.set_parameters( parameters=np.random.uniform(-np.pi, np.pi, len(circuit.get_parameters())), ) ``` -------------------------------- ### Defining Symbolic Hamiltonian Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Constructs a quantum Hamiltonian using the symbolic operators `Z` and `X`. The Hamiltonian is defined as a linear combination of products of these operators acting on specific qubits. The symbolic form of the created Hamiltonian is then displayed. ```python # We can create a symbolic Hamiltonian form = 0.5 * Z(0) * Z(1) +- 1.5 * X(0) * Z(2) + Z(3) hamiltonian = hamiltonians.SymbolicHamiltonian(form) # Let's show it hamiltonian.form ``` -------------------------------- ### Computing Expectation Value Backend Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Calculates the expectation value of the defined symbolic Hamiltonian with respect to the quantum state prepared by the circuit. This computation is performed using the configured `qmatcha_backend`'s specialized `expectation` method. ```python # And compute its expectation value qmatcha_backend.expectation( circuit=circuit, observable=hamiltonian, ) ``` -------------------------------- ### Accessing Simulation Outcome Properties Python Source: https://github.com/qiboteam/qibotn/blob/main/examples/qmatchatea_intro/qmatchatea_introduction.ipynb Retrieves and prints specific results from the `outcome` object obtained from the circuit execution. It demonstrates how to access the calculated probabilities of the final state and the full statevector, which was requested by setting `return_array=True`. ```python print(f"Probabilities:\n {outcome.probabilities()}\n") print(f"State:\n {outcome.state()}\n") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.