forked from qiskit-community/qiskit-machine-learning
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify SamplerQNN and EstimatorQNN interfaces with QNNCircuit (qisk…
…it-community#609) * init set up & QNNCircuit instance gate * extend documentation & release notes * add tests & extend docu. * update parity function to pass pylint E0012 * omitt QNNCircuit type hint & different wording in documentation * add quotation marks for property names in estimator_qnn.py Co-authored-by: Anton Dekusar <[email protected]> * add quotation marks for property names in sampler_qnn.py Co-authored-by: Anton Dekusar <[email protected]> * add quotation marks for weight_params in estimator_qnn.py Co-authored-by: Anton Dekusar <[email protected]> * add quotation marks for weight_params in sampler_qnn.py Co-authored-by: Anton Dekusar <[email protected]> * add quotation marks for input_params in sampler_qnn.py Co-authored-by: Anton Dekusar <[email protected]> * add quotation marks for input_params in estimator_qnn.py Co-authored-by: Anton Dekusar <[email protected]> --------- Co-authored-by: Anton Dekusar <[email protected]>
- Loading branch information
1 parent
410d212
commit 10aa219
Showing
5 changed files
with
233 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
releasenotes/notes/add-qnn-circuit-to-qnns-2e0edc76f4893fdd.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
features: | ||
- | | ||
The :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` class can be passed as circuit | ||
to the :class:`~qiskit_machine_learning.neural_networks.SamplerQNN` | ||
and :class:`~qiskit_machine_learning.neural_networks.EstimatorQNN`. | ||
This simplifies the interfaces to build a :class:`~qiskit.primitives.Sampler` or | ||
:class:`~qiskit.primitives.Estimator` based neural network implementation from a feature map | ||
and an ansatz circuit. | ||
Using the :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` comes with the benefit | ||
that the feature map and ansatz do not have to be composed explicitly. | ||
If a :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is passed to the | ||
:class:`~qiskit_machine_learning.neural_networks.SamplerQNN` or | ||
:class:`~qiskit_machine_learning.neural_networks.EstimatorQNN` the input and weight parameters | ||
do not have to be provided, because these two properties are taken | ||
from the :class:`~qiskit_machine_learning.circuit.library.QNNCircuit`. | ||
An example of using :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` with the | ||
:class:`~qiskit_machine_learning.neural_networks.SamplerQNN` class is as follows: | ||
.. code-block:: python | ||
from qiskit_machine_learning.circuit.library import QNNCircuit | ||
from qiskit_machine_learning.neural_networks import SamplerQNN | ||
def parity(x): | ||
return f"{bin(x)}".count("1") % 2 | ||
# Create a parameterized 2 qubit circuit composed of the default ZZFeatureMap feature map | ||
# and RealAmplitudes ansatz. | ||
qnn_qc = QNNCircuit(num_qubits = 2) | ||
qnn = SamplerQNN( | ||
circuit=qnn_qc, | ||
interpret=parity, | ||
output_shape=2 | ||
) | ||
qnn.forward(input_data=[1, 2], weights=[1, 2, 3, 4, 5, 6, 7, 8]) | ||
The :class:`~qiskit_machine_learning.circuit.library.QNNCircuit` is used with the | ||
:class:`~qiskit_machine_learning.neural_networks.EstimatorQNN` class in the same fashion: | ||
.. code-block:: python | ||
from qiskit_machine_learning.circuit.library import QNNCircuit | ||
from qiskit_machine_learning.neural_networks import EstimatorQNN | ||
# Create a parameterized 2 qubit circuit composed of the default ZZFeatureMap feature map | ||
# and RealAmplitudes ansatz. | ||
qnn_qc = QNNCircuit(num_qubits = 2) | ||
qnn = EstimatorQNN( | ||
circuit=qnn_qc | ||
) | ||
qnn.forward(input_data=[1, 2], weights=[1, 2, 3, 4, 5, 6, 7, 8]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.