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

Fix vqc initialisation with default parameters #248

Merged
merged 7 commits into from
Nov 2, 2021

Conversation

jonvet
Copy link
Contributor

@jonvet jonvet commented Oct 25, 2021

Summary

Fixes #217 where VQC couldn't be instantiated unless either feature_map or ansatz were provided. VQC is now instantiated with the default feature_map and/or ansatz.

Details and comments

Changelog: Bugfix

jonvet added 2 commits October 25, 2021 23:32
Fixes qiskit-community#217 where ```VQC``` couldn't be instantiated unless either ```feature_map``` or ```ansatz``` were provided. ```VQC``` is now instantiated with the default ```feature_map``` and/or ```ansatz```.

Changelog: Bugfix
Fixes qiskit-community#217 where ```VQC``` couldn't be instantiated unless either ```feature_map``` or ```ansatz``` were provided. ```VQC``` is now instantiated with the default ```feature_map``` and/or ```ansatz```.

Changelog: Bugfix
Copy link
Collaborator

@adekusar-drl adekusar-drl left a comment

Choose a reason for hiding this comment

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

Thanks a lot, looks good! Nice to see you are back. I left just minor comments. Could you please take a quick look if VQR does not have the same problem.

Comment on lines +142 to +148
# pylint: disable=invalid-name
X = algorithm_globals.random.random((num_samples, num_inputs))
y = 1.0 * (np.sum(X, axis=1) <= 1)
while len(np.unique(y)) == 1:
X = algorithm_globals.random.random((num_samples, num_inputs))
y = 1.0 * (np.sum(X, axis=1) <= 1)
y = np.array([y, 1 - y]).transpose() # VQC requires one-hot encoded input
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, this snippet is everywhere, datasets should be organized in a better way. But this is not a request to this PR.

@jonvet
Copy link
Contributor Author

jonvet commented Oct 31, 2021

Thanks a lot, looks good! Nice to see you are back. I left just minor comments. Could you please take a quick look if VQR does not have the same problem.

thanks @adekusar-drl

I checked and VQR doesn't have the problem, you can instantiate it with vqr = VQR(num_qubits=4) without problems.

The behaviour of the init method is very different though. In the init method of VQC we create a quantum circuit and then a CircuitQNN. But the init method of VQR just creates a TwoLayerQNN (which handles the case that was a problem here, where no ansatz or feature map were provided). Is it intentional that VQC and VQR are initialised differently or should they be made more similar?

@adekusar-drl
Copy link
Collaborator

I checked and VQR doesn't have the problem, you can instantiate it with vqr = VQR(num_qubits=4) without problems.

The behaviour of the init method is very different though. In the init method of VQC we create a quantum circuit and then a CircuitQNN. But the init method of VQR just creates a TwoLayerQNN (which handles the case that was a problem here, where no ansatz or feature map were provided). Is it intentional that VQC and VQR are initialised differently or should they be made more similar?

Oh, thanks for looking into this, all correct!

@adekusar-drl adekusar-drl merged commit 1baf45c into qiskit-community:main Nov 2, 2021
gentinettagian pushed a commit to gentinettagian/qiskit-machine-learning that referenced this pull request Dec 14, 2021
* Summary:
Fixes qiskit-community#217 where ```VQC``` couldn't be instantiated unless either ```feature_map``` or ```ansatz``` were provided. ```VQC``` is now instantiated with the default ```feature_map``` and/or ```ansatz```.

Changelog: Bugfix

* Summary:
Fixes qiskit-community#217 where ```VQC``` couldn't be instantiated unless either ```feature_map``` or ```ansatz``` were provided. ```VQC``` is now instantiated with the default ```feature_map``` and/or ```ansatz```.

Changelog: Bugfix

* add docstring to test

* Update releasenotes/notes/fix-vqc-initialisation-bdf753c45b66f192.yaml

Co-authored-by: Anton Dekusar <[email protected]>

Co-authored-by: jonvet <[email protected]>
Co-authored-by: Manoel Marques <[email protected]>
Co-authored-by: Anton Dekusar <[email protected]>
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.

VQC fails to initialize from minimal settings
3 participants