{ "cells": [ { "cell_type": "markdown", "id": "intro", "metadata": {}, "source": [ "# Quick start\n", "\n", "This guide demonstrates a minimal working example of the `qiskit-addon-aqc-tensor` package. We use AQC-Tensor to compress a deep Trotter circuit into a shallower parametrized ansatz that approximates the same time-evolved state. To see examples of how to build realistic workflows with this tool and execute on quantum hardware, check out the tutorials on the IBM Quantum Platform ([Tutorial 1](https://quantum.cloud.ibm.com/docs/en/tutorials/reducing-circuit-depth-with-aqc))." ] }, { "cell_type": "markdown", "id": "inputs-header", "metadata": {}, "source": [ "## Prepare inputs for AQC-Tensor\n", "\n", "AQC-Tensor takes as input a deep target circuit (simulated as a tensor network) and a shallower circuit from which to derive the ansatz structure.\n", "\n", "We define a 10-site Ising Hamiltonian and generate both circuits from it." ] }, { "cell_type": "code", "execution_count": null, "id": "setup-inputs", "metadata": {}, "outputs": [], "source": [ "from qiskit.synthesis import SuzukiTrotter\n", "from qiskit.transpiler import CouplingMap\n", "from qiskit_addon_utils.problem_generators import (\n", " generate_time_evolution_circuit,\n", " generate_xyz_hamiltonian,\n", ")\n", "\n", "coupling_map = CouplingMap.from_heavy_hex(3, bidirectional=False)\n", "reduced_coupling_map = coupling_map.reduce([0, 13, 1, 14, 10, 16, 4, 15, 3, 9])\n", "\n", "hamiltonian = generate_xyz_hamiltonian(\n", " reduced_coupling_map,\n", " coupling_constants=(0.0, 0.0, 1.0),\n", " ext_magnetic_field=(0.4, 0.0, 0.0),\n", ")\n", "\n", "evolution_time = 4.0\n", "\n", "# Deep target circuit (many Trotter steps)\n", "target_circuit = generate_time_evolution_circuit(\n", " hamiltonian,\n", " synthesis=SuzukiTrotter(reps=45),\n", " time=evolution_time,\n", ")\n", "\n", "# Shallow circuit (fewer Trotter steps) to define ansatz structure\n", "good_circuit = generate_time_evolution_circuit(\n", " hamiltonian,\n", " synthesis=SuzukiTrotter(reps=5),\n", " time=evolution_time,\n", ")" ] }, { "cell_type": "markdown", "id": "aqc-header", "metadata": {}, "source": [ "## Compress with AQC-Tensor\n", "\n", "We simulate the target circuit as a matrix-product state (MPS), generate a parametrized ansatz from the shallow circuit, and optimize its parameters to maximize fidelity with the target state." ] }, { "cell_type": "code", "execution_count": null, "id": "run-aqc", "metadata": {}, "outputs": [], "source": [ "from functools import partial\n", "\n", "import quimb.tensor\n", "from scipy.optimize import minimize\n", "\n", "from qiskit_addon_aqc_tensor import generate_ansatz_from_circuit\n", "from qiskit_addon_aqc_tensor.objective import MaximizeStateFidelity\n", "from qiskit_addon_aqc_tensor.simulation import tensornetwork_from_circuit\n", "from qiskit_addon_aqc_tensor.simulation.quimb import QuimbSimulator\n", "\n", "# Configure the MPS simulator\n", "simulator_settings = QuimbSimulator(\n", " partial(quimb.tensor.CircuitMPS, max_bond=100, cutoff=1e-8),\n", " autodiff_backend=\"jax\",\n", ")\n", "\n", "# Simulate target circuit as MPS\n", "target_mps = tensornetwork_from_circuit(target_circuit, simulator_settings)\n", "\n", "# Generate ansatz and initial parameters from the shallow circuit\n", "ansatz, initial_parameters = generate_ansatz_from_circuit(good_circuit, qubits_initially_zero=True)\n", "print(f\"Target circuit depth: {target_circuit.depth()}\")\n", "print(f\"Ansatz circuit depth: {ansatz.depth()}, with {len(initial_parameters)} parameters\")\n", "\n", "# Optimize ansatz parameters against the target MPS\n", "objective = MaximizeStateFidelity(target_mps, ansatz, simulator_settings)\n", "\n", "result = minimize(\n", " objective.loss_function,\n", " initial_parameters,\n", " method=\"L-BFGS-B\",\n", " jac=True,\n", " options={\"maxiter\": 100},\n", ")\n", "\n", "print(f\"\\nFinal fidelity: {1 - result.fun:.8f}\")\n", "print(f\"Compressed circuit depth: {ansatz.assign_parameters(result.x).depth()}\")" ] }, { "cell_type": "markdown", "id": "expected-output", "metadata": {}, "source": [ "```\n", "Target circuit depth: 270\n", "Ansatz circuit depth: 23, with 515 parameters\n", "\n", "Final fidelity: 0.99971010\n", "Compressed circuit depth: 23\n", "```" ] }, { "cell_type": "markdown", "id": "next-steps", "metadata": {}, "source": [ "## Next steps\n", "\n", "Check out the tutorials on the IBM Quantum Platform to see how to build realistic workflows with AQC-Tensor ([Tutorial 1](https://quantum.cloud.ibm.com/docs/en/tutorials/reducing-circuit-depth-with-aqc))." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 5 }