Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neural networks update #5

Merged
merged 11 commits into from
Mar 11, 2021
Merged

Conversation

adekusar-drl
Copy link
Collaborator

@adekusar-drl adekusar-drl commented Mar 9, 2021

Summary

New implementations of QNNs.

Details and comments

This includes:

  • A base class NeuralNetwork
  • Sampling NN, a base class for networks that generate samples
  • CircuitQNN based on an arbitrary circuit
  • OpflowQNN a network based on opflow
  • TwoLayerQNN consisting of a feature map, a variational form, and an observable.

Authored by @stefan-woerner, edited by @adekusar-drl.

stefan-woerner
stefan-woerner previously approved these changes Mar 11, 2021
Copy link
Contributor

@stefan-woerner stefan-woerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me for initial commit. We can then adjust sparse logic, add batching, etc. in separate PRs.

@adekusar-drl adekusar-drl marked this pull request as ready for review March 11, 2021 18:34
@adekusar-drl adekusar-drl changed the title [WIP] Neural networks update Neural networks update Mar 11, 2021
"""Initializes the Circuit Quantum Neural Network.

Args:
circuit: The (parametrized) quantum circuit that generates the samples of this network.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameterized is in () as this optional, ie the circuit is a Circuit and can optionally be parameterized. If so then input_params and weight params needs to be defined, such that the total set of params there match what the circuit needs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now parameterized is not in (). Circuit should be parameterized, otherwise it does not make much sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it does make sense, you can use the circuit in a pytorch setting and train a classical NN based on the samples.

Comment on lines +87 to +89
# TODO this should not be necessary... but currently prop grads fail otherwise
from qiskit import Aer
self._sampler = CircuitSampler(Aer.get_backend('statevector_simulator'), param_qobj=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, hopefully we don't need that. If there was any need to do something we should use BasicAer since Aer is still really an optional install and not part of Qiskit core (i.e. Terra)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency on Aer is removed.

QiskitMachineLearningError: Invalid parameter values.
"""
if num_inputs < 0:
raise QiskitMachineLearningError('Number of inputs cannot be negative!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its always nice to have the invalid value etc in these error messages of course.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added invalid values to the messages.

"""Initializes the Opflow Quantum Neural Network.

Args:
operator: The parametrized operator that represents the neural network.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not have parameterized in () - but given the following params default to None I guess though this is analgous to the circuit based ine

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the circuits.

self.quantum_instance,
param_qobj=is_aer_provider(self.quantum_instance.backend)
)
# TODO: replace by extended caching in circuit sampler after merged: "caching='all'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI This has been merged already Qiskit/qiskit#5934

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now make use of caching="all".

@adekusar-drl adekusar-drl merged commit 1950083 into qiskit-community:master Mar 11, 2021
@adekusar-drl adekusar-drl deleted the nn branch April 5, 2021 12:59
gentinettagian pushed a commit to gentinettagian/qiskit-machine-learning that referenced this pull request Dec 14, 2021
* moving to public

* mypy, spell, other fixes

* more on sphinx

* more on sphinx

* more on sphinx

* fix docs

* type hints

* fix mypy

Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Co-authored-by: Stefan Woerner <WOR@zurich.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants