Skip to content

Commit

Permalink
Merge pull request qiskit-community#90 from manoelmarques/aqua0.8
Browse files Browse the repository at this point in the history
Fix Aqua Notebook Errors for release 0.8.0
  • Loading branch information
woodsp-ibm authored Oct 19, 2020
2 parents 7b5c4ce + 3120abe commit 6de54e7
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 184 deletions.
36 changes: 14 additions & 22 deletions aqua/evolution.ipynb

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions aqua/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"### 5. [Qiskit Finance](../finance/)<a id='finance'></a>\n",
"\n",
"Qiskit Finance is a set of tools, algorithms and software for use with quantum computers to carry out research and investigate how to take advantage of quantum computing power to solve problems in the financial domain.\n",
"Please also see the [Qiskit Finance Tutorials](https://github.com/Qiskit/qiskit-iqx-tutorials/tree/master/qiskit/advanced/aqua/finance/index.ipynb) for more examples.\n",
"Please also see the [Qiskit Finance Tutorials](https://github.com/Qiskit/qiskit-tutorials/tree/master/tutorials/finance) for more examples.\n",
"\n",
"Quantum computing for option pricing:\n",
"* <a href=\"../finance/simulation/long_butterfly.ipynb\">Long Butterfly</a> (univariate, payoff with 4 segments)\n",
Expand All @@ -87,9 +87,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
}
Expand All @@ -110,7 +108,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.9"
}
},
"nbformat": 4,
Expand Down
153 changes: 86 additions & 67 deletions aqua/simulations_with_noise_and_measurement_error_mitigation.ipynb

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions chemistry/LiH_with_qubit_tapering_and_uccsd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,16 @@
"outputs": [],
"source": [
"# setup initial state\n",
"init_state = HartreeFock(num_qubits=the_tapered_op.num_qubits, num_orbitals=core._molecule_info['num_orbitals'],\n",
"init_state = HartreeFock(num_orbitals=core._molecule_info['num_orbitals'],\n",
" qubit_mapping=core._qubit_mapping, two_qubit_reduction=core._two_qubit_reduction,\n",
" num_particles=core._molecule_info['num_particles'], sq_list=the_tapered_op.z2_symmetries.sq_list)\n",
"\n",
"# setup variationl form\n",
"var_form = UCCSD(num_qubits=the_tapered_op.num_qubits, depth=1,\n",
" num_orbitals=core._molecule_info['num_orbitals'], \n",
" num_particles=core._molecule_info['num_particles'],\n",
" active_occupied=None, active_unoccupied=None, initial_state=init_state,\n",
" qubit_mapping=core._qubit_mapping, two_qubit_reduction=core._two_qubit_reduction, \n",
" num_time_slices=1, z2_symmetries=the_tapered_op.z2_symmetries)\n",
"var_form = UCCSD(num_orbitals=core._molecule_info['num_orbitals'], \n",
" num_particles=core._molecule_info['num_particles'],\n",
" active_occupied=None, active_unoccupied=None, initial_state=init_state,\n",
" qubit_mapping=core._qubit_mapping, two_qubit_reduction=core._two_qubit_reduction, \n",
" num_time_slices=1, z2_symmetries=the_tapered_op.z2_symmetries)\n",
"\n",
"# setup optimizer\n",
"optimizer = COBYLA(maxiter=1000)\n",
Expand Down Expand Up @@ -289,15 +288,15 @@
"text": [
"=== GROUND STATE ENERGY ===\n",
" \n",
"* Electronic ground state energy (Hartree): -8.874303856889\n",
" - computed part: -1.078084288118\n",
"* Electronic ground state energy (Hartree): -8.874303841496\n",
" - computed part: -1.078084272725\n",
" - frozen energy part: -7.796219568771\n",
" - particle hole part: 0.0\n",
"~ Nuclear repulsion energy (Hartree): 0.992207270475\n",
"> Total ground state energy (Hartree): -7.882096586414\n",
"> Total ground state energy (Hartree): -7.882096571021\n",
"The parameters for UCCSD are:\n",
"[ 0.03815735 0.00366554 0.03827111 0.00369737 -0.03604811 0.0594364\n",
" -0.02741369 -0.02735108 0.05956488 -0.11497243]\n"
"[ 0.03803094 0.00360661 0.0382837 0.00369849 -0.03608325 0.05942172\n",
" -0.02729715 -0.02732059 0.05965191 -0.11498381]\n"
]
}
],
Expand Down
18 changes: 9 additions & 9 deletions chemistry/adaptive_VQE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"source": [
"# setup the initial state for the variational form\n",
"from qiskit.chemistry.components.initial_states import HartreeFock\n",
"init_state = HartreeFock(num_qubits, num_spin_orbitals, num_particles)\n",
"init_state = HartreeFock(num_spin_orbitals, num_particles)\n",
"\n",
"# set the backend for the quantum computation=\n",
"backend = BasicAer.get_backend('statevector_simulator')\n",
Expand Down Expand Up @@ -144,7 +144,7 @@
"source": [
"# setup the variational form for VQE\n",
"from qiskit.chemistry.components.variational_forms import UCCSD\n",
"var_form = UCCSD(num_qubits, 1, num_spin_orbitals, num_particles, initial_state=init_state)\n",
"var_form = UCCSD(num_spin_orbitals, num_particles, initial_state=init_state)\n",
"from qiskit.aqua.algorithms import VQE\n",
"algorithm = VQE(qubitOp, var_form, optimizer)\n",
"result = algorithm.run(backend)"
Expand All @@ -166,7 +166,7 @@
},
"outputs": [],
"source": [
"var_form_base = UCCSD(num_qubits, 1, num_spin_orbitals, num_particles, initial_state=init_state)\n",
"var_form_base = UCCSD(num_spin_orbitals, num_particles, initial_state=init_state)\n",
"\n",
"from qiskit.chemistry.algorithms import VQEAdapt\n",
"algorithm = VQEAdapt(qubitOp, var_form_base, optimizer, threshold=0.00001, delta=0.1)\n",
Expand All @@ -190,12 +190,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------+-------------------+----------------------------------------------+\n",
"| Ansatz | Energy (Hartree) | Gates |\n",
"+-----------+-------------------+----------------------------------------------+\n",
"| UCCSD | -1.85727503020237 | OrderedDict([('Evolution^1', 3), ('u3', 1)]) |\n",
"| ADAPT-VQE | -1.85727503020237 | OrderedDict([('u3', 1), ('Evolution^1', 1)]) |\n",
"+-----------+-------------------+----------------------------------------------+\n"
"+-----------+---------------------+----------------------------------------------+\n",
"| Ansatz | Energy (Hartree) | Gates |\n",
"+-----------+---------------------+----------------------------------------------+\n",
"| UCCSD | -1.8572750302023762 | OrderedDict([('Evolution^1', 3), ('u3', 1)]) |\n",
"| ADAPT-VQE | -1.8572750302023793 | OrderedDict([('u3', 1), ('Evolution^1', 1)]) |\n",
"+-----------+---------------------+----------------------------------------------+\n"
]
}
],
Expand Down
66 changes: 37 additions & 29 deletions chemistry/h2_eom_excited_states.ipynb

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions machine_learning/custom_feature_map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@
"import functools\n",
"\n",
"from qiskit import BasicAer\n",
"from qiskit.circuit.library import ZFeatureMap,ZZFeatureMap, PauliFeatureMap\n",
"from qiskit.circuit.library import ZZFeatureMap, PauliFeatureMap\n",
"from qiskit.aqua import QuantumInstance\n",
"from qiskit.aqua.components.feature_maps import self_product\n",
"from qiskit.aqua.algorithms import QSVM\n",
"from qiskit.ml.datasets import ad_hoc_data"
]
Expand All @@ -83,15 +82,16 @@
"source": [
"# Generate synthetic training and test sets from the SecondOrderExpansion quantum feature map\n",
"feature_dim = 2\n",
"sample_Total, training_dataset, test_dataset, class_labels = ad_hoc_data(training_size=20, test_size=10,\n",
" n=feature_dim, gap=0.3,\n",
" plot_data=False)\n",
"sample_Total, training_dataset, test_dataset, class_labels = ad_hoc_data(training_size=10, \n",
" test_size=5,\n",
" n=feature_dim, \n",
" gap=0.3)\n",
"\n",
"# Using the statevector simulator\n",
"backend = BasicAer.get_backend('statevector_simulator')\n",
"random_seed = 10598\n",
"\n",
"quantum_instance = QuantumInstance(backend, seed_simulator=random_seed, seed_transpiler=random_seed)"
"quantum_instance = QuantumInstance(backend, shots=1024, seed_simulator=random_seed, seed_transpiler=random_seed)"
]
},
{
Expand All @@ -117,11 +117,7 @@
"\n",
"- `feature_dimension`: dimensionality of the classical data (equal to the number of required qubits)\n",
"- `reps`: number of times $d$ to repeat the feature map circuit \n",
"- `data_map_func`: function $\\phi_S(\\mathbf{x})$ encoding the classical data.\n",
"\n",
"The default setting `data_map_func = self_product` for the `ZFeatureMap` has $S = \\{i\\}$ and is given by \n",
"\n",
"$$\\phi_S:x\\mapsto x_i.$$\n"
"- `data_map_func`: function $\\phi_S(\\mathbf{x})$ encoding the classical data."
]
},
{
Expand All @@ -133,13 +129,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"testing success ratio: 0.8\n"
"testing success ratio: 1.0\n"
]
}
],
"source": [
"# Generate the feature map\n",
"feature_map = ZFeatureMap(feature_dimension=feature_dim, reps=2)\n",
"feature_map = ZZFeatureMap(feature_dimension=feature_dim, reps=2, entanglement='linear')\n",
"\n",
"# Run the Quantum Kernel Estimator and classify the test data\n",
"qsvm = QSVM(feature_map=feature_map, training_dataset=training_dataset, test_dataset=test_dataset)\n",
Expand Down Expand Up @@ -313,7 +309,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"testing success ratio: 0.65\n"
"testing success ratio: 0.5\n"
]
}
],
Expand Down Expand Up @@ -358,7 +354,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"testing success ratio: 0.65\n"
"testing success ratio: 0.45\n"
]
}
],
Expand Down Expand Up @@ -466,7 +462,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/manoel/anaconda3/envs/QiskitenvProd/lib/python3.7/site-packages/ipykernel_launcher.py:3: DeprecationWarning: \n",
"/Users/manoel/anaconda3/envs/Qiskitenv/lib/python3.7/site-packages/ipykernel_launcher.py:3: DeprecationWarning: \n",
" The <class '__main__.CustomFeatureMap'> object as input for the QSVM is deprecated as of 0.7.0 and will\n",
" be removed no earlier than 3 months after the release.\n",
" You should pass a QuantumCircuit object instead.\n",
Expand All @@ -479,7 +475,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"testing success ratio: 0.55\n"
"testing success ratio: 0.6\n"
]
}
],
Expand Down
16 changes: 8 additions & 8 deletions machine_learning/qsvm_multiclass.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions optimization/3-Coloring Oracle via Reduction to SAT.ipynb

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions optimization/vertex_cover.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[0. 4. 5.]\n",
" [4. 0. 3.]\n",
" [5. 3. 0.]]\n"
"[[ 0. 5. -4.]\n",
" [ 5. 0. 0.]\n",
" [-4. 0. 0.]]\n"
]
}
],
Expand Down Expand Up @@ -66,7 +66,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Size of the vertex cover 2\n"
"Size of the vertex cover 1\n"
]
}
],
Expand Down Expand Up @@ -120,7 +120,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Size of the vertex cover 2\n"
"[1 0 0]\n",
"Size of the vertex cover 1\n"
]
}
],
Expand All @@ -130,7 +131,7 @@
"\n",
"x = sample_most_likely(result.eigenstate)\n",
"sol = vertex_cover.get_graph_solution(x)\n",
"np.testing.assert_array_equal(sol, [0, 1, 1])\n",
"print(sol)\n",
"print('Size of the vertex cover', np.count_nonzero(sol))"
]
},
Expand All @@ -150,7 +151,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Size of the vertex cover 2\n"
"Size of the vertex cover 1\n"
]
}
],
Expand All @@ -162,7 +163,7 @@
"\n",
"aqua_globals.random_seed = 100\n",
"\n",
"optimizer = SPSA(max_trials=200)\n",
"optimizer = SPSA(maxiter=200)\n",
"var_form = TwoLocal(qubit_op.num_qubits, ['ry', 'rz'], 'cz', reps=3)\n",
"vqe = VQE(qubit_op, var_form, optimizer)\n",
"\n",
Expand Down

0 comments on commit 6de54e7

Please sign in to comment.