{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"## Tutorial: InQuanto + qnexus\n",
"\n",
"Hamiltonian averaging project on H1 Emulator using InQuanto and qnexus to estimate the ground-state energy for CH2\n",
"\n",
"This notebook demonstrates a computable workflow with InQuanto and Nexus. To access Nexus, the user needs to use `inquanto.extensions.nexus` to submit circuits and retrieve results. Today, the intention is to submit circuits to the H1-1 emulator (H1-1E) for execution. Once results are available, they can be retrieved and processed by InQuanto to determine the ground-state energy."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"1. Nexus Project Name Setup\n",
"\n",
"We can use a new Nexus project for managing our chemistry jobs, or we can re-use an old one. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from qnexus.client import projects\n",
"\n",
"project_name = f\"InQuanto::Project\"\n",
"\n",
"project_ref = projects.get_or_create(\n",
" name=project_name, description=\"A demo project with inquanto-nexus\", properties={}\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Chemical Specification\n",
"\n",
"Here we will run an example calculation on methylene, CH2. \n",
"\n",
"Initially, the geometry of CH2 is specified, loaded into `inquanto.geometries.GeometryMolecular` and rendered as a pandas DataFrame.\n",
"\n",
"The geometry we use is from CCSD(T)=FULL/aug-cc-pVTZ level calculations presented on the Computational Chemistry Comparison and Benchmark DataBase. https://cccbdb.nist.gov/"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "id",
"rawType": "int64",
"type": "integer"
},
{
"name": "Element",
"rawType": "object",
"type": "string"
},
{
"name": "X",
"rawType": "float64",
"type": "float"
},
{
"name": "Y",
"rawType": "float64",
"type": "float"
},
{
"name": "Z",
"rawType": "float64",
"type": "float"
},
{
"name": "Atom",
"rawType": "object",
"type": "string"
}
],
"ref": "fcdfa37f-4781-4a54-b864-185aa34da43e",
"rows": [
[
"0",
"C",
"0.0",
"0.0",
"0.105132",
"C1"
],
[
"1",
"H",
"0.0",
"0.988263",
"-0.315396",
"H2"
],
[
"2",
"H",
"0.0",
"-0.988263",
"-0.315396",
"H3"
]
],
"shape": {
"columns": 5,
"rows": 3
}
},
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Element | \n",
" X | \n",
" Y | \n",
" Z | \n",
" Atom | \n",
"
\n",
" \n",
" id | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" C | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.105132 | \n",
" C1 | \n",
"
\n",
" \n",
" 1 | \n",
" H | \n",
" 0.0 | \n",
" 0.988263 | \n",
" -0.315396 | \n",
" H2 | \n",
"
\n",
" \n",
" 2 | \n",
" H | \n",
" 0.0 | \n",
" -0.988263 | \n",
" -0.315396 | \n",
" H3 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Element X Y Z Atom\n",
"id \n",
"0 C 0.0 0.000000 0.105132 C1\n",
"1 H 0.0 0.988263 -0.315396 H2\n",
"2 H 0.0 -0.988263 -0.315396 H3"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from inquanto.geometries import GeometryMolecular\n",
"\n",
"xyz = [\n",
" [\"C\", [0.0, 0.0, 0.1051320]],\n",
" [\"H\", [0.0, 0.9882630,-0.3153960]],\n",
" [\"H\", [0.0, -0.9882630, -0.3153960]],\n",
"]\n",
"\n",
"geometry = GeometryMolecular(xyz, \"angstrom\")\n",
"geometry.df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This structure can be visualised using NGLview, via the InQuanto-NGLView extension."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#from inquanto.extensions.nglview import VisualizerNGL\n",
"\n",
"#visualizer_nglview = VisualizerNGL(geometry)\n",
"#visualizer_nglview.visualize_molecule()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we construct an InQuanto driver object, which is used to prepare the qubit operators and spaces needed to construct the circuits. \n",
"\n",
"To do this, we use the InQuanto interface to PySCF. \n",
"\n",
"For a basic driver we need to specify the charge and multiplicity of our system. Here we construct a more advanced driver by applying an orbital rotation (transf). This transformation is to the basis of natural orbitals obtained after performing a CASSCF calculation with an active space of 2 electrons in 3 spatial (6-spin) orbitals"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from inquanto.extensions.pyscf import (\n",
" FromActiveSpace,\n",
" ChemistryDriverPySCFMolecularROHF,\n",
" CASSCF,\n",
")\n",
"\n",
"charge = 0\n",
"basis = \"sto-3g\"\n",
"multiplicity = 1\n",
"ncas = 3\n",
"nelecas = 2\n",
"frozen = FromActiveSpace(ncas=ncas, nelecas=nelecas) \n",
"transf = CASSCF(ncas=ncas, nelecas=nelecas)\n",
"point_group_symmetry=True\n",
"\n",
"driver_parameters = {\n",
" \"geometry\": geometry, # As a GeometryMolecular object\n",
" \"charge\": charge,\n",
" \"basis\": basis,\n",
" \"transf\": transf,\n",
" \"frozen\": frozen,\n",
" \"multiplicity\": multiplicity,\n",
" \"point_group_symmetry\": True,\n",
"}\n",
"\n",
"driver = ChemistryDriverPySCFMolecularROHF(**driver_parameters)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When the driver variables are defined we can use its get_system method to obtain the fermionic hamiltonian, space, and state. We'll carry these objects forward to build our circuits. "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"fermion_hamiltonian, fermion_space, fermion_state = driver.get_system()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also inspect various results of our calculation, such as the point group symmetry or orbital symmetries."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'This structure has a point group of C2v'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f\"This structure has a point group of {driver.point_group}\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As well as obtaining the objects needed to construct circuits, we can also use some driver convenience functions to perform classical computational chemistry methods to give results for comparison. \n",
"\n",
"Here we calculate Coupled Cluster Singles & Doubles (CCSD) energies classically for comparison. "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hartree Fock (RHF) energy: -38.33809020351786 Ha\n",
"CCSD energy: -38.3588270738749 Ha\n",
"CCSD energy correlation energy: 0.02073687035704097 Ha\n"
]
}
],
"source": [
"ccsd_energy = driver.run_ccsd()\n",
"scf_energy = driver.run_hf()\n",
"ccsd_correlation_energy = scf_energy - ccsd_energy \n",
"# correlation is positive: ccsd should be lower in energy than HF\n",
"\n",
"print(f\"Hartree Fock (RHF) energy: {scf_energy} Ha\")\n",
"print(f\"CCSD energy: {ccsd_energy} Ha\")\n",
"print(f\"CCSD energy correlation energy: {ccsd_correlation_energy} Ha\") "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Review Hamiltonian \n",
"\n",
"Here, we inspect the fermionic Hamiltonian we generated for CH2 with HF in the STO-3G basis set. Initially, we view the Fermionic strings. Each index in the string corresponds to action on a spin orbital. The symbol, `^`, following an index denotes electron creation, otherwise it is an electron destroying action. Our Hamiltonian contains 132 Fermionic strings (discluding the identity term)."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "Coefficient",
"rawType": "float64",
"type": "float"
},
{
"name": "Term",
"rawType": "object",
"type": "string"
}
],
"ref": "0349aed0-b980-472c-8f02-7e6935e70a3a",
"rows": [
[
"0",
"-37.10769637372601",
""
],
[
"1",
"-0.9681972002652369",
"F0^ F0 "
],
[
"2",
"-0.030655589908756962",
"F0^ F4 "
],
[
"3",
"0.7060005707386292",
"F1^ F0^ F0 F1 "
],
[
"4",
"0.02334667984112546",
"F1^ F0^ F0 F5 "
],
[
"5",
"0.05267347556240578",
"F1^ F0^ F2 F3 "
],
[
"6",
"0.023346679841125647",
"F1^ F0^ F4 F1 "
],
[
"7",
"0.0246853769777431",
"F1^ F0^ F4 F5 "
],
[
"8",
"-0.9681972002652369",
"F1^ F1 "
],
[
"9",
"-0.030655589908756962",
"F1^ F5 "
],
[
"10",
"0.5951650466932307",
"F2^ F0^ F0 F2 "
],
[
"11",
"0.052673475562405786",
"F2^ F0^ F2 F0 "
],
[
"12",
"-0.018601647606506788",
"F2^ F0^ F2 F4 "
],
[
"13",
"0.027105561311192402",
"F2^ F0^ F4 F2 "
],
[
"14",
"0.5951650466932307",
"F2^ F1^ F1 F2 "
],
[
"15",
"0.052673475562405786",
"F2^ F1^ F3 F0 "
],
[
"16",
"-0.018601647606506788",
"F2^ F1^ F3 F4 "
],
[
"17",
"0.027105561311192402",
"F2^ F1^ F5 F2 "
],
[
"18",
"-0.8950074624889344",
"F2^ F2 "
],
[
"19",
"0.5951650466932307",
"F3^ F0^ F0 F3 "
],
[
"20",
"0.052673475562405786",
"F3^ F0^ F2 F1 "
],
[
"21",
"-0.018601647606506788",
"F3^ F0^ F2 F5 "
],
[
"22",
"0.027105561311192402",
"F3^ F0^ F4 F3 "
],
[
"23",
"0.5951650466932307",
"F3^ F1^ F1 F3 "
],
[
"24",
"0.052673475562405786",
"F3^ F1^ F3 F1 "
],
[
"25",
"-0.018601647606506788",
"F3^ F1^ F3 F5 "
],
[
"26",
"0.027105561311192402",
"F3^ F1^ F5 F3 "
],
[
"27",
"0.05267347556240579",
"F3^ F2^ F0 F1 "
],
[
"28",
"-0.018601647606506778",
"F3^ F2^ F0 F5 "
],
[
"29",
"0.6728327205216605",
"F3^ F2^ F2 F3 "
],
[
"30",
"-0.018601647606506785",
"F3^ F2^ F4 F1 "
],
[
"31",
"0.048912471585477714",
"F3^ F2^ F4 F5 "
],
[
"32",
"-0.8950074624889344",
"F3^ F3 "
],
[
"33",
"-0.030655589908757018",
"F4^ F0 "
],
[
"34",
"0.4514118674871275",
"F4^ F0^ F0 F4 "
],
[
"35",
"0.024685376977743118",
"F4^ F0^ F4 F0 "
],
[
"36",
"0.023346679841125463",
"F4^ F1^ F1 F0 "
],
[
"37",
"0.4514118674871275",
"F4^ F1^ F1 F4 "
],
[
"38",
"-0.01860164760650677",
"F4^ F1^ F3 F2 "
],
[
"39",
"0.024685376977743118",
"F4^ F1^ F5 F0 "
],
[
"40",
"0.02523192632549295",
"F4^ F1^ F5 F4 "
],
[
"41",
"-0.018601647606506767",
"F4^ F2^ F0 F2 "
],
[
"42",
"0.02710556131119235",
"F4^ F2^ F2 F0 "
],
[
"43",
"0.5005988464063563",
"F4^ F2^ F2 F4 "
],
[
"44",
"0.0489124715854777",
"F4^ F2^ F4 F2 "
],
[
"45",
"-0.018601647606506767",
"F4^ F3^ F1 F2 "
],
[
"46",
"0.02710556131119235",
"F4^ F3^ F3 F0 "
],
[
"47",
"0.5005988464063563",
"F4^ F3^ F3 F4 "
],
[
"48",
"0.0489124715854777",
"F4^ F3^ F5 F2 "
],
[
"49",
"-0.27103398423097164",
"F4^ F4 "
]
],
"shape": {
"columns": 2,
"rows": 72
}
},
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Coefficient | \n",
" Term | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" -37.107696 | \n",
" | \n",
"
\n",
" \n",
" 1 | \n",
" -0.968197 | \n",
" F0^ F0 | \n",
"
\n",
" \n",
" 2 | \n",
" -0.030656 | \n",
" F0^ F4 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.706001 | \n",
" F1^ F0^ F0 F1 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.023347 | \n",
" F1^ F0^ F0 F5 | \n",
"
\n",
" \n",
" 5 | \n",
" 0.052673 | \n",
" F1^ F0^ F2 F3 | \n",
"
\n",
" \n",
" 6 | \n",
" 0.023347 | \n",
" F1^ F0^ F4 F1 | \n",
"
\n",
" \n",
" 7 | \n",
" 0.024685 | \n",
" F1^ F0^ F4 F5 | \n",
"
\n",
" \n",
" 8 | \n",
" -0.968197 | \n",
" F1^ F1 | \n",
"
\n",
" \n",
" 9 | \n",
" -0.030656 | \n",
" F1^ F5 | \n",
"
\n",
" \n",
" 10 | \n",
" 0.595165 | \n",
" F2^ F0^ F0 F2 | \n",
"
\n",
" \n",
" 11 | \n",
" 0.052673 | \n",
" F2^ F0^ F2 F0 | \n",
"
\n",
" \n",
" 12 | \n",
" -0.018602 | \n",
" F2^ F0^ F2 F4 | \n",
"
\n",
" \n",
" 13 | \n",
" 0.027106 | \n",
" F2^ F0^ F4 F2 | \n",
"
\n",
" \n",
" 14 | \n",
" 0.595165 | \n",
" F2^ F1^ F1 F2 | \n",
"
\n",
" \n",
" 15 | \n",
" 0.052673 | \n",
" F2^ F1^ F3 F0 | \n",
"
\n",
" \n",
" 16 | \n",
" -0.018602 | \n",
" F2^ F1^ F3 F4 | \n",
"
\n",
" \n",
" 17 | \n",
" 0.027106 | \n",
" F2^ F1^ F5 F2 | \n",
"
\n",
" \n",
" 18 | \n",
" -0.895007 | \n",
" F2^ F2 | \n",
"
\n",
" \n",
" 19 | \n",
" 0.595165 | \n",
" F3^ F0^ F0 F3 | \n",
"
\n",
" \n",
" 20 | \n",
" 0.052673 | \n",
" F3^ F0^ F2 F1 | \n",
"
\n",
" \n",
" 21 | \n",
" -0.018602 | \n",
" F3^ F0^ F2 F5 | \n",
"
\n",
" \n",
" 22 | \n",
" 0.027106 | \n",
" F3^ F0^ F4 F3 | \n",
"
\n",
" \n",
" 23 | \n",
" 0.595165 | \n",
" F3^ F1^ F1 F3 | \n",
"
\n",
" \n",
" 24 | \n",
" 0.052673 | \n",
" F3^ F1^ F3 F1 | \n",
"
\n",
" \n",
" 25 | \n",
" -0.018602 | \n",
" F3^ F1^ F3 F5 | \n",
"
\n",
" \n",
" 26 | \n",
" 0.027106 | \n",
" F3^ F1^ F5 F3 | \n",
"
\n",
" \n",
" 27 | \n",
" 0.052673 | \n",
" F3^ F2^ F0 F1 | \n",
"
\n",
" \n",
" 28 | \n",
" -0.018602 | \n",
" F3^ F2^ F0 F5 | \n",
"
\n",
" \n",
" 29 | \n",
" 0.672833 | \n",
" F3^ F2^ F2 F3 | \n",
"
\n",
" \n",
" 30 | \n",
" -0.018602 | \n",
" F3^ F2^ F4 F1 | \n",
"
\n",
" \n",
" 31 | \n",
" 0.048912 | \n",
" F3^ F2^ F4 F5 | \n",
"
\n",
" \n",
" 32 | \n",
" -0.895007 | \n",
" F3^ F3 | \n",
"
\n",
" \n",
" 33 | \n",
" -0.030656 | \n",
" F4^ F0 | \n",
"
\n",
" \n",
" 34 | \n",
" 0.451412 | \n",
" F4^ F0^ F0 F4 | \n",
"
\n",
" \n",
" 35 | \n",
" 0.024685 | \n",
" F4^ F0^ F4 F0 | \n",
"
\n",
" \n",
" 36 | \n",
" 0.023347 | \n",
" F4^ F1^ F1 F0 | \n",
"
\n",
" \n",
" 37 | \n",
" 0.451412 | \n",
" F4^ F1^ F1 F4 | \n",
"
\n",
" \n",
" 38 | \n",
" -0.018602 | \n",
" F4^ F1^ F3 F2 | \n",
"
\n",
" \n",
" 39 | \n",
" 0.024685 | \n",
" F4^ F1^ F5 F0 | \n",
"
\n",
" \n",
" 40 | \n",
" 0.025232 | \n",
" F4^ F1^ F5 F4 | \n",
"
\n",
" \n",
" 41 | \n",
" -0.018602 | \n",
" F4^ F2^ F0 F2 | \n",
"
\n",
" \n",
" 42 | \n",
" 0.027106 | \n",
" F4^ F2^ F2 F0 | \n",
"
\n",
" \n",
" 43 | \n",
" 0.500599 | \n",
" F4^ F2^ F2 F4 | \n",
"
\n",
" \n",
" 44 | \n",
" 0.048912 | \n",
" F4^ F2^ F4 F2 | \n",
"
\n",
" \n",
" 45 | \n",
" -0.018602 | \n",
" F4^ F3^ F1 F2 | \n",
"
\n",
" \n",
" 46 | \n",
" 0.027106 | \n",
" F4^ F3^ F3 F0 | \n",
"
\n",
" \n",
" 47 | \n",
" 0.500599 | \n",
" F4^ F3^ F3 F4 | \n",
"
\n",
" \n",
" 48 | \n",
" 0.048912 | \n",
" F4^ F3^ F5 F2 | \n",
"
\n",
" \n",
" 49 | \n",
" -0.271034 | \n",
" F4^ F4 | \n",
"
\n",
" \n",
" 50 | \n",
" 0.023347 | \n",
" F5^ F0^ F0 F1 | \n",
"
\n",
" \n",
" 51 | \n",
" 0.451412 | \n",
" F5^ F0^ F0 F5 | \n",
"
\n",
" \n",
" 52 | \n",
" -0.018602 | \n",
" F5^ F0^ F2 F3 | \n",
"
\n",
" \n",
" 53 | \n",
" 0.024685 | \n",
" F5^ F0^ F4 F1 | \n",
"
\n",
" \n",
" 54 | \n",
" 0.025232 | \n",
" F5^ F0^ F4 F5 | \n",
"
\n",
" \n",
" 55 | \n",
" -0.030656 | \n",
" F5^ F1 | \n",
"
\n",
" \n",
" 56 | \n",
" 0.451412 | \n",
" F5^ F1^ F1 F5 | \n",
"
\n",
" \n",
" 57 | \n",
" 0.024685 | \n",
" F5^ F1^ F5 F1 | \n",
"
\n",
" \n",
" 58 | \n",
" -0.018602 | \n",
" F5^ F2^ F0 F3 | \n",
"
\n",
" \n",
" 59 | \n",
" 0.027106 | \n",
" F5^ F2^ F2 F1 | \n",
"
\n",
" \n",
" 60 | \n",
" 0.500599 | \n",
" F5^ F2^ F2 F5 | \n",
"
\n",
" \n",
" 61 | \n",
" 0.048912 | \n",
" F5^ F2^ F4 F3 | \n",
"
\n",
" \n",
" 62 | \n",
" -0.018602 | \n",
" F5^ F3^ F1 F3 | \n",
"
\n",
" \n",
" 63 | \n",
" 0.027106 | \n",
" F5^ F3^ F3 F1 | \n",
"
\n",
" \n",
" 64 | \n",
" 0.500599 | \n",
" F5^ F3^ F3 F5 | \n",
"
\n",
" \n",
" 65 | \n",
" 0.048912 | \n",
" F5^ F3^ F5 F3 | \n",
"
\n",
" \n",
" 66 | \n",
" 0.024685 | \n",
" F5^ F4^ F0 F1 | \n",
"
\n",
" \n",
" 67 | \n",
" 0.025232 | \n",
" F5^ F4^ F0 F5 | \n",
"
\n",
" \n",
" 68 | \n",
" 0.048912 | \n",
" F5^ F4^ F2 F3 | \n",
"
\n",
" \n",
" 69 | \n",
" 0.025232 | \n",
" F5^ F4^ F4 F1 | \n",
"
\n",
" \n",
" 70 | \n",
" 0.561441 | \n",
" F5^ F4^ F4 F5 | \n",
"
\n",
" \n",
" 71 | \n",
" -0.271034 | \n",
" F5^ F5 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Coefficient Term\n",
"0 -37.107696 \n",
"1 -0.968197 F0^ F0 \n",
"2 -0.030656 F0^ F4 \n",
"3 0.706001 F1^ F0^ F0 F1 \n",
"4 0.023347 F1^ F0^ F0 F5 \n",
"5 0.052673 F1^ F0^ F2 F3 \n",
"6 0.023347 F1^ F0^ F4 F1 \n",
"7 0.024685 F1^ F0^ F4 F5 \n",
"8 -0.968197 F1^ F1 \n",
"9 -0.030656 F1^ F5 \n",
"10 0.595165 F2^ F0^ F0 F2 \n",
"11 0.052673 F2^ F0^ F2 F0 \n",
"12 -0.018602 F2^ F0^ F2 F4 \n",
"13 0.027106 F2^ F0^ F4 F2 \n",
"14 0.595165 F2^ F1^ F1 F2 \n",
"15 0.052673 F2^ F1^ F3 F0 \n",
"16 -0.018602 F2^ F1^ F3 F4 \n",
"17 0.027106 F2^ F1^ F5 F2 \n",
"18 -0.895007 F2^ F2 \n",
"19 0.595165 F3^ F0^ F0 F3 \n",
"20 0.052673 F3^ F0^ F2 F1 \n",
"21 -0.018602 F3^ F0^ F2 F5 \n",
"22 0.027106 F3^ F0^ F4 F3 \n",
"23 0.595165 F3^ F1^ F1 F3 \n",
"24 0.052673 F3^ F1^ F3 F1 \n",
"25 -0.018602 F3^ F1^ F3 F5 \n",
"26 0.027106 F3^ F1^ F5 F3 \n",
"27 0.052673 F3^ F2^ F0 F1 \n",
"28 -0.018602 F3^ F2^ F0 F5 \n",
"29 0.672833 F3^ F2^ F2 F3 \n",
"30 -0.018602 F3^ F2^ F4 F1 \n",
"31 0.048912 F3^ F2^ F4 F5 \n",
"32 -0.895007 F3^ F3 \n",
"33 -0.030656 F4^ F0 \n",
"34 0.451412 F4^ F0^ F0 F4 \n",
"35 0.024685 F4^ F0^ F4 F0 \n",
"36 0.023347 F4^ F1^ F1 F0 \n",
"37 0.451412 F4^ F1^ F1 F4 \n",
"38 -0.018602 F4^ F1^ F3 F2 \n",
"39 0.024685 F4^ F1^ F5 F0 \n",
"40 0.025232 F4^ F1^ F5 F4 \n",
"41 -0.018602 F4^ F2^ F0 F2 \n",
"42 0.027106 F4^ F2^ F2 F0 \n",
"43 0.500599 F4^ F2^ F2 F4 \n",
"44 0.048912 F4^ F2^ F4 F2 \n",
"45 -0.018602 F4^ F3^ F1 F2 \n",
"46 0.027106 F4^ F3^ F3 F0 \n",
"47 0.500599 F4^ F3^ F3 F4 \n",
"48 0.048912 F4^ F3^ F5 F2 \n",
"49 -0.271034 F4^ F4 \n",
"50 0.023347 F5^ F0^ F0 F1 \n",
"51 0.451412 F5^ F0^ F0 F5 \n",
"52 -0.018602 F5^ F0^ F2 F3 \n",
"53 0.024685 F5^ F0^ F4 F1 \n",
"54 0.025232 F5^ F0^ F4 F5 \n",
"55 -0.030656 F5^ F1 \n",
"56 0.451412 F5^ F1^ F1 F5 \n",
"57 0.024685 F5^ F1^ F5 F1 \n",
"58 -0.018602 F5^ F2^ F0 F3 \n",
"59 0.027106 F5^ F2^ F2 F1 \n",
"60 0.500599 F5^ F2^ F2 F5 \n",
"61 0.048912 F5^ F2^ F4 F3 \n",
"62 -0.018602 F5^ F3^ F1 F3 \n",
"63 0.027106 F5^ F3^ F3 F1 \n",
"64 0.500599 F5^ F3^ F3 F5 \n",
"65 0.048912 F5^ F3^ F5 F3 \n",
"66 0.024685 F5^ F4^ F0 F1 \n",
"67 0.025232 F5^ F4^ F0 F5 \n",
"68 0.048912 F5^ F4^ F2 F3 \n",
"69 0.025232 F5^ F4^ F4 F1 \n",
"70 0.561441 F5^ F4^ F4 F5 \n",
"71 -0.271034 F5^ F5 "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fermion_hamiltonian.df()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Hamiltonian can now be converted into a qubit representation. We use the Jordan-Wigner transformation to accomplish this task. Each Fermionic string is now transformed to a Pauli operator (`I`, `X`, `Y`, `Z`) acting on a qubit `q[i]`, where: - `q` is the name of the qubit register;
- `i` is the qubit index.
. We refer to each term in this new representation as 'Pauli word'. After the transformation, the Hamiltonian in the Qubit Pauli basis contains 61 terms, not including identity (`I`)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "Coefficient",
"rawType": "float64",
"type": "float"
},
{
"name": "Term",
"rawType": "object",
"type": "string"
},
{
"name": "Coefficient type",
"rawType": "object",
"type": "unknown"
}
],
"ref": "e2d9c641-edf0-4fef-a449-168fc160bb5c",
"rows": [
[
"0",
"-37.272826299989326",
"",
""
],
[
"1",
"-0.4624492020733236",
"Z5",
""
],
[
"2",
"-0.4624492020733236",
"Z4",
""
],
[
"3",
"0.14036029938287248",
"Z4 Z5",
""
],
[
"4",
"-0.2431899086487707",
"Z3",
""
],
[
"5",
"0.11292159370521966",
"Z3 Z5",
""
],
[
"6",
"0.12514971160158908",
"Z3 Z4",
""
],
[
"7",
"-0.012228117896369425",
"X2 X3 Y4 Y5",
""
],
[
"8",
"0.012228117896369425",
"X2 Y3 Y4 X5",
""
],
[
"9",
"0.012228117896369425",
"Y2 X3 X4 Y5",
""
],
[
"10",
"-0.012228117896369425",
"Y2 Y3 X4 X5",
""
],
[
"11",
"-0.2431899086487706",
"Z2",
""
],
[
"12",
"0.12514971160158908",
"Z2 Z5",
""
],
[
"13",
"0.11292159370521966",
"Z2 Z4",
""
],
[
"14",
"0.16820818013041514",
"Z2 Z3",
""
],
[
"15",
"-0.006776390327798094",
"X1 Z3 Z4 X5",
""
],
[
"16",
"0.0046504119016266944",
"X1 X2 Y3 Y4",
""
],
[
"17",
"-0.0046504119016266944",
"X1 Y2 Y3 X4",
""
],
[
"18",
"-0.011426802229424788",
"X1 Z2 Z4 X5",
""
],
[
"19",
"-0.0063079815813732055",
"X1 Z2 Z3 X5",
""
],
[
"20",
"0.015020049144498957",
"X1 Z2 Z3 Z4 X5",
""
],
[
"21",
"-0.006776390327798094",
"Y1 Z3 Z4 Y5",
""
],
[
"22",
"-0.0046504119016266944",
"Y1 X2 X3 Y4",
""
],
[
"23",
"0.0046504119016266944",
"Y1 Y2 X3 X4",
""
],
[
"24",
"-0.011426802229424788",
"Y1 Z2 Z4 Y5",
""
],
[
"25",
"-0.0063079815813732055",
"Y1 Z2 Z3 Y5",
""
],
[
"26",
"0.015020049144498957",
"Y1 Z2 Z3 Z4 Y5",
""
],
[
"27",
"-0.19635028650718073",
"Z1",
""
],
[
"28",
"0.1066816226273461",
"Z1 Z5",
""
],
[
"29",
"0.11285296687178188",
"Z1 Z4",
""
],
[
"30",
"0.13562289278270623",
"Z1 Z3",
""
],
[
"31",
"0.14879126167330767",
"Z1 Z2",
""
],
[
"32",
"-0.005836669960281388",
"X0 Z2 Z3 X4",
""
],
[
"33",
"-0.0061713442444357855",
"X0 X1 Y4 Y5",
""
],
[
"34",
"-0.013168368890601446",
"X0 X1 Y2 Y3",
""
],
[
"35",
"0.0061713442444357855",
"X0 Y1 Y4 X5",
""
],
[
"36",
"0.013168368890601446",
"X0 Y1 Y2 X3",
""
],
[
"37",
"-0.011426802229424788",
"X0 Z1 Z3 X4",
""
],
[
"38",
"-0.004650411901626694",
"X0 Z1 X2 X3 Z4 X5",
""
],
[
"39",
"-0.004650411901626694",
"X0 Z1 X2 Y3 Z4 Y5",
""
],
[
"40",
"-0.006776390327798094",
"X0 Z1 Z2 X4",
""
],
[
"41",
"0.015020049144499004",
"X0 Z1 Z2 Z3 X4",
""
],
[
"42",
"-0.0063079815813732315",
"X0 Z1 Z2 Z3 X4 Z5",
""
],
[
"43",
"-0.005836669960281388",
"Y0 Z2 Z3 Y4",
""
],
[
"44",
"0.0061713442444357855",
"Y0 X1 X4 Y5",
""
],
[
"45",
"0.013168368890601446",
"Y0 X1 X2 Y3",
""
],
[
"46",
"-0.0061713442444357855",
"Y0 Y1 X4 X5",
""
],
[
"47",
"-0.013168368890601446",
"Y0 Y1 X2 X3",
""
],
[
"48",
"-0.011426802229424788",
"Y0 Z1 Z3 Y4",
""
],
[
"49",
"-0.004650411901626694",
"Y0 Z1 Y2 X3 Z4 X5",
""
]
],
"shape": {
"columns": 3,
"rows": 62
}
},
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Coefficient | \n",
" Term | \n",
" Coefficient type | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" -37.272826 | \n",
" | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 1 | \n",
" -0.462449 | \n",
" Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 2 | \n",
" -0.462449 | \n",
" Z4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 3 | \n",
" 0.140360 | \n",
" Z4 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 4 | \n",
" -0.243190 | \n",
" Z3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 5 | \n",
" 0.112922 | \n",
" Z3 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 6 | \n",
" 0.125150 | \n",
" Z3 Z4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 7 | \n",
" -0.012228 | \n",
" X2 X3 Y4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 8 | \n",
" 0.012228 | \n",
" X2 Y3 Y4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 9 | \n",
" 0.012228 | \n",
" Y2 X3 X4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 10 | \n",
" -0.012228 | \n",
" Y2 Y3 X4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 11 | \n",
" -0.243190 | \n",
" Z2 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 12 | \n",
" 0.125150 | \n",
" Z2 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 13 | \n",
" 0.112922 | \n",
" Z2 Z4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 14 | \n",
" 0.168208 | \n",
" Z2 Z3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 15 | \n",
" -0.006776 | \n",
" X1 Z3 Z4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 16 | \n",
" 0.004650 | \n",
" X1 X2 Y3 Y4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 17 | \n",
" -0.004650 | \n",
" X1 Y2 Y3 X4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 18 | \n",
" -0.011427 | \n",
" X1 Z2 Z4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 19 | \n",
" -0.006308 | \n",
" X1 Z2 Z3 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 20 | \n",
" 0.015020 | \n",
" X1 Z2 Z3 Z4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 21 | \n",
" -0.006776 | \n",
" Y1 Z3 Z4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 22 | \n",
" -0.004650 | \n",
" Y1 X2 X3 Y4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 23 | \n",
" 0.004650 | \n",
" Y1 Y2 X3 X4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 24 | \n",
" -0.011427 | \n",
" Y1 Z2 Z4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 25 | \n",
" -0.006308 | \n",
" Y1 Z2 Z3 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 26 | \n",
" 0.015020 | \n",
" Y1 Z2 Z3 Z4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 27 | \n",
" -0.196350 | \n",
" Z1 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 28 | \n",
" 0.106682 | \n",
" Z1 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 29 | \n",
" 0.112853 | \n",
" Z1 Z4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 30 | \n",
" 0.135623 | \n",
" Z1 Z3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 31 | \n",
" 0.148791 | \n",
" Z1 Z2 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 32 | \n",
" -0.005837 | \n",
" X0 Z2 Z3 X4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 33 | \n",
" -0.006171 | \n",
" X0 X1 Y4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 34 | \n",
" -0.013168 | \n",
" X0 X1 Y2 Y3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 35 | \n",
" 0.006171 | \n",
" X0 Y1 Y4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 36 | \n",
" 0.013168 | \n",
" X0 Y1 Y2 X3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 37 | \n",
" -0.011427 | \n",
" X0 Z1 Z3 X4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 38 | \n",
" -0.004650 | \n",
" X0 Z1 X2 X3 Z4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 39 | \n",
" -0.004650 | \n",
" X0 Z1 X2 Y3 Z4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 40 | \n",
" -0.006776 | \n",
" X0 Z1 Z2 X4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 41 | \n",
" 0.015020 | \n",
" X0 Z1 Z2 Z3 X4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 42 | \n",
" -0.006308 | \n",
" X0 Z1 Z2 Z3 X4 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 43 | \n",
" -0.005837 | \n",
" Y0 Z2 Z3 Y4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 44 | \n",
" 0.006171 | \n",
" Y0 X1 X4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 45 | \n",
" 0.013168 | \n",
" Y0 X1 X2 Y3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 46 | \n",
" -0.006171 | \n",
" Y0 Y1 X4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 47 | \n",
" -0.013168 | \n",
" Y0 Y1 X2 X3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 48 | \n",
" -0.011427 | \n",
" Y0 Z1 Z3 Y4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 49 | \n",
" -0.004650 | \n",
" Y0 Z1 Y2 X3 Z4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 50 | \n",
" -0.004650 | \n",
" Y0 Z1 Y2 Y3 Z4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 51 | \n",
" -0.006776 | \n",
" Y0 Z1 Z2 Y4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 52 | \n",
" 0.015020 | \n",
" Y0 Z1 Z2 Z3 Y4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 53 | \n",
" -0.006308 | \n",
" Y0 Z1 Z2 Z3 Y4 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 54 | \n",
" -0.196350 | \n",
" Z0 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 55 | \n",
" 0.112853 | \n",
" Z0 Z5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 56 | \n",
" 0.106682 | \n",
" Z0 Z4 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 57 | \n",
" 0.148791 | \n",
" Z0 Z3 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 58 | \n",
" 0.135623 | \n",
" Z0 Z2 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 59 | \n",
" -0.005837 | \n",
" Z0 X1 Z2 Z3 Z4 X5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 60 | \n",
" -0.005837 | \n",
" Z0 Y1 Z2 Z3 Z4 Y5 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
" 61 | \n",
" 0.176500 | \n",
" Z0 Z1 | \n",
" <class 'numpy.float64'> | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Coefficient Term Coefficient type\n",
"0 -37.272826 \n",
"1 -0.462449 Z5 \n",
"2 -0.462449 Z4 \n",
"3 0.140360 Z4 Z5 \n",
"4 -0.243190 Z3 \n",
"5 0.112922 Z3 Z5 \n",
"6 0.125150 Z3 Z4 \n",
"7 -0.012228 X2 X3 Y4 Y5 \n",
"8 0.012228 X2 Y3 Y4 X5 \n",
"9 0.012228 Y2 X3 X4 Y5 \n",
"10 -0.012228 Y2 Y3 X4 X5 \n",
"11 -0.243190 Z2 \n",
"12 0.125150 Z2 Z5 \n",
"13 0.112922 Z2 Z4 \n",
"14 0.168208 Z2 Z3 \n",
"15 -0.006776 X1 Z3 Z4 X5 \n",
"16 0.004650 X1 X2 Y3 Y4 \n",
"17 -0.004650 X1 Y2 Y3 X4 \n",
"18 -0.011427 X1 Z2 Z4 X5 \n",
"19 -0.006308 X1 Z2 Z3 X5 \n",
"20 0.015020 X1 Z2 Z3 Z4 X5 \n",
"21 -0.006776 Y1 Z3 Z4 Y5 \n",
"22 -0.004650 Y1 X2 X3 Y4 \n",
"23 0.004650 Y1 Y2 X3 X4 \n",
"24 -0.011427 Y1 Z2 Z4 Y5 \n",
"25 -0.006308 Y1 Z2 Z3 Y5 \n",
"26 0.015020 Y1 Z2 Z3 Z4 Y5 \n",
"27 -0.196350 Z1 \n",
"28 0.106682 Z1 Z5 \n",
"29 0.112853 Z1 Z4 \n",
"30 0.135623 Z1 Z3 \n",
"31 0.148791 Z1 Z2 \n",
"32 -0.005837 X0 Z2 Z3 X4 \n",
"33 -0.006171 X0 X1 Y4 Y5 \n",
"34 -0.013168 X0 X1 Y2 Y3 \n",
"35 0.006171 X0 Y1 Y4 X5 \n",
"36 0.013168 X0 Y1 Y2 X3 \n",
"37 -0.011427 X0 Z1 Z3 X4 \n",
"38 -0.004650 X0 Z1 X2 X3 Z4 X5 \n",
"39 -0.004650 X0 Z1 X2 Y3 Z4 Y5 \n",
"40 -0.006776 X0 Z1 Z2 X4 \n",
"41 0.015020 X0 Z1 Z2 Z3 X4 \n",
"42 -0.006308 X0 Z1 Z2 Z3 X4 Z5 \n",
"43 -0.005837 Y0 Z2 Z3 Y4 \n",
"44 0.006171 Y0 X1 X4 Y5 \n",
"45 0.013168 Y0 X1 X2 Y3 \n",
"46 -0.006171 Y0 Y1 X4 X5 \n",
"47 -0.013168 Y0 Y1 X2 X3 \n",
"48 -0.011427 Y0 Z1 Z3 Y4 \n",
"49 -0.004650 Y0 Z1 Y2 X3 Z4 X5 \n",
"50 -0.004650 Y0 Z1 Y2 Y3 Z4 Y5 \n",
"51 -0.006776 Y0 Z1 Z2 Y4 \n",
"52 0.015020 Y0 Z1 Z2 Z3 Y4 \n",
"53 -0.006308 Y0 Z1 Z2 Z3 Y4 Z5 \n",
"54 -0.196350 Z0 \n",
"55 0.112853 Z0 Z5 \n",
"56 0.106682 Z0 Z4 \n",
"57 0.148791 Z0 Z3 \n",
"58 0.135623 Z0 Z2 \n",
"59 -0.005837 Z0 X1 Z2 Z3 Z4 X5 \n",
"60 -0.005837 Z0 Y1 Z2 Z3 Z4 Y5 \n",
"61 0.176500 Z0 Z1 "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from inquanto.mappings import QubitMappingJordanWigner\n",
"\n",
"jw_map = QubitMappingJordanWigner()\n",
"qubit_hamiltonian_jw = fermion_hamiltonian.qubit_encode(jw_map)\n",
"qubit_hamiltonian_jw.df()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Chemically Aware Unitary Coupled Cluster State-Preparation\n",
"\n",
"We now build the Unitary Coupled Cluster Singles & Doubles (UCCSD) state-preparation circuit. This captures a similar level of electronic correlation as classical CCSD. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Inside the state and space from our driver is symmetry information and orbital occupancies, which are now inputted into the `FermionSpaceAnsatzChemicallyAwareUCCSD` object to generate the UCCSD state-preparation circuit. We can inspect some of this data as such:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 0a : 1 \n",
" 1 0b : 1 \n",
" 2 1a : 0 \n",
" 3 1b : 0 \n",
" 4 2a : 0 \n",
" 5 2b : 0 \n"
]
}
],
"source": [
"fermion_space.print_state(fermion_state)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, we use these quantities to build the ansatz state-preparation circuit:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"from inquanto.ansatzes import FermionSpaceAnsatzChemicallyAwareUCCSD\n",
"from pytket.circuit import OpType\n",
"\n",
"ansatz = FermionSpaceAnsatzChemicallyAwareUCCSD(fermion_space, fermion_state)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As a first, we print some basic circuit statistics:- # of qubits;
- # of symbols;
- # of CX gates.
"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# of qubits: 6\n",
"# of symbols: 4\n",
"# of 2=qubit gates: 23\n"
]
}
],
"source": [
"\n",
"print(f\"# of qubits: {ansatz.n_qubits}\")\n",
"print(f\"# of symbols: {ansatz.n_symbols}\")\n",
"print(f\"# of 2=qubit gates: {ansatz.circuit_resources()['gates_2q']}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also render the State-Preparation circuit in jupyter for inspection"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \n",
"
\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from pytket.circuit.display import render_circuit_jupyter\n",
"\n",
"render_circuit_jupyter(ansatz.state_circuit)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"5. Perform a classical VQE project to obtain parameters that characterise the ground-state wavefunction\n",
"\n",
"In the cell below we perform a variational quantum eigensolver using inquanto's express module. This is a statevector backed only convenience function. \n",
"Firstly we instantiate a statevector NexusConfig into our NexusBackend. \n",
"Then we provide the run_vqe algorithm class with the qubit hamiltonian and the ansatz circuit. A loop then beings where, at each step, the statevector job is submitted to our Nexus project and executed. These jobs can be inspected as https://nexus.quantinuum.com/ . \n",
"When the VQE cycle has converged with respect to energy the cycle stops and we can inspect the total energy obtained and the symbol coefficients of our parameterized circuit\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# TIMER BLOCK-0 BEGINS AT 2025-06-23 15:14:18.750726\n",
"# TIMER BLOCK-0 ENDS - DURATION (s): 1310.9996753 [0:21:50.999675]\n",
"VQE Energy: -38.35882707383371\n",
"{d0: np.float64(-0.37329427840313417), d1: np.float64(-0.004353051918026713), s0: np.float64(-2.9756111818475934e-06), s1: np.float64(-1.974384093816498e-06)}\n"
]
}
],
"source": [
"from inquanto.express import run_vqe\n",
"from qnexus import AerStateConfig\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"vqe = run_vqe(ansatz, qubit_hamiltonian_jw, AerStateConfig(), with_gradient=False, project_ref=project_ref)\n",
"print(f\"VQE Energy: {vqe.final_value}\")\n",
"gs_parameters = vqe.final_parameters\n",
"print(vqe.final_parameters)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can relate these coefficients to the fermionic exponents:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Fermion Excitations and Amplitudes\n",
"==================================\n",
"Exponent\t\t\t\t\tAmplitude\t\tSymbol\n",
"(1.0, F2^ F0 F3^ F1 ), (-1.0, F1^ F3 F0^ F2 )\t-0.37329427840313417\td0\n",
"(1.0, F4^ F0 F5^ F1 ), (-1.0, F1^ F5 F0^ F4 )\t-0.004353051918026713\td1\n",
"(1.0, F4^ F0 ), (-1.0, F0^ F4 )\t-2.9756111818475934e-06\ts0\n",
"(1.0, F5^ F1 ), (-1.0, F1^ F5 )\t-1.974384093816498e-06\ts1\n"
]
}
],
"source": [
"print(\"Fermion Excitations and Amplitudes\")\n",
"print(\"==================================\")\n",
"print(\"Exponent\\t\\t\\t\\t\\tAmplitude\\t\\tSymbol\")\n",
"for fermion_operator, symbol in ansatz._fermion_operator_exponents:\n",
" parameter = vqe.final_parameters[symbol]\n",
" print(f\"{fermion_operator}\\t{parameter}\\t{symbol}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. Hamiltonian Averaging using InQuanto Computables\n",
"\n",
"In general, InQuanto uses 'Computables' to calculate the chemical quantity of relevance. A protocol is then the blueprint which defines how we calculate the chemical quantity on the quantum computer. The simplest computables, such as expectation values of an operator on a state, can be evaluated directly using a single protocol. More details on these structures can be found at https://inquanto.quantinuum.com/\n",
"\n",
"\n",
"6. a. Prepare Protocol\n",
"\n",
"We will re-use our ansatz and operator from above. \n",
"\n",
"The protocol we use today is called `PauliAveraging`, and is one way to perform Hamiltonian Averaging. This protocol generates measurement circuits from the Hamiltonian and state-preparation circuit. These circuits will be submitted to the H1 emulator (H1-1E) via Nexus. Once the results are retrieved, the protocol can then estimate the expectation value of the Pauli words. These expectations are multiplied by the corresponding coefficient in the Hamiltonian, and summed to obtain the ground-state energy."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from inquanto.protocols import PauliAveraging\n",
"from qnexus import QuantinuumConfig\n",
"from inquanto.core._tket import PauliPartitionStrat\n",
"\n",
"configuration = QuantinuumConfig(device_name=\"H1-1E\", user_group=\"Default - UK\")\n",
"protocol = PauliAveraging(\n",
" configuration,\n",
" shots_per_circuit=5000,\n",
" pauli_partition_strategy=PauliPartitionStrat.CommutingSets,\n",
" project_ref=project_ref\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. b. Partition Measurement Symmetry Verification\n",
"\n",
"We recognise that our system possesses C2v point group symmetry. This can be exploited in the Hamiltonian Averaging procedure since we know the parity of certain Pauli words and therefore their expectation values. \n",
"\n",
"These Pauli words corresponding to symmetry operations - mirror planes and pi radian rotations. \n",
"\n",
"One can use InQuanto to calculate the Pauli words (within Jordan Wigner encoding)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1.0, Z2 Z3)\n",
"(1.0, Z0 Z1 Z2 Z3 Z4 Z5)\n",
"(-1.0, Z0 Z2 Z4)\n"
]
}
],
"source": [
"pauli_symmetries = jw_map.operator_map(fermion_space.symmetry_operators_z2_in_sector(fermion_state))\n",
"\n",
"for op in pauli_symmetries:\n",
" print(op)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The protocol can be modified to include Symmetry Verification step. The flavour we use in InQuanto is called Partition Measurement Symmetry Verification (PMSV). The steps are as follows:\n",
"\n",
"- Find largest Abelian point group of molecule. Transformations of this point group are Pauli-symmetries.
\n",
"- Build symmetry verifiable circuits using the measurement reduction facility in tket. The operators that we need to measure on the quantum device to solve out problem consist of Pauli-Is, Pauli-Xs, Pauli-Ys and Pauli-Zs across the qubit register. These operations can be partitioned into commuting sets. For element in a commuting set, if the Pauli-symmetries commute element-wise, it can be added to the commuting set. This way, each commuting set is symmetry verifiable.
\n",
"- Post-select on measurement result before counting bitstrings to compute expectation value of problem Hamiltonian. The quantity to post-select on is the XOR sum over the bit-strings needed to compute expectation value of Pauli-symmetry.
\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from inquanto.protocols import PMSV\n",
"mitms_pmsv = PMSV(pauli_symmetries)\n",
"protocol.clear()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. c. Build Protocol\n",
"\n",
"We now build and compile the measurement circuits for the shot based protocol, including instructions for symmetry verification noise mitigation with Hamiltonian Averaging. Note that compilation is also performed using Nexus. The uncompiled circuits are sent and compiled circuits are retrieved. When all compiled circuits are obtained we can launch the execution job. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"protocol.build(vqe.final_parameters, ansatz, qubit_hamiltonian_jw, noise_mitigation=mitms_pmsv).compile_circuits()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "object",
"type": "unknown"
},
{
"name": "Qubits",
"rawType": "object",
"type": "unknown"
},
{
"name": "Depth",
"rawType": "object",
"type": "unknown"
},
{
"name": "Count",
"rawType": "object",
"type": "unknown"
},
{
"name": "Depth2q",
"rawType": "object",
"type": "unknown"
},
{
"name": "Count2q",
"rawType": "object",
"type": "unknown"
},
{
"name": "DepthCX",
"rawType": "object",
"type": "unknown"
},
{
"name": "CountCX",
"rawType": "object",
"type": "unknown"
},
{
"name": "Shots",
"rawType": "int64",
"type": "integer"
}
],
"ref": "56810d42-c08e-4f7c-bb7f-877cbfe42538",
"rows": [
[
"0",
"6",
"47",
"84",
"24",
"28",
"0",
"0",
"5000"
],
[
"1",
"6",
"46",
"80",
"24",
"27",
"0",
"0",
"5000"
],
[
"2",
"6",
"50",
"87",
"26",
"29",
"0",
"0",
"5000"
],
[
"3",
"6",
"46",
"85",
"24",
"28",
"0",
"0",
"5000"
],
[
"4",
"6",
"46",
"80",
"24",
"27",
"0",
"0",
"5000"
],
[
"5",
"6",
"40",
"74",
"20",
"24",
"0",
"0",
"5000"
],
[
"Sum",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"30000"
]
],
"shape": {
"columns": 8,
"rows": 7
}
},
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Qubits | \n",
" Depth | \n",
" Count | \n",
" Depth2q | \n",
" Count2q | \n",
" DepthCX | \n",
" CountCX | \n",
" Shots | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 6 | \n",
" 47 | \n",
" 84 | \n",
" 24 | \n",
" 28 | \n",
" 0 | \n",
" 0 | \n",
" 5000 | \n",
"
\n",
" \n",
" 1 | \n",
" 6 | \n",
" 46 | \n",
" 80 | \n",
" 24 | \n",
" 27 | \n",
" 0 | \n",
" 0 | \n",
" 5000 | \n",
"
\n",
" \n",
" 2 | \n",
" 6 | \n",
" 50 | \n",
" 87 | \n",
" 26 | \n",
" 29 | \n",
" 0 | \n",
" 0 | \n",
" 5000 | \n",
"
\n",
" \n",
" 3 | \n",
" 6 | \n",
" 46 | \n",
" 85 | \n",
" 24 | \n",
" 28 | \n",
" 0 | \n",
" 0 | \n",
" 5000 | \n",
"
\n",
" \n",
" 4 | \n",
" 6 | \n",
" 46 | \n",
" 80 | \n",
" 24 | \n",
" 27 | \n",
" 0 | \n",
" 0 | \n",
" 5000 | \n",
"
\n",
" \n",
" 5 | \n",
" 6 | \n",
" 40 | \n",
" 74 | \n",
" 20 | \n",
" 24 | \n",
" 0 | \n",
" 0 | \n",
" 5000 | \n",
"
\n",
" \n",
" Sum | \n",
" - | \n",
" - | \n",
" - | \n",
" - | \n",
" - | \n",
" - | \n",
" - | \n",
" 30000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Qubits Depth Count Depth2q Count2q DepthCX CountCX Shots\n",
"0 6 47 84 24 28 0 0 5000\n",
"1 6 46 80 24 27 0 0 5000\n",
"2 6 50 87 26 29 0 0 5000\n",
"3 6 46 85 24 28 0 0 5000\n",
"4 6 46 80 24 27 0 0 5000\n",
"5 6 40 74 20 24 0 0 5000\n",
"Sum - - - - - - - 30000"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"protocol.dataframe_circuit_shot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"circuits=protocol.get_circuits()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can examine the `circuits` object here, which is a list of NexusCircuits (as opposed to tket Circuits like usual). Not only does this contain a tket circuit, but it also contains information about the job and its submission"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[PhasedX(2.5, 0) q[0]; PhasedX(2.5, 0.5) q[1]; PhasedX(0.5, 0) q[2]; PhasedX(0.5, 0.5) q[3]; PhasedX(0.5, 0) q[4]; PhasedX(0.5, 0.5) q[5]; ZZPhase(0.5) q[2], q[0]; PhasedX(0.118823, 1.5) q[0]; PhasedX(2.11882, 1.5) q[2]; ZZPhase(0.5) q[2], q[0]; ZZPhase(0.5) q[4], q[0]; PhasedX(0.5, 0) q[2]; PhasedX(2.00139, 0.5) q[0]; ZZPhase(0.5) q[2], q[3]; PhasedX(2.00139, 1.5) q[4]; ZZPhase(0.5) q[4], q[0]; PhasedX(2.5, 1) q[2]; PhasedX(0.5, 0) q[3]; PhasedX(0.5, 0) q[0]; ZZPhase(0.5) q[3], q[2]; PhasedX(2.5, 0) q[4]; ZZPhase(0.5) q[0], q[1]; PhasedX(0.5, 0.5) q[2]; ZZPhase(0.5) q[4], q[5]; PhasedX(0.5, 0.5) q[0]; ZZPhase(0.5) q[2], q[1]; PhasedX(1, 0.5) q[4]; PhasedX(1.5, 0) q[5]; PhasedX(0.5, 0.5) q[1]; ZZPhase(0.5) q[1], q[4]; PhasedX(0.5, 0) q[4]; ZZPhase(0.5) q[4], q[0]; PhasedX(2, 0) q[0]; PhasedX(2, 0.5) q[4]; ZZPhase(0.5) q[4], q[0]; PhasedX(2.5, 0.5) q[0]; PhasedX(2.5, 0) q[4]; ZZPhase(0.5) q[1], q[4]; PhasedX(2.5, 0.5) q[1]; PhasedX(1, 1.5) q[4]; ZZPhase(0.5) q[2], q[1]; PhasedX(1.5, 0.5) q[1]; PhasedX(1.5, 1.5) q[2]; ZZPhase(0.5) q[3], q[2]; PhasedX(0.5, 0) q[3]; ZZPhase(0.5) q[4], q[3]; PhasedX(0.5, 1.5) q[3]; ZZPhase(0.5) q[3], q[2]; PhasedX(0.5, 0.5) q[2]; ZZPhase(0.5) q[2], q[5]; PhasedX(3.5, 0) q[5]; ZZPhase(0.5) q[5], q[1]; PhasedX(2, 1.5) q[1]; PhasedX(2, 1.5) q[5]; ZZPhase(0.5) q[5], q[1]; PhasedX(3.5, 0) q[1]; PhasedX(2.5, 1) q[5]; ZZPhase(0.5) q[2], q[5]; PhasedX(1.5, 1.5) q[2]; PhasedX(3.5, 1) q[5]; ZZPhase(0.5) q[0], q[5]; ZZPhase(0.5) q[3], q[2]; PhasedX(2.5, 0) q[0]; PhasedX(1.5, 0.5) q[3]; PhasedX(0.5, 0.5) q[5]; Measure q[5] --> c[5]; ZZPhase(0.5) q[4], q[3]; PhasedX(0.5, 0) q[4]; ZZPhase(0.5) q[1], q[4]; PhasedX(1.5, 0) q[1]; PhasedX(0.5, 1.5) q[4]; Measure q[4] --> c[4]; ZZPhase(0.5) q[0], q[1]; PhasedX(1.5, 0) q[0]; PhasedX(0.5, 1) q[1]; Measure q[1] --> c[1]; ZZPhase(0.5) q[0], q[2]; ZZPhase(0.5) q[0], q[3]; PhasedX(0.5, 0.5) q[2]; Measure q[2] --> c[2]; PhasedX(0.5, 1.5) q[0]; PhasedX(0.5, 1.5) q[3]; Measure q[0] --> c[0]; Measure q[3] --> c[3]; ]"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"circuits[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With the circuits returned, we can launch them for execution using `protocol.launch()`. This will tell Nexus to run the list of circuits in the protocol on the backend, returning a ResultsHandle for each circuit so that we may later retrieve them when our hardware/emulation is complete. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results_handles=protocol.launch()\n",
"#wait "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `result_handles` is a list of ResultHandle objects. These are made up of tuples of the job id and an enumerator. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(results_handles)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. e. Retrieve results from Nexus\n",
"\n",
"Results can be retrieved from Nexus using the computables \"retrieve_distributions\" function when they have completed. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results = protocol.retrieve(results_handles)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now our protocol is complete and we can examine and evaluate it! Firstly we take a peak at the results for the individual Pauli strings we measured for our hamiltonian and PMSV. Note that sample size is below 5000 has symmetry violating shots are discarded. Some Pauli strings have been measured by multiple circuits and so have more than 5000 samples. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "Pauli string",
"rawType": "object",
"type": "unknown"
},
{
"name": "Mean",
"rawType": "float64",
"type": "float"
},
{
"name": "Standard error",
"rawType": "float64",
"type": "float"
},
{
"name": "Sample size",
"rawType": "int64",
"type": "integer"
}
],
"ref": "34c60dbd-fd03-4323-ac30-d6f3f3d90889",
"rows": [
[
"0",
"Z1 Z5",
"-0.7362001240438288",
"0.009731819355757046",
"4837"
],
[
"1",
"Y1 Z3 Z4 Y5",
"-0.04238164151333471",
"0.014367012266026566",
"4837"
],
[
"2",
"Z2",
"0.7362001240438288",
"0.009731819355757046",
"4837"
],
[
"3",
"Y2 Y3 X4 X5",
"-0.012949039264828738",
"0.01445213043222715",
"4788"
],
[
"4",
"Z4",
"0.9987595617118048",
"0.0007160192734321476",
"4837"
],
[
"5",
"Y0 Z1 Z3 Y4",
"0.015037593984962405",
"0.014451707980036237",
"4788"
],
[
"6",
"X2 X3 Y4 Y5",
"-0.016618196925633568",
"0.01441226014096534",
"4814"
],
[
"7",
"X0 X1 Y2 Y3",
"0.6672206065641878",
"0.010736601071633125",
"4814"
],
[
"8",
"Y0 X1 X4 Y5",
"0.0047787242883856225",
"0.014415583691185016",
"4813"
],
[
"9",
"Z3 Z5",
"0.7355889724310777",
"0.00979110051994372",
"4788"
],
[
"10",
"X1 Z2 Z3 X5",
"-0.0427951209427331",
"0.014366758813796234",
"4837"
],
[
"11",
"X0 Z1 Z2 Z3 X4 Z5",
"-0.02778929904603899",
"0.0143967239905161",
"4822"
],
[
"12",
"X0 Z1 X2 X3 Z4 X5",
"0.005194265530853937",
"0.014415553820023264",
"4813"
],
[
"13",
"Y0 Z1 Z2 Z3 Y4 Z5",
"0.0012531328320802004",
"0.014453330885676536",
"4788"
],
[
"14",
"Y0 Z1 Z2 Y4",
"0.015037593984962405",
"0.014451707980036237",
"4788"
],
[
"15",
"X0 X1 Y4 Y5",
"0.02534275031159119",
"0.014409621074656934",
"4814"
],
[
"16",
"Z0 Z1",
"0.9970918155380141",
"0.0010985050555059523",
"4814"
],
[
"17",
"Z0 Z3",
"-0.9987595617118048",
"0.0007160192734321476",
"4837"
],
[
"18",
"X1 Z2 Z4 X5",
"-0.03411205292536696",
"0.014371563802239468",
"4837"
],
[
"19",
"X0 Y1 Y2 X3",
"-0.6430500727197175",
"0.011039927949884742",
"4813"
],
[
"20",
"X2 Y3 Y4 X5",
"-0.021815915229586536",
"0.014412317410847478",
"4813"
],
[
"21",
"X1 Z3 Z4 X5",
"-0.03411205292536696",
"0.014371563802239468",
"4837"
],
[
"22",
"Z5",
"0.997096640398175",
"0.001096683702564563",
"4822"
],
[
"23",
"Y1 Z2 Z4 Y5",
"-0.04238164151333471",
"0.014367012266026566",
"4837"
],
[
"24",
"X0 Z2 Z3 X4",
"-0.0012531328320802004",
"0.014453330885676536",
"4788"
],
[
"25",
"Z4 Z5",
"0.9970918155380141",
"0.0010985050555059523",
"4814"
],
[
"26",
"Y1 Z2 Z3 Y5",
"-0.034525532354765354",
"0.014371359629068183",
"4837"
],
[
"27",
"Y0 Z1 Y2 X3 Z4 X5",
"-0.01211361737677527",
"0.014452281755381146",
"4788"
],
[
"28",
"X0 Z1 Z3 X4",
"-0.0010388531061707874",
"0.01441574051376871",
"4813"
],
[
"29",
"Y1 Z2 Z3 Z4 Y5",
"-0.03411205292536696",
"0.014371563802239468",
"4837"
],
[
"30",
"Y0 X1 X2 Y3",
"-0.6644545831605143",
"0.010763240996801792",
"4822"
],
[
"31",
"Z0",
"-0.7349596857556336",
"0.00975118771067469",
"4837"
],
[
"32",
"Y1 Y2 X3 X4",
"-0.012547051442910916",
"0.01446127018591743",
"4782"
],
[
"33",
"Z3",
"0.7362001240438288",
"0.009731819355757046",
"4837"
],
[
"34",
"Y0 Z2 Z3 Y4",
"0.02778929904603899",
"0.0143967239905161",
"4822"
],
[
"35",
"Y2 X3 X4 Y5",
"-0.007518796992481203",
"0.014452933687852363",
"4788"
],
[
"36",
"Z2 Z5",
"0.7355889724310777",
"0.00979110051994372",
"4788"
],
[
"37",
"X0 Z1 Z2 Z3 X4",
"0.015037593984962405",
"0.014451707980036237",
"4788"
],
[
"38",
"Y0 Z1 Z2 Z3 Y4",
"-0.0010388531061707874",
"0.01441574051376871",
"4813"
],
[
"39",
"Z0 Z2",
"-0.9987595617118048",
"0.0007160192734321476",
"4837"
],
[
"40",
"Z1 Z2",
"-0.997096640398175",
"0.001096683702564563",
"4822"
],
[
"41",
"X0 Y1 Y4 X5",
"0.0047787242883856225",
"0.014415583691185016",
"4813"
],
[
"42",
"Z0 Y1 Z2 Z3 Z4 Y5",
"0.0427951209427331",
"0.014366758813796234",
"4837"
],
[
"43",
"Z1 Z3",
"-0.997096640398175",
"0.001096683702564563",
"4822"
],
[
"44",
"Y1 X2 X3 Y4",
"0.01783492326835338",
"0.014399995358212249",
"4822"
],
[
"45",
"Z2 Z4",
"0.7349596857556336",
"0.00975118771067469",
"4837"
],
[
"46",
"X1 X2 Y3 Y4",
"-0.017420157610949814",
"0.014400100673989575",
"4822"
],
[
"47",
"Y0 Y1 X4 X5",
"0.02534275031159119",
"0.014409621074656934",
"4814"
],
[
"48",
"X0 Z1 Z2 X4",
"-0.0010388531061707874",
"0.01441574051376871",
"4813"
],
[
"49",
"Y0 Y1 X2 X3",
"0.6651433319484836",
"0.010763347358838719",
"4814"
]
],
"shape": {
"columns": 4,
"rows": 61
}
},
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Pauli string | \n",
" Mean | \n",
" Standard error | \n",
" Sample size | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Z1 Z5 | \n",
" -0.736200 | \n",
" 0.009732 | \n",
" 4837 | \n",
"
\n",
" \n",
" 1 | \n",
" Y1 Z3 Z4 Y5 | \n",
" -0.042382 | \n",
" 0.014367 | \n",
" 4837 | \n",
"
\n",
" \n",
" 2 | \n",
" Z2 | \n",
" 0.736200 | \n",
" 0.009732 | \n",
" 4837 | \n",
"
\n",
" \n",
" 3 | \n",
" Y2 Y3 X4 X5 | \n",
" -0.012949 | \n",
" 0.014452 | \n",
" 4788 | \n",
"
\n",
" \n",
" 4 | \n",
" Z4 | \n",
" 0.998760 | \n",
" 0.000716 | \n",
" 4837 | \n",
"
\n",
" \n",
" 5 | \n",
" Y0 Z1 Z3 Y4 | \n",
" 0.015038 | \n",
" 0.014452 | \n",
" 4788 | \n",
"
\n",
" \n",
" 6 | \n",
" X2 X3 Y4 Y5 | \n",
" -0.016618 | \n",
" 0.014412 | \n",
" 4814 | \n",
"
\n",
" \n",
" 7 | \n",
" X0 X1 Y2 Y3 | \n",
" 0.667221 | \n",
" 0.010737 | \n",
" 4814 | \n",
"
\n",
" \n",
" 8 | \n",
" Y0 X1 X4 Y5 | \n",
" 0.004779 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 9 | \n",
" Z3 Z5 | \n",
" 0.735589 | \n",
" 0.009791 | \n",
" 4788 | \n",
"
\n",
" \n",
" 10 | \n",
" X1 Z2 Z3 X5 | \n",
" -0.042795 | \n",
" 0.014367 | \n",
" 4837 | \n",
"
\n",
" \n",
" 11 | \n",
" X0 Z1 Z2 Z3 X4 Z5 | \n",
" -0.027789 | \n",
" 0.014397 | \n",
" 4822 | \n",
"
\n",
" \n",
" 12 | \n",
" X0 Z1 X2 X3 Z4 X5 | \n",
" 0.005194 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 13 | \n",
" Y0 Z1 Z2 Z3 Y4 Z5 | \n",
" 0.001253 | \n",
" 0.014453 | \n",
" 4788 | \n",
"
\n",
" \n",
" 14 | \n",
" Y0 Z1 Z2 Y4 | \n",
" 0.015038 | \n",
" 0.014452 | \n",
" 4788 | \n",
"
\n",
" \n",
" 15 | \n",
" X0 X1 Y4 Y5 | \n",
" 0.025343 | \n",
" 0.014410 | \n",
" 4814 | \n",
"
\n",
" \n",
" 16 | \n",
" Z0 Z1 | \n",
" 0.997092 | \n",
" 0.001099 | \n",
" 4814 | \n",
"
\n",
" \n",
" 17 | \n",
" Z0 Z3 | \n",
" -0.998760 | \n",
" 0.000716 | \n",
" 4837 | \n",
"
\n",
" \n",
" 18 | \n",
" X1 Z2 Z4 X5 | \n",
" -0.034112 | \n",
" 0.014372 | \n",
" 4837 | \n",
"
\n",
" \n",
" 19 | \n",
" X0 Y1 Y2 X3 | \n",
" -0.643050 | \n",
" 0.011040 | \n",
" 4813 | \n",
"
\n",
" \n",
" 20 | \n",
" X2 Y3 Y4 X5 | \n",
" -0.021816 | \n",
" 0.014412 | \n",
" 4813 | \n",
"
\n",
" \n",
" 21 | \n",
" X1 Z3 Z4 X5 | \n",
" -0.034112 | \n",
" 0.014372 | \n",
" 4837 | \n",
"
\n",
" \n",
" 22 | \n",
" Z5 | \n",
" 0.997097 | \n",
" 0.001097 | \n",
" 4822 | \n",
"
\n",
" \n",
" 23 | \n",
" Y1 Z2 Z4 Y5 | \n",
" -0.042382 | \n",
" 0.014367 | \n",
" 4837 | \n",
"
\n",
" \n",
" 24 | \n",
" X0 Z2 Z3 X4 | \n",
" -0.001253 | \n",
" 0.014453 | \n",
" 4788 | \n",
"
\n",
" \n",
" 25 | \n",
" Z4 Z5 | \n",
" 0.997092 | \n",
" 0.001099 | \n",
" 4814 | \n",
"
\n",
" \n",
" 26 | \n",
" Y1 Z2 Z3 Y5 | \n",
" -0.034526 | \n",
" 0.014371 | \n",
" 4837 | \n",
"
\n",
" \n",
" 27 | \n",
" Y0 Z1 Y2 X3 Z4 X5 | \n",
" -0.012114 | \n",
" 0.014452 | \n",
" 4788 | \n",
"
\n",
" \n",
" 28 | \n",
" X0 Z1 Z3 X4 | \n",
" -0.001039 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 29 | \n",
" Y1 Z2 Z3 Z4 Y5 | \n",
" -0.034112 | \n",
" 0.014372 | \n",
" 4837 | \n",
"
\n",
" \n",
" 30 | \n",
" Y0 X1 X2 Y3 | \n",
" -0.664455 | \n",
" 0.010763 | \n",
" 4822 | \n",
"
\n",
" \n",
" 31 | \n",
" Z0 | \n",
" -0.734960 | \n",
" 0.009751 | \n",
" 4837 | \n",
"
\n",
" \n",
" 32 | \n",
" Y1 Y2 X3 X4 | \n",
" -0.012547 | \n",
" 0.014461 | \n",
" 4782 | \n",
"
\n",
" \n",
" 33 | \n",
" Z3 | \n",
" 0.736200 | \n",
" 0.009732 | \n",
" 4837 | \n",
"
\n",
" \n",
" 34 | \n",
" Y0 Z2 Z3 Y4 | \n",
" 0.027789 | \n",
" 0.014397 | \n",
" 4822 | \n",
"
\n",
" \n",
" 35 | \n",
" Y2 X3 X4 Y5 | \n",
" -0.007519 | \n",
" 0.014453 | \n",
" 4788 | \n",
"
\n",
" \n",
" 36 | \n",
" Z2 Z5 | \n",
" 0.735589 | \n",
" 0.009791 | \n",
" 4788 | \n",
"
\n",
" \n",
" 37 | \n",
" X0 Z1 Z2 Z3 X4 | \n",
" 0.015038 | \n",
" 0.014452 | \n",
" 4788 | \n",
"
\n",
" \n",
" 38 | \n",
" Y0 Z1 Z2 Z3 Y4 | \n",
" -0.001039 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 39 | \n",
" Z0 Z2 | \n",
" -0.998760 | \n",
" 0.000716 | \n",
" 4837 | \n",
"
\n",
" \n",
" 40 | \n",
" Z1 Z2 | \n",
" -0.997097 | \n",
" 0.001097 | \n",
" 4822 | \n",
"
\n",
" \n",
" 41 | \n",
" X0 Y1 Y4 X5 | \n",
" 0.004779 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 42 | \n",
" Z0 Y1 Z2 Z3 Z4 Y5 | \n",
" 0.042795 | \n",
" 0.014367 | \n",
" 4837 | \n",
"
\n",
" \n",
" 43 | \n",
" Z1 Z3 | \n",
" -0.997097 | \n",
" 0.001097 | \n",
" 4822 | \n",
"
\n",
" \n",
" 44 | \n",
" Y1 X2 X3 Y4 | \n",
" 0.017835 | \n",
" 0.014400 | \n",
" 4822 | \n",
"
\n",
" \n",
" 45 | \n",
" Z2 Z4 | \n",
" 0.734960 | \n",
" 0.009751 | \n",
" 4837 | \n",
"
\n",
" \n",
" 46 | \n",
" X1 X2 Y3 Y4 | \n",
" -0.017420 | \n",
" 0.014400 | \n",
" 4822 | \n",
"
\n",
" \n",
" 47 | \n",
" Y0 Y1 X4 X5 | \n",
" 0.025343 | \n",
" 0.014410 | \n",
" 4814 | \n",
"
\n",
" \n",
" 48 | \n",
" X0 Z1 Z2 X4 | \n",
" -0.001039 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 49 | \n",
" Y0 Y1 X2 X3 | \n",
" 0.665143 | \n",
" 0.010763 | \n",
" 4814 | \n",
"
\n",
" \n",
" 50 | \n",
" Z0 Z5 | \n",
" -0.732330 | \n",
" 0.009848 | \n",
" 4782 | \n",
"
\n",
" \n",
" 51 | \n",
" Z0 Z4 | \n",
" -0.736200 | \n",
" 0.009732 | \n",
" 4837 | \n",
"
\n",
" \n",
" 52 | \n",
" X1 Y2 Y3 X4 | \n",
" -0.005194 | \n",
" 0.014416 | \n",
" 4813 | \n",
"
\n",
" \n",
" 53 | \n",
" X0 Z1 X2 Y3 Z4 Y5 | \n",
" -0.009201 | \n",
" 0.014462 | \n",
" 4782 | \n",
"
\n",
" \n",
" 54 | \n",
" Y0 Z1 Y2 Y3 Z4 Y5 | \n",
" 0.024227 | \n",
" 0.014449 | \n",
" 4788 | \n",
"
\n",
" \n",
" 55 | \n",
" Z2 Z3 | \n",
" 1.000000 | \n",
" 0.000000 | \n",
" 28856 | \n",
"
\n",
" \n",
" 56 | \n",
" X1 Z2 Z3 Z4 X5 | \n",
" -0.042382 | \n",
" 0.014367 | \n",
" 4837 | \n",
"
\n",
" \n",
" 57 | \n",
" Z1 | \n",
" -0.735589 | \n",
" 0.009791 | \n",
" 4788 | \n",
"
\n",
" \n",
" 58 | \n",
" Z1 Z4 | \n",
" -0.732330 | \n",
" 0.009848 | \n",
" 4782 | \n",
"
\n",
" \n",
" 59 | \n",
" Z0 X1 Z2 Z3 Z4 X5 | \n",
" 0.034526 | \n",
" 0.014371 | \n",
" 4837 | \n",
"
\n",
" \n",
" 60 | \n",
" Z3 Z4 | \n",
" 0.734960 | \n",
" 0.009751 | \n",
" 4837 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Pauli string Mean Standard error Sample size\n",
"0 Z1 Z5 -0.736200 0.009732 4837\n",
"1 Y1 Z3 Z4 Y5 -0.042382 0.014367 4837\n",
"2 Z2 0.736200 0.009732 4837\n",
"3 Y2 Y3 X4 X5 -0.012949 0.014452 4788\n",
"4 Z4 0.998760 0.000716 4837\n",
"5 Y0 Z1 Z3 Y4 0.015038 0.014452 4788\n",
"6 X2 X3 Y4 Y5 -0.016618 0.014412 4814\n",
"7 X0 X1 Y2 Y3 0.667221 0.010737 4814\n",
"8 Y0 X1 X4 Y5 0.004779 0.014416 4813\n",
"9 Z3 Z5 0.735589 0.009791 4788\n",
"10 X1 Z2 Z3 X5 -0.042795 0.014367 4837\n",
"11 X0 Z1 Z2 Z3 X4 Z5 -0.027789 0.014397 4822\n",
"12 X0 Z1 X2 X3 Z4 X5 0.005194 0.014416 4813\n",
"13 Y0 Z1 Z2 Z3 Y4 Z5 0.001253 0.014453 4788\n",
"14 Y0 Z1 Z2 Y4 0.015038 0.014452 4788\n",
"15 X0 X1 Y4 Y5 0.025343 0.014410 4814\n",
"16 Z0 Z1 0.997092 0.001099 4814\n",
"17 Z0 Z3 -0.998760 0.000716 4837\n",
"18 X1 Z2 Z4 X5 -0.034112 0.014372 4837\n",
"19 X0 Y1 Y2 X3 -0.643050 0.011040 4813\n",
"20 X2 Y3 Y4 X5 -0.021816 0.014412 4813\n",
"21 X1 Z3 Z4 X5 -0.034112 0.014372 4837\n",
"22 Z5 0.997097 0.001097 4822\n",
"23 Y1 Z2 Z4 Y5 -0.042382 0.014367 4837\n",
"24 X0 Z2 Z3 X4 -0.001253 0.014453 4788\n",
"25 Z4 Z5 0.997092 0.001099 4814\n",
"26 Y1 Z2 Z3 Y5 -0.034526 0.014371 4837\n",
"27 Y0 Z1 Y2 X3 Z4 X5 -0.012114 0.014452 4788\n",
"28 X0 Z1 Z3 X4 -0.001039 0.014416 4813\n",
"29 Y1 Z2 Z3 Z4 Y5 -0.034112 0.014372 4837\n",
"30 Y0 X1 X2 Y3 -0.664455 0.010763 4822\n",
"31 Z0 -0.734960 0.009751 4837\n",
"32 Y1 Y2 X3 X4 -0.012547 0.014461 4782\n",
"33 Z3 0.736200 0.009732 4837\n",
"34 Y0 Z2 Z3 Y4 0.027789 0.014397 4822\n",
"35 Y2 X3 X4 Y5 -0.007519 0.014453 4788\n",
"36 Z2 Z5 0.735589 0.009791 4788\n",
"37 X0 Z1 Z2 Z3 X4 0.015038 0.014452 4788\n",
"38 Y0 Z1 Z2 Z3 Y4 -0.001039 0.014416 4813\n",
"39 Z0 Z2 -0.998760 0.000716 4837\n",
"40 Z1 Z2 -0.997097 0.001097 4822\n",
"41 X0 Y1 Y4 X5 0.004779 0.014416 4813\n",
"42 Z0 Y1 Z2 Z3 Z4 Y5 0.042795 0.014367 4837\n",
"43 Z1 Z3 -0.997097 0.001097 4822\n",
"44 Y1 X2 X3 Y4 0.017835 0.014400 4822\n",
"45 Z2 Z4 0.734960 0.009751 4837\n",
"46 X1 X2 Y3 Y4 -0.017420 0.014400 4822\n",
"47 Y0 Y1 X4 X5 0.025343 0.014410 4814\n",
"48 X0 Z1 Z2 X4 -0.001039 0.014416 4813\n",
"49 Y0 Y1 X2 X3 0.665143 0.010763 4814\n",
"50 Z0 Z5 -0.732330 0.009848 4782\n",
"51 Z0 Z4 -0.736200 0.009732 4837\n",
"52 X1 Y2 Y3 X4 -0.005194 0.014416 4813\n",
"53 X0 Z1 X2 Y3 Z4 Y5 -0.009201 0.014462 4782\n",
"54 Y0 Z1 Y2 Y3 Z4 Y5 0.024227 0.014449 4788\n",
"55 Z2 Z3 1.000000 0.000000 28856\n",
"56 X1 Z2 Z3 Z4 X5 -0.042382 0.014367 4837\n",
"57 Z1 -0.735589 0.009791 4788\n",
"58 Z1 Z4 -0.732330 0.009848 4782\n",
"59 Z0 X1 Z2 Z3 Z4 X5 0.034526 0.014371 4837\n",
"60 Z3 Z4 0.734960 0.009751 4837"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"protocol.dataframe_measurements()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we can evaluate our expectation value using the coefficients in our Hamiltonian. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"energy_nexus = protocol.evaluate_expectation_value(ansatz, qubit_hamiltonian_jw)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. f. Post-process classically to evaluate ground-state energy\n",
"\n",
"Below we perform a little analysis of our results."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Energy [Hamiltonian Averaging] on H1-1E via nexus: -38.35591669827696 Ha\n",
"Energy [Benchmark]: -38.3588270738749 Ha\n",
"\n",
"Correlation Energy [Hamiltonian Averaging] on H1-1E via nexus: 0.01782649475909892 Ha\n",
"Correlation Energy [Benchmark]: 0.02073687035704097 Ha\n",
"\n",
"Relative Error [Hamiltonian Averaging] on H1-1E via nexus: 0.007587238137260944 %\n",
"\n",
"Absolute Error [Hamiltonian Averaging] on H1-1E via nexus: 0.0029103755567518874 Ha\n"
]
}
],
"source": [
"import numpy\n",
"rel_error = (\n",
" 100\n",
" * numpy.absolute(vqe.final_value - energy_nexus)\n",
" / numpy.absolute(vqe.final_value)\n",
")\n",
"abs_error = numpy.absolute(vqe.final_value - energy_nexus)\n",
"correlation_energy_nexus = scf_energy - energy_nexus\n",
"\n",
"print(f\"Energy [Hamiltonian Averaging] on H1-1E via nexus: {energy_nexus} Ha\")\n",
"print(f\"Energy [Benchmark]: {ccsd_energy} Ha\")\n",
"print(\n",
" f\"\\nCorrelation Energy [Hamiltonian Averaging] on H1-1E via nexus: {correlation_energy_nexus} Ha\"\n",
")\n",
"print(f\"Correlation Energy [Benchmark]: {ccsd_correlation_energy} Ha\")\n",
"print(f\"\\nRelative Error [Hamiltonian Averaging] on H1-1E via nexus: {rel_error} %\")\n",
"print(f\"\\nAbsolute Error [Hamiltonian Averaging] on H1-1E via nexus: {abs_error} Ha\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For this small system we've got pretty good results. Our noisy backend averaging is 0.004 Ha from the statevector (noiseless) result when using 5000 shots and PMSV. This represents a relative error of about 0.01 % "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "11jun25_docs",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}