Skip to content

Commit f589e0a

Browse files
author
Abraham Asfaw
authored
Merge pull request #59 from manoelmarques/deprecate/aqua0.7
Remove Aqua Declarative API, Update import paths, Change to Machine Learning
2 parents 1cf11ad + 5d3bbd3 commit f589e0a

File tree

89 files changed

+2106
-5612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2106
-5612
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ aer/* @chriseclectic @attp @aasfaw @quantumjim @rraymondhp
99
ignis/* @dcmckayibm @yehuda-naveh @attp @aasfaw @quantumjim @rraymondhp
1010

1111
aqua/**/* @chunfuchen @pistoia @aasfaw
12-
artificial_intelligence/**/* @chunfuchen @pistoia @aasfaw
12+
machine_learning/**/* @chunfuchen @pistoia @aasfaw
1313
chemistry/**/* @chunfuchen @pistoia @aasfaw
1414
finance/**/* @chunfuchen @pistoia @aasfaw
1515
optimization/**/* @chunfuchen @pistoia @aasfaw

aqua/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ There are also Python code files too.
88

99
For more detail see the main [index](../index.ipynb#aqua)
1010

11-
## Input files
12-
13-
The folder [input_files](../input_files) contains a number of example json input files that can be loaded
14-
and run by the Qiskit Aqua [GUI](https://github.com/Qiskit/aqua/README.md#gui) or by the Qiskit Aqua
15-
[command line](https://github.com/Qiskit/aqua/README.md#command-line) tool.
16-
17-
1811
## Domains
1912

2013
Aqua provides a library of cross-domain algorithms upon which domain-specific applications and stacks can be
21-
built. Tutorials, sample code and sample input files may be found here for:
14+
built. Tutorials and sample code may be found here for:
2215

2316
* [Qiskit Chemistry](../chemistry)
2417
* [Qiskit Optimization](../optimization)
25-
* [Qiskit Artificial Intelligence](../artificial_intelligence)
18+
* [Qiskit Machine Learning](../machine_learning)
2619
* [Qiskit Finance](../finance)
2720

2821
More information may be found the [main index notebook](index.ipynb).

aqua/algorithm_introduction_with_vqe.ipynb

Lines changed: 24 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"\n",
1313
"Further information may be found for the algorithms in the online [Aqua documentation](https://qiskit.org/documentation/aqua/algorithms.html).\n",
1414
"\n",
15-
"Algorithms in Aqua can be created and run as usual in Python by constructing instances and calling methods. There is also a high level `run_algorithm` method that takes a configuration dictionary with data describing which algorithm to use, which components etc along with an InputInstance type to supply data to the algorithm. This latter approach is what we call `declarative` with the former, the regular Python way, `programmatic`. This tutorial will show both approaches.\n",
15+
"Algorithms in Aqua can be created and run as usual in Python by constructing instances and calling methods.\n",
1616
"\n",
1717
"Aqua has many `algorithms` for solving different problems. For some we also have classical algorithms, that take the exact same input data, to solve the problem. This can be useful in the near term as Quantum algorithms are developed since we are still at a stage where we can do classical comparison of the result.\n",
1818
"\n",
@@ -67,8 +67,6 @@
6767
"\n",
6868
"We can now use the Operator without regard to how it was created. We chose to start this tutorial with a classical algorithm as it involves a little less setting up than the `VQE` quantum algorithm we will use later. Here we will use `ExactEigensolver` to compute the minimum eigenvalue of the Operator (Hamiltonian).\n",
6969
"\n",
70-
"#### First let's show the `programmatic` approach.\n",
71-
"\n",
7270
"We construct an `ExactEigensolver` instance, passing in the Operator, and then call `run()` on in order to compute the result. All Aqua algorithms have the run method (it is defined by a base class which all algorithms extend) and while no parameters are need for classical algorithms a quantum algorithm will require a backend (quantum simulator or real device) on which it will be run. The `result` object returned is a dictionary. While the results fields can be different for algorithms solving different problems, and even within a given problem type there may be algorithm specific data returned, for a given problem the fields core to that problem are common across algorithms in order that different algorithms can be chosen to solve the same problem in a consistent fashion."
7371
]
7472
},
@@ -97,11 +95,16 @@
9795
"cell_type": "markdown",
9896
"metadata": {},
9997
"source": [
100-
"#### Now let's show the `declarative` approach. \n",
101-
"\n",
102-
"Here we need to prepare a configuration dictionary of parameters to define the algorithm. Again we we will use the ExactEigensolver and need to create an `algorithm` where it is named by `name`. The name comes from a `CONFIGURATION` dictionary in the algorithm and this name is registered to the Aqua discovery framework so we can load the corresponding class and run it during the exceution of `run_algorithm`. `run_algorithm` requires the configuration dictionary and input data passed via an InputInstance class. For an energy problem the data is supplied via an EnergyInput (extends InputInstance), other problem types have their own specific InputInstance. `run_algorithm` returns the same dictionary as above (internally it calls the run() method of the algorithm and passes back the result)\n",
98+
"### Lets switch now to using a Quantum algorithm.\n",
10399
"\n",
104-
"Note: there are other fields such `problem` that could have been added below. This field defaults to `energy`, which is what we want so it has been omitted. Defaults are convenient in the declarative form too as algorithms can define for both their properties as well as defaults for dependent components."
100+
"We will use the Variational Quantum Eigensolver (VQE) to solve the same problem as above. As its name implies its uses a variational approach. An ansatz (a variational form) is supplied and using a quantum/classical hybrid technique the energy resulting from evaluating the Operator with the variational form on a quantum backend is taken down to a minimum using a classical optimizer that varies the parameters of the variational form."
101+
]
102+
},
103+
{
104+
"cell_type": "markdown",
105+
"metadata": {},
106+
"source": [
107+
"Here we create the variational form and optimizer and then pass them to VQE along with the Operator. The backend is created and passed to the algorithm so it can be run there."
105108
]
106109
},
107110
{
@@ -113,87 +116,10 @@
113116
"name": "stdout",
114117
"output_type": "stream",
115118
"text": [
116-
"-1.8572750302023813\n"
119+
"-1.8572750302017973\n"
117120
]
118121
}
119122
],
120-
"source": [
121-
"from qiskit.aqua import run_algorithm\n",
122-
"from qiskit.aqua.input import EnergyInput\n",
123-
"\n",
124-
"aqua_cfg_dict = {\n",
125-
" 'algorithm': {\n",
126-
" 'name': 'ExactEigensolver'\n",
127-
" }\n",
128-
"}\n",
129-
"\n",
130-
"algo_input = EnergyInput(qubit_op)\n",
131-
"result = run_algorithm(aqua_cfg_dict, algo_input)\n",
132-
"print(result['energy'])"
133-
]
134-
},
135-
{
136-
"cell_type": "markdown",
137-
"metadata": {},
138-
"source": [
139-
"### Lets switch now to using a Quantum algorithm.\n",
140-
"\n",
141-
"We will use the Variational Quantum Eigensolver (VQE) to solve the same problem as above. As its name implies its uses a variational approach. An ansatz (a variational form) is supplied and using a quantum/classical hybrid technique the energy resulting from evaluating the Operator with the variational form on a quantum backend is taken down to a minimum using a classical optimizer that varies the parameters of the variational form.\n",
142-
"\n",
143-
"#### Lets do the `declarative` approach first this time\n",
144-
"\n",
145-
"In the description above we talked about `VQE` a `variational form` and an `optimizer`. We can now set this up as a dictionary. While we can omit them from the dictionary, such that defaults are used, here we specify them explicitly so we can set their parameters as we desire.\n",
146-
"\n",
147-
"As this is a quantum algorithm we need to specify a backend. Here we use the `statevector_simpulator` from the `qiskit.BasicAer` provider from `Qiskit Terra`. As this is a variational algorithm going from quantum to classical and looping until it finds a minimum it takes a few seconds. The result here is very close to our classical result above."
148-
]
149-
},
150-
{
151-
"cell_type": "code",
152-
"execution_count": null,
153-
"metadata": {
154-
"scrolled": true
155-
},
156-
"outputs": [],
157-
"source": [
158-
"aqua_cfg_dict = {\n",
159-
" 'algorithm': {\n",
160-
" 'name': 'VQE',\n",
161-
" 'operator_mode': 'matrix'\n",
162-
" },\n",
163-
" 'variational_form': {\n",
164-
" 'name': 'RYRZ',\n",
165-
" 'depth': 3,\n",
166-
" 'entanglement': 'linear'\n",
167-
" },\n",
168-
" 'optimizer': {\n",
169-
" 'name': 'L_BFGS_B',\n",
170-
" 'maxfun': 1000\n",
171-
" },\n",
172-
" 'backend': {\n",
173-
" 'name': 'statevector_simulator',\n",
174-
" 'provider': 'qiskit.BasicAer'\n",
175-
" }\n",
176-
"}\n",
177-
"\n",
178-
"algo_input = EnergyInput(qubit_op)\n",
179-
"result = run_algorithm(aqua_cfg_dict, algo_input)\n",
180-
"print(result['energy'])"
181-
]
182-
},
183-
{
184-
"cell_type": "markdown",
185-
"metadata": {},
186-
"source": [
187-
"#### And now `programmatic`\n",
188-
" \n",
189-
"Here we create the variational form and optimizer and then pass them to VQE along with the Operator. The backend is created and passed to the algorithm so it can be run there."
190-
]
191-
},
192-
{
193-
"cell_type": "code",
194-
"execution_count": null,
195-
"metadata": {},
196-
"outputs": [],
197123
"source": [
198124
"from qiskit import BasicAer\n",
199125
"from qiskit.aqua.algorithms import VQE\n",
@@ -212,14 +138,22 @@
212138
"cell_type": "markdown",
213139
"metadata": {},
214140
"source": [
215-
"While a backend can be passed directly to the quantum algorithm run(), internally it will be detected as such and wrapped as a QuantumInstance. However by doing this explicitly yourself, as below, various parameters governing the execution can be set, including in more advanced cases ability to set noise models, coupling maps etc. The following shows the above but using a QuantumInstance and setting up a default transpiler PassManager for circuit processing."
141+
"The following shows the above but using a QuantumInstance and setting up a default transpiler PassManager for circuit processing."
216142
]
217143
},
218144
{
219145
"cell_type": "code",
220-
"execution_count": null,
146+
"execution_count": 5,
221147
"metadata": {},
222-
"outputs": [],
148+
"outputs": [
149+
{
150+
"name": "stdout",
151+
"output_type": "stream",
152+
"text": [
153+
"-1.8572750301967933\n"
154+
]
155+
}
156+
],
223157
"source": [
224158
"from qiskit.aqua import QuantumInstance\n",
225159
"from qiskit.transpiler import PassManager\n",
@@ -239,7 +173,7 @@
239173
"source": [
240174
"### Concluding\n",
241175
"\n",
242-
"This completes an introduction to programming and using Aqua algorithms. There are plenty of other tutorials showing Aqua being used to solve other problems, including AI, Finance, Optimization and Chemistry. We encourage you to explore these further and see that various capabilities and techniques employed."
176+
"This completes an introduction to programming and using Aqua algorithms. There are plenty of other tutorials showing Aqua being used to solve other problems, including Machine Learning, Finance, Optimization and Chemistry. We encourage you to explore these further and see that various capabilities and techniques employed."
243177
]
244178
},
245179
{
@@ -266,7 +200,7 @@
266200
"name": "python",
267201
"nbconvert_exporter": "python",
268202
"pygments_lexer": "ipython3",
269-
"version": "3.6.8"
203+
"version": "3.7.4"
270204
}
271205
},
272206
"nbformat": 4,

aqua/bernstein_vazirani.ipynb

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"import math\n",
2323
"from qiskit import BasicAer\n",
2424
"from qiskit.aqua import QuantumInstance\n",
25-
"from qiskit.aqua import run_algorithm\n",
2625
"from qiskit.aqua.algorithms import BernsteinVazirani\n",
2726
"from qiskit.aqua.components.oracles import TruthTableOracle"
2827
]
@@ -143,50 +142,6 @@
143142
"print('The result bitstring computed using Bernstein-Vazirani is {}.'.format(result['result']))\n",
144143
"assert(result['result'] == a_bitstr)"
145144
]
146-
},
147-
{
148-
"cell_type": "markdown",
149-
"metadata": {},
150-
"source": [
151-
"The above step-by-step programatic approach can also be achieved by using a json configuration dictionary with the parameters for the algorithm and any other dependent objects it requires, as follows:"
152-
]
153-
},
154-
{
155-
"cell_type": "code",
156-
"execution_count": 6,
157-
"metadata": {
158-
"scrolled": true
159-
},
160-
"outputs": [
161-
{
162-
"name": "stdout",
163-
"output_type": "stream",
164-
"text": [
165-
"The result bitstring computed using Bernstein-Vazirani is 110.\n"
166-
]
167-
}
168-
],
169-
"source": [
170-
"params = {\n",
171-
" 'problem': {\n",
172-
" 'name': 'hiddenstringfinding',\n",
173-
" },\n",
174-
" 'algorithm': {\n",
175-
" 'name': 'BernsteinVazirani'\n",
176-
" },\n",
177-
" 'oracle': {\n",
178-
" 'name': 'TruthTableOracle',\n",
179-
" 'bitmaps': [bitstr]\n",
180-
" },\n",
181-
" 'backend': {\n",
182-
" 'shots': 1024,\n",
183-
" },\n",
184-
"}\n",
185-
"\n",
186-
"result_dict = run_algorithm(params, backend=backend)\n",
187-
"print('The result bitstring computed using Bernstein-Vazirani is {}.'.format(result_dict['result']))\n",
188-
"assert(result_dict['result'] == a_bitstr)"
189-
]
190145
}
191146
],
192147
"metadata": {
@@ -205,7 +160,7 @@
205160
"name": "python",
206161
"nbconvert_exporter": "python",
207162
"pygments_lexer": "ipython3",
208-
"version": "3.7.2"
163+
"version": "3.7.4"
209164
}
210165
},
211166
"nbformat": 4,

aqua/deutsch_jozsa.ipynb

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
"cell_type": "code",
1818
"execution_count": 1,
1919
"metadata": {},
20-
"outputs": [
21-
],
20+
"outputs": [],
2221
"source": [
2322
"from qiskit import BasicAer\n",
2423
"from qiskit.aqua import QuantumInstance\n",
25-
"from qiskit.aqua import run_algorithm\n",
2624
"from qiskit.aqua.algorithms import DeutschJozsa\n",
2725
"from qiskit.aqua.components.oracles import TruthTableOracle"
2826
]
@@ -105,50 +103,6 @@
105103
"print('The truth table {} represents a {} function.'.format(bitstr, result['result']))"
106104
]
107105
},
108-
{
109-
"cell_type": "markdown",
110-
"metadata": {},
111-
"source": [
112-
"The above step-by-step programatic approach can also be achieved by using a json configuration dictionary with the parameters for the algorithm and any other dependent objects it requires, as follows:"
113-
]
114-
},
115-
{
116-
"cell_type": "code",
117-
"execution_count": 5,
118-
"metadata": {
119-
"scrolled": true
120-
},
121-
"outputs": [
122-
{
123-
"name": "stdout",
124-
"output_type": "stream",
125-
"text": [
126-
"The truth table 11110000 represents a balanced function.\n"
127-
]
128-
}
129-
],
130-
"source": [
131-
"bitstr = '11110000'\n",
132-
"params = {\n",
133-
" 'problem': {\n",
134-
" 'name': 'functionevaluation',\n",
135-
" },\n",
136-
" 'algorithm': {\n",
137-
" 'name': 'DeutschJozsa'\n",
138-
" },\n",
139-
" 'oracle': {\n",
140-
" 'name': 'TruthTableOracle',\n",
141-
" 'bitmaps': [bitstr]\n",
142-
" },\n",
143-
" 'backend': {\n",
144-
" 'shots': 1024,\n",
145-
" },\n",
146-
"}\n",
147-
"\n",
148-
"result_dict = run_algorithm(params, backend=backend)\n",
149-
"print('The truth table {} represents a {} function.'.format(bitstr, result_dict['result']))"
150-
]
151-
},
152106
{
153107
"cell_type": "markdown",
154108
"metadata": {},
@@ -195,7 +149,7 @@
195149
"name": "python",
196150
"nbconvert_exporter": "python",
197151
"pygments_lexer": "ipython3",
198-
"version": "3.7.2"
152+
"version": "3.7.4"
199153
}
200154
},
201155
"nbformat": 4,

0 commit comments

Comments
 (0)