### Install QiboTN from Source Source: https://qibo.science/qibotn/stable/getting-started/installation.html Clone the repository and install dependencies using Poetry. Ensure you have Poetry installed. ```bash git clone https://github.com/qiboteam/qibotn.git cd qibotn poetry install ``` -------------------------------- ### Install Qibo from source Source: https://qibo.science/qibo/stable/getting-started/installation.html Clone the Qibo repository and install from source. This is useful for development. ```bash git clone https://github.com/qiboteam/qibo.git cd qibo pip install . ``` -------------------------------- ### Install qibo-client Source: https://qibo.science/qibo-client/stable/index.html Install the package using pip. ```bash pip install qibo-client ``` -------------------------------- ### Install documentation dependencies Source: https://qibo.science/qibo/stable/developer-guides/contributing.html Install the necessary packages to build the Qibo documentation. ```bash pip install qibo[docs] ``` -------------------------------- ### Install Qibolab from Source (Poetry) Source: https://qibo.science/qibolab/stable/getting-started/installation.html Recommended method for installing Qibolab from source when modifications to the source code are required. Requires Poetry to be installed. ```bash poetry install ``` -------------------------------- ### Install qibojit from source Source: https://qibo.science/qibo/stable/getting-started/installation.html Clone the qibojit repository and install from source. This is useful for development. ```bash git clone https://github.com/qiboteam/qibojit.git cd qibojit pip install . ``` -------------------------------- ### Install qiboopt from source Source: https://qibo.science/qiboopt/stable/getting-started/installation.html Method for installing the latest development version directly from the GitHub repository. ```bash git clone https://github.com/qiboteam/qiboopt cd qiboopt pip install . ``` -------------------------------- ### Install documentation dependencies Source: https://qibo.science/qibochem/stable/developer-guides/contributing.html Install the necessary packages to build the project documentation. ```bash pip install qibochem[docs] ``` -------------------------------- ### Install Qibosoq from source Source: https://qibo.science/qibosoq/stable/getting-started/installation.html Commands for installing in normal or developer mode using pip or poetry. ```bash pip install . # normal mode poetry install # developer mode ``` -------------------------------- ### Install qiboopt via pip Source: https://qibo.science/qiboopt/stable/getting-started/installation.html Standard installation method for the package and its dependencies. ```bash pip install qiboopt ``` -------------------------------- ### Install qibo-cloud-backends package Source: https://qibo.science/qibo-cloud-backends/stable/index.html Install the qibo-cloud-backends package using pip. ```bash pip install qibo-cloud-backends ``` -------------------------------- ### Install Qiboml from Source Source: https://qibo.science/qiboml/stable/getting_started/installation.html Install Qiboml directly from its GitHub repository for development or the latest version. This method allows for installing extra dependencies. ```bash git clone https://github.com/qiboteam/qiboml.git cd qiboml pip install -e . ``` ```bash pip install -e .[torch,keras] ``` -------------------------------- ### Install Qibo with Dependencies Source: https://qibo.science/qibo/stable/getting-started/installation.html Installation commands for setting up Qibo with either TensorFlow or PyTorch support. ```bash pip install qibo qiboml tensorflow ``` ```bash pip install qibo qiboml torch ``` -------------------------------- ### Install Qibosoq from source with sudo Source: https://qibo.science/qibosoq/stable/getting-started/installation.html Commands for installing from source on board requiring sudo privileges. ```bash sudo -E python -m pip install # normal mode sudo -E python -m poetry install # developer mode ``` -------------------------------- ### Install Qibosoq via pip Source: https://qibo.science/qibosoq/stable/getting-started/installation.html Standard installation command for the Qibosoq package. ```bash pip install qibosoq ``` -------------------------------- ### Initialize and Start TCPServer Source: https://qibo.science/qibosoq/stable/_modules/qibosoq/server.html Configures the QickSoc object and starts the TCP server to listen for incoming connections. ```python def serve(host, port): """Open the TCPServer and wait forever for connections.""" # initialize QickSoc object (firmware and clocks) TCPServer.allow_reuse_address = True with TCPServer((host, port), ConnectionHandler) as server: server.qick_soc = QickSoc(bitfile=cfg.QICKSOC_LOCATION) log_initial_info() server.serve_forever() ``` -------------------------------- ### Install Qiboml and dependencies Source: https://qibo.science/qiboml/stable/tutorials/binary_mnist.html Install the required packages including qiboml, torch, torchvision, torchmetrics, and matplotlib. ```bash # %%capture # qiboml, provides the means to build the quantum model # !pip install git+https://github.com/qiboteam/qiboml; # torch, handles the creation of all the classical layers # and provides the optimizer # !pip install torch; # some additional requirements to run this notebook # torchvision to gather the MNIST dataset # torchmetrics to evaluate the performance # matplotlib to do some plotting # !pip install torchvision torchmetrics matplotlib; ``` -------------------------------- ### TSP Class Initialization and QAOA Example Source: https://qibo.science/qiboopt/stable/api-reference/combinatorial.html Demonstrates how to initialize the TSP class and use it with QAOA to find an optimal route. Requires numpy and qibo libraries. The example includes helper functions for converting configurations and evaluating distances. ```python from qiboopt.combinatorial.combinatorial import TSP import numpy as np from collections import defaultdict from qibo import Circuit, gates from qibo.models import QAOA from qibo.result import CircuitResult def convert_to_standard_Cauchy(config): m = int(np.sqrt(len(config))) cauchy = [-1] * m # Cauchy's notation for permutation, e.g. (1,2,0) or (2,0,1) for i in range(m): for j in range(m): if config[m * i + j] == '1': cauchy[j] = i # citi i is in slot j for i in range(m): if cauchy[i] == 0: cauchy = cauchy[i:] + cauchy[:i] return tuple(cauchy) # now, the cauchy notation for permutation begins with 0 def evaluate_dist(cauchy): ''' Given a permutation of 0 to n-1, we compute the distance of the tour ''' m = len(cauchy) return sum(distance_matrix[cauchy[i]][cauchy[(i+1)%m]] for i in range(m)) def qaoa_function_of_layer(layer, distance_matrix): ''' This is a function to study the impact of the number of layers on QAOA, it takes in the number of layers and compute the distance of the mode of the histogram obtained from QAOA ''' small_tsp = TSP(distance_matrix) obj_hamil, mixer = small_tsp.hamiltonians() qaoa = QAOA(obj_hamil, mixer=mixer) best_energy, final_parameters, extra = qaoa.minimize(initial_p=[0.1] * layer, initial_state=initial_state, method='BFGS') qaoa.set_parameters(final_parameters) quantum_state = qaoa.execute(initial_state) circuit = Circuit(9) circuit.add(gates.M(*range(9))) result = CircuitResult(quantum_state, circuit.measurements, small_tsp.backend, nshots=1000) freq_counter = result.frequencies() # let's combine freq_counter here, first convert each key and sum up the frequency cauchy_dict = defaultdict(int) for freq_key in freq_counter: standard_cauchy_key = convert_to_standard_Cauchy(freq_key) cauchy_dict[standard_cauchy_key] += freq_counter[freq_key] max_key = max(cauchy_dict, key=cauchy_dict.get) return evaluate_dist(max_key) np.random.seed(42) num_cities = 3 distance_matrix = np.array([[0, 0.9, 0.8], [0.4, 0, 0.1],[0, 0.7, 0]]) distance_matrix = distance_matrix.round(1) small_tsp = TSP(distance_matrix) initial_parameters = np.random.uniform(0, 1, 2) initial_state = small_tsp.prepare_initial_state([i for i in range(num_cities)]) qaoa_function_of_layer(2, distance_matrix) ``` -------------------------------- ### Bluefors Temperature Controller Example Source: https://qibo.science/qibolab/stable/api-reference/qibolab.instruments.html Demonstrates how to connect to and read temperature data from a Bluefors temperature controller. Ensure the IP address and port are correct for your setup. ```python if __name__ == "__main__": from qibolab.instruments.bluefors import TemperatureController tc = TemperatureController("XLD1000_Temperature_Controller", "192.168.0.114", 8888) tc.connect() temperature_values = tc.read_data() for temperature_value in temperature_values: print(temperature_value) ``` -------------------------------- ### Create Dummy Hardware and Platform Source: https://qibo.science/qibolab/stable/_modules/qibolab/_core/dummy/platform.html Initializes a dummy hardware setup with simulated qubits, couplers, and instruments, then loads a platform instance. ```python import pathlib from qibolab._core.components import AcquisitionChannel, DcChannel, IqChannel from qibolab._core.instruments.dummy import DummyInstrument, DummyLocalOscillator from qibolab._core.parameters import Hardware from qibolab._core.platform import Platform from qibolab._core.qubits import Qubit FOLDER = pathlib.Path(__file__).parent def create_dummy_hardware() -> Hardware: """Create dummy hardware configuration based on the dummy instrument.""" qubits = {} channels = {} # attach the channels pump_name = "twpa_pump" for q in range(5): drive12 = f"{q}/drive12" qubits[q] = qubit = Qubit.default(q, drive_extra={(1, 2): drive12}) channels |= { qubit.probe: IqChannel(mixer=None, lo=None), qubit.acquisition: AcquisitionChannel( twpa_pump=pump_name, probe=qubit.probe ), qubit.drive: IqChannel(mixer=None, lo=None), drive12: IqChannel(mixer=None, lo=None), qubit.flux: DcChannel(), } couplers = {} for c in (0, 1, 3, 4): couplers[c] = coupler = Qubit(flux=f"coupler_{c}/flux") channels |= {coupler.flux: DcChannel()} # register the instruments instruments = { "dummy": DummyInstrument(address="0.0.0.0", channels=channels), pump_name: DummyLocalOscillator(address="0.0.0.0"), } return Hardware(instruments=instruments, qubits=qubits, couplers=couplers) [docs] def create_dummy() -> Platform: """Create a dummy platform using the dummy instrument.""" hardware = create_dummy_hardware() return Platform.load(path=FOLDER, **vars(hardware)) ``` -------------------------------- ### POST /setup Source: https://qibo.science/qibocal/stable/_modules/qibocal/protocols/randomized_benchmarking/utils.html Sets up the randomized benchmarking experiment backend and initializes the appropriate data class based on experiment parameters. ```APIDOC ## POST /setup ### Description Initializes the experiment backend and data structure for randomized benchmarking. ### Method POST ### Endpoint /setup ### Parameters #### Request Body - **params** (Parameters) - Required - The parameters for the experiment. - **platform** (CalibrationPlatform) - Required - The calibration platform instance. - **single_qubit** (bool) - Optional - Flag indicating whether the experiment is for a single qubit or two qubits. Defaults to True. - **interleave** (str) - Optional - The type of interleaving to apply. Defaults to None. ### Response #### Success Response (200) - **data** (RBData/RB2QData/RB2QInterData) - The initialized experiment data object. - **backend** (object) - The configured experiment backend. ``` -------------------------------- ### Build and Test UCCD Ansatz with H2 Molecule Source: https://qibo.science/qibochem/stable/getting-started/quickstart.html Example of building the UCCD ansatz with the H2 molecule to test installation. Requires PySCF for integral calculations. The VQE is initialized with random parameters. ```python import numpy as np from qibo.models import VQE from qibochem.driver import Molecule from qibochem.ansatz import hf_circuit, ucc_circuit # Define the H2 molecule and obtain its 1-/2- electron integrals with PySCF h2 = Molecule([('H', (0.0, 0.0, 0.0)), ('H', (0.0, 0.0, 0.7))]) h2.run_pyscf() # Generate the molecular Hamiltonian hamiltonian = h2.hamiltonian() # Build a UCC circuit ansatz for running VQE circuit = hf_circuit(h2.nso, h2.nelec) circuit += ucc_circuit(h2.nso, [0, 1, 2, 3]) # Create and run the VQE, starting with random initial parameters vqe = VQE(circuit, hamiltonian) initial_parameters = np.random.uniform(0.0, 2*np.pi, 8) best, params, extra = vqe.minimize(initial_parameters) ``` -------------------------------- ### Install qibojit with pip Source: https://qibo.science/qibo/stable/getting-started/installation.html Install the qibojit package using pip. Note that cupy and cuQuantum for GPU acceleration are not installed by default and must be installed separately. ```bash pip install qibojit ``` -------------------------------- ### Set up virtual environment and activate Source: https://qibo.science/qibo-cloud-backends/stable/index.html Use these commands to create and activate a virtual environment for package installation. ```bash python -m venv ./env source activate ./env/bin/activate ``` -------------------------------- ### Install Qiboml with Pip Source: https://qibo.science/qiboml/stable/getting_started/installation.html Use this command for the recommended installation of Qiboml. Note that base installation does not include torch or tensorflow. ```bash pip install qiboml ``` -------------------------------- ### Set up virtual environment Source: https://qibo.science/qibo-client/stable/index.html Create and activate a fresh virtual environment to prevent dependency conflicts. ```bash $ python -m venv ./env source activate ./env/bin/activate ``` -------------------------------- ### Initialize Execution Path Source: https://qibo.science/qibocal/stable/_modules/qibocal/auto/execute.html Sets up the output directory, generates metadata, and initializes the platform connection. ```python path = Output.mkdir(Path(path), force) # generate meta meta = Metadata.generate(path.name, backend) output = Output(History(), meta, platform) output.dump(path) # run meta.start() # connect and initialize platform platform.connect() self.path = path self.meta = meta ``` -------------------------------- ### Install Qibo with pip Source: https://qibo.science/qibo/stable/getting-started/installation.html Use this command to install the base Qibo package with pip. Ensure Python 3.9 or greater is installed. ```bash pip install qibo ``` -------------------------------- ### Initialize Backend and Circuit Source: https://qibo.science/qiboml/stable/advanced/calibrator.html Sets up the Qibolab backend, transpiler, and a variational quantum circuit. ```python set_backend(backend = "qibolab", platform = "mock") transpiler = get_transpiler() nqubits = 2 epochs = 3 wire_names=[i for i in range(nqubits)] vqe_circ = Circuit(2,) vqe_circ.add(gates.RX(0, 3*np.pi/4, trainable=True)) vqe_circ.add(gates.RX(1, np.pi/4, trainable=True)) vqe_circ.add(gates.CZ(0,1)) ``` -------------------------------- ### setup_backend_specifics Source: https://qibo.science/qibotn/stable/api-reference/qibotn.backends.html Sets up specific backend configurations for the Quimb simulation. ```APIDOC ## setup_backend_specifics ### Description Sets up the backend specifics for the quimb tensor network simulation. ### Parameters - **qimb_backend** (str) - Optional - The backend to use for the quimb tensor network simulation. Default is 'numpy'. ``` -------------------------------- ### Install Qibochem from Source Source: https://qibo.science/qibochem/stable/getting-started/installation.html Installs the latest development version of Qibochem directly from its Github repository. This involves cloning the repository and then installing it using pip. ```bash git clone https://github.com/qiboteam/qibochem.git cd qibochem pip install . ``` -------------------------------- ### Install Qibocal from source using Poetry Source: https://qibo.science/qibocal/stable/getting-started/installation.html Clone the Qibocal repository and install it using Poetry. This is an alternative to pip for managing dependencies and installations from source. ```bash git clone https://github.com/qiboteam/qibocal.git cd qibocal poetry install ``` -------------------------------- ### Build documentation locally Source: https://qibo.science/qibo/stable/developer-guides/contributing.html Navigate to the documentation directory and generate the HTML files. ```bash cd doc make html ``` -------------------------------- ### Initialize and Run AAVQE Source: https://qibo.science/qibo/stable/_modules/qibo/models/variational.html Demonstrates how to set up the AAVQE model with a circuit ansatz, Hamiltonians, and a scheduling function, then minimize the energy. ```python import numpy as np from qibo import Circuit, gates from qibo.hamiltonians import X, XXZ from qibo.models import AAVQE # create circuit ansatz for two qubits circuit = Circuit(2) circuit.add(gates.RY(0, theta=0)) circuit.add(gates.RY(1, theta=0)) # define the easy and the problem Hamiltonians. easy_hamiltonian = X(2) problem_hamiltonian = XXZ(2) # define a scheduling function with only one parameter # and boundary conditions s(0) = 0, s(1) = 1 s = lambda t: t # create AAVQE model aavqe = AAVQE( circuit, easy_hamiltonian, problem_hamiltonian, s, nsteps=10, t_max=1 ) # optimize using random initial variational parameters np.random.seed(0) initial_parameters = np.random.uniform(0, 2*np.pi, 2) ground_energy, params = aavqe.minimize(initial_parameters) ``` -------------------------------- ### Initialize Qibo Circuits Source: https://qibo.science/qibo/stable/_modules/qibo/models/circuit.html Demonstrates various ways to initialize a circuit using qubit counts and wire names. ```python from qibo import Circuit circuit = Circuit(3) circuit = Circuit(3, wire_names=["q0", "q1", "q2"]) circuit = Circuit(["q0", "q1", "q2"]) circuit = Circuit(wire_names=["q0", "q1", "q2"]) ``` -------------------------------- ### Install Qibochem Source: https://qibo.science/qibochem/stable/getting-started/quickstart.html Install Qibochem using pip. Ensure you have Python 3.9 or higher. ```bash pip install qibochem ``` -------------------------------- ### POST /protocols/randomized_benchmarking/setup Source: https://qibo.science/qibocal/stable/api-reference/qibocal.protocols.randomized_benchmarking.html Sets up the randomized benchmarking experiment backend and initializes the data structure. ```APIDOC ## POST /protocols/randomized_benchmarking/setup ### Description Initializes the randomized benchmarking experiment, configuring the backend and data structures based on the provided parameters. ### Method POST ### Endpoint /protocols/randomized_benchmarking/setup ### Parameters #### Request Body - **params** (Parameters) - Required - The parameters for the experiment. - **platform** (CalibrationPlatform) - Required - The calibration platform instance. - **single_qubit** (bool) - Optional - Flag indicating if the experiment is for a single qubit. Defaults to True. - **interleave** (str) - Optional - The type of interleaving to apply. Defaults to None. ### Response #### Success Response (200) - **data** (tuple) - A tuple containing the experiment data and backend. ``` -------------------------------- ### Create Dummy Platform and Execute Sequence Source: https://qibo.science/qibolab/stable/api-reference/qibolab.html Demonstrates creating a dummy Qibo platform, defining a pulse sequence, and executing it with a sweeper. Ensure numpy and qibolab are imported. ```python import numpy as np from qibolab import Parameter, PulseSequence, Sweeper from qibolab.instruments.dummy import create_dummy platform = create_dummy() qubit = platform.qubits[0] natives = platform.natives.single_qubit[0] sequence = natives.MZ.create_sequence() parameter_range = np.random.randint(10, size=10) sweeper = Sweeper( parameter=Parameter.frequency, values=parameter_range, channels=[qubit.probe] ) platform.execute([sequence], [[sweeper]]) ``` -------------------------------- ### Initialize execution environment Source: https://qibo.science/qibocal/stable/_modules/qibocal/auto/execute.html Sets up the calibration platform and backend for the executor. ```python def init( self, path: os.PathLike, force: bool = False, platform: Union[CalibrationPlatform, str, None] = None, update: Optional[bool] = None, targets: Optional[Targets] = None, ): """Initialize execution.""" if platform is None or isinstance(platform, CalibrationPlatform): platform = self.platform elif isinstance(platform, str): platform = self.platform = create_calibration_platform(platform) else: platform = self.platform = CalibrationPlatform.from_platform(platform) assert isinstance(platform, CalibrationPlatform) backend = construct_backend(backend="qibolab", platform=platform) if update is not None: self.update = update if targets is not None: self.targets = targets # generate output folder ``` -------------------------------- ### Initialize FALQON model Source: https://qibo.science/qibo/stable/_modules/qibo/models/variational.html Shows how to instantiate a FALQON model with a specific Hamiltonian. ```python import numpy as np from qibo.hamiltonians import XXZ from qibo.models import FALQON # create XXZ Hamiltonian for four qubits hamiltonian = XXZ(4) # create FALQON model for this Hamiltonian falqon = FALQON(hamiltonian) # optimize using random initial variational parameters ``` -------------------------------- ### Install Qibo via conda Source: https://qibo.science/qibo/stable/getting-started/quickstart.html Use this command to install Qibo using the conda-forge channel. ```bash conda install -c conda-forge qibo ``` -------------------------------- ### Initialize and manipulate QUBO instances Source: https://qibo.science/qiboopt/stable/api-reference/opt_class.html Demonstrates creating a QUBO instance, scaling it, and adding multiple instances together. ```python from qiboopt.opt_class.opt_class import QUBO Qdict1 = {(0, 0): 1.0, (0, 1): 0.5, (1, 1): -1.0} qp1 = QUBO(0, Qdict1) print(qp1.Qdict) ``` ```python qp1 *= 2 print(qp1.Qdict) ``` ```python Qdict2 = {(0, 0): 2.0, (1, 1): 1.0} qp2 = QUBO(1, Qdict2) qp3 = qp1 + qp2 print(qp3.Qdict) ``` ```python print(qp3.offset) ``` ```python h = {3: 1.0, 4: 0.82, 5: 0.23} J = {(0, 0): 1.0, (0, 1): 0.5, (1, 1): -1.0} qp = QUBO(0, h, J) print(qp.Qdict) ``` -------------------------------- ### Install Qibo via pip Source: https://qibo.science/ Use this command to install the Qibo package in your Python environment. ```bash pip install qibo ``` -------------------------------- ### Initialize QAOA Model Source: https://qibo.science/qibo/stable/_modules/qibo/models/variational.html Example usage for creating and optimizing a QAOA model. ```python import numpy as np from qibo.hamiltonians import XXZ from qibo.models import QAOA # create XXZ Hamiltonian for four qubits hamiltonian = XXZ(4) # create QAOA model for this Hamiltonian qaoa = QAOA(hamiltonian) # optimize using random initial variational parameters # and default options and initial state initial_parameters = 0.01 * np.random.random(4) best_energy, final_parameters, extra = qaoa.minimize(initial_parameters, method="BFGS") ``` -------------------------------- ### Install Qibosoq via pip with sudo Source: https://qibo.science/qibosoq/stable/getting-started/installation.html Required installation command when running on board with sudo privileges. ```bash sudo -i python -m pip install qibosoq ``` -------------------------------- ### POST /init Source: https://qibo.science/qibocal/stable/_modules/qibocal/auto/execute.html Initializes the execution environment with a specified platform and configuration. ```APIDOC ## POST /init ### Description Initializes the execution environment, setting up the backend and platform configuration. ### Method POST ### Endpoint /init ### Parameters #### Request Body - **path** (os.PathLike) - Required - The path for execution output. - **force** (bool) - Optional - Force initialization. - **platform** (Union[CalibrationPlatform, str, None]) - Optional - The calibration platform or name. - **update** (bool) - Optional - Whether to update settings. - **targets** (Targets) - Optional - Specific targets for execution. ``` -------------------------------- ### Initialize the dummy platform Source: https://qibo.science/qibolab/stable/tutorials/instrument.html Use this to create a platform instance that returns random numbers instead of interacting with physical hardware. ```python from qibolab import create_platform platform = create_platform("dummy") ``` -------------------------------- ### Install Qibocal using pip Source: https://qibo.science/qibocal/stable/getting-started/installation.html Use this command to install Qibocal with pip. Ensure your pip is up-to-date. ```bash pip install qibocal ``` -------------------------------- ### Initialize a Circuit and Add Gates Source: https://qibo.science/qibo/stable/api-reference/qibo.html Example of initializing a Qibo circuit and preparing to add gates. ```python from qibo import Circuit, gates circuit = Circuit(4) # Add some CNOT gates ``` -------------------------------- ### TSP Example Usage Source: https://qibo.science/qiboopt/stable/api-reference/combinatorial.html Example demonstrating how to use the TSP class with QAOA to find an optimal route. ```APIDOC ## TSP Example Usage ### Description This example demonstrates how to set up and solve the Travelling Salesman Problem using the `TSP` class and the QAOA algorithm from Qibo. It includes helper functions for converting configurations, evaluating tour distances, and studying the impact of QAOA layers. ### Code Example ```python from qiboopt.combinatorial.combinatorial import TSP import numpy as np from collections import defaultdict from qibo import Circuit, gates from qibo.models import QAOA from qibo.result import CircuitResult def convert_to_standard_Cauchy(config): m = int(np.sqrt(len(config))) cauchy = [-1] * m # Cauchy's notation for permutation, e.g. (1,2,0) or (2,0,1) for i in range(m): for j in range(m): if config[m * i + j] == '1': cauchy[j] = i # citi i is in slot j for i in range(m): if cauchy[i] == 0: cauchy = cauchy[i:] + cauchy[:i] return tuple(cauchy) # now, the cauchy notation for permutation begins with 0 def evaluate_dist(cauchy): ''' Given a permutation of 0 to n-1, we compute the distance of the tour ''' m = len(cauchy) return sum(distance_matrix[cauchy[i]][cauchy[(i+1)%m]] for i in range(m)) def qaoa_function_of_layer(layer, distance_matrix): ''' This is a function to study the impact of the number of layers on QAOA, it takes in the number of layers and compute the distance of the mode of the histogram obtained from QAOA ''' small_tsp = TSP(distance_matrix) obj_hamil, mixer = small_tsp.hamiltonians() qaoa = QAOA(obj_hamil, mixer=mixer) best_energy, final_parameters, extra = qaoa.minimize(initial_p=[0.1] * layer, initial_state=initial_state, method='BFGS') qaoa.set_parameters(final_parameters) quantum_state = qaoa.execute(initial_state) circuit = Circuit(9) circuit.add(gates.M(*range(9))) result = CircuitResult(quantum_state, circuit.measurements, small_tsp.backend, nshots=1000) freq_counter = result.frequencies() # let's combine freq_counter here, first convert each key and sum up the frequency cauchy_dict = defaultdict(int) for freq_key in freq_counter: standard_cauchy_key = convert_to_standard_Cauchy(freq_key) cauchy_dict[standard_cauchy_key] += freq_counter[freq_key] max_key = max(cauchy_dict, key=cauchy_dict.get) return evaluate_dist(max_key) np.random.seed(42) num_cities = 3 distance_matrix = np.array([[0, 0.9, 0.8], [0.4, 0, 0.1],[0, 0.7, 0]]) distance_matrix = distance_matrix.round(1) small_tsp = TSP(distance_matrix) initial_parameters = np.random.uniform(0, 1, 2) initial_state = small_tsp.prepare_initial_state([i for i in range(num_cities)]) qaoa_function_of_layer(2, distance_matrix) ``` ### Reference 1. S. Hadfield, Z. Wang, B. O’Gorman, E. G. Rieffel, D. Venturelli, R. Biswas, _From the Quantum Approximate Optimization Algorithm to a Quantum Alternating Operator Ansatz_. (arxiv:1709.03489) ``` -------------------------------- ### Install Qibolab with Pip Source: https://qibo.science/qibolab/stable/getting-started/installation.html Use this command to install the latest stable version of Qibolab. Ensure your pip is up-to-date. ```bash pip install qibolab ``` -------------------------------- ### Configure Platform Source: https://qibo.science/qibolab/stable/tutorials/emulator.html Create a platform instance using validated parameters and external configuration. ```python from qibolab import Parameters, Platform params = Parameters.model_validate(parameters) platform = Platform(name="my_platform", parameters=params, **vars(create())) ``` -------------------------------- ### CNOT Gate Example Source: https://qibo.science/qibo/stable/api-reference/qibo.html Example demonstrating the usage of the CNOT gate and its `on_qubits` method for targeting different qubits. ```APIDOC ## Example Usage of CNOT Gate ```python from qibo import Circuit, gates circuit = Circuit(4) # Add some CNOT gates # equivalent to gates.CNOT(2, 3) circuit.add(gates.CNOT(2, 3).on_qubits({2: 2, 3: 3})) # equivalent to gates.CNOT(3, 0) circuit.add(gates.CNOT(2, 3).on_qubits({2: 3, 3: 0})) # equivalent to gates.CNOT(1, 3) circuit.add(gates.CNOT(2, 3).on_qubits({2: 1, 3: 3})) # equivalent to gates.CNOT(2, 1) circuit.add(gates.CNOT(2, 3).on_qubits({2: 2, 3: 1})) circuit.draw() ``` ``` 0: ───X───── 1: ───|─o─X─ 2: ─o─|─|─o─ 3: ─X─o─X─── ``` ``` -------------------------------- ### Single Shot Classification Parameters Example Source: https://qibo.science/qibocal/stable/protocols/singleshot.html Example configuration for single-shot classification, specifying the operation, number of shots, and a list of classifiers. ```yaml - id: single shot classification operation: single_shot_classification parameters: nshots: 5000 classifiers_list: ["qubit_fit", "naive_bayes"] ``` -------------------------------- ### Execute Pulse Sequences on Platform Source: https://qibo.science/qibolab/stable/_modules/qibolab/_core/platform/platform.html Demonstrates how to initialize a dummy platform, define a pulse sequence, and execute it with a frequency sweeper. ```python import numpy as np from qibolab import Parameter, PulseSequence, Sweeper from qibolab.instruments.dummy import create_dummy platform = create_dummy() qubit = platform.qubits[0] natives = platform.natives.single_qubit[0] sequence = natives.MZ.create_sequence() parameter_range = np.random.randint(10, size=10) sweeper = [ Sweeper( parameter=Parameter.frequency, values=parameter_range, channels=[qubit.probe], ) ] platform.execute([sequence], [sweeper]) ``` -------------------------------- ### Install Qibolab from Source (Pip) Source: https://qibo.science/qibolab/stable/getting-started/installation.html Install Qibolab using pip after cloning the repository. This method is suitable if no source code modifications are needed. ```bash pip install . ``` -------------------------------- ### Initialize Qibolab Platform and Experiment Parameters Source: https://qibo.science/qibosoq/stable/getting-started/qibosoq_lab_cal.html Imports necessary Qibolab modules and initializes the platform with a specified runcard, setting up acquisition and averaging modes. ```python from qibolab import create_platform from qibolab import AcquisitionType, AveragingMode, ExecutionParameters from qibolab.pulses import ( DrivePulse, ReadoutPulse, PulseSequence, ) # Define platform and load specific runcard platform = create_platform("my_platform") ``` -------------------------------- ### Install Qibolab from Source (Editable Pip) Source: https://qibo.science/qibolab/stable/getting-started/installation.html An alternative, not recommended, method for installing Qibolab from source with editable mode using pip. Useful for development. ```bash pip install -e . ``` -------------------------------- ### POST /create_calibration_platform Source: https://qibo.science/qibocal/stable/genindex.html Initializes a new calibration platform instance for quantum hardware control. ```APIDOC ## POST /create_calibration_platform ### Description Creates and returns a new calibration platform instance used for managing quantum hardware calibration. ### Method POST ### Endpoint /create_calibration_platform ### Response #### Success Response (200) - **platform** (Object) - The initialized CalibrationPlatform instance. ``` -------------------------------- ### Install Qibocal from source using pip Source: https://qibo.science/qibocal/stable/getting-started/installation.html Clone the Qibocal repository and install it from source using pip. This method is useful for development or when needing the latest changes. ```bash git clone https://github.com/qiboteam/qibocal.git cd qibocal pip install . ```