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

VQC fails to initialize from minimal settings #217

Closed
woodsp-ibm opened this issue Sep 14, 2021 · 2 comments · Fixed by #248
Closed

VQC fails to initialize from minimal settings #217

woodsp-ibm opened this issue Sep 14, 2021 · 2 comments · Fixed by #248
Assignees
Labels
priority: medium type: bug 🐞 Something isn't working

Comments

@woodsp-ibm
Copy link
Member

This problem was brought up here https://qiskit.slack.com/archives/CB6C24TPB/p1631635618251500

The following should create a VQC instance with default feature map and ansatz.

from qiskit_machine_learning.algorithms.classifiers import VQC
vqc = VQC(num_qubits=4)

however it fails with

  File qiskit_machine_learning\algorithms\classifiers\vqc.py", line 107, in __init__
    self._circuit.compose(feature_map, inplace=True)
  File qiskit\circuit\quantumcircuit.py", line 727, in compose
    qubits = list(range(other.num_qubits))
AttributeError: 'NoneType' object has no attribute 'num_qubits'

It seems to be from this logic https://github.com/Qiskit/qiskit-machine-learning/blob/673140c0624ad928ec1b6da307e58221847c48da/qiskit_machine_learning/algorithms/classifiers/vqc.py#L106-L108

where the latter tries to compose feature_map and ansatz, which are directly the params from init. I think more likely it should be using self.feature_map and self.ansatz to pull in whatever these ended up as, whether supplied or internally created.

Needs some unit tests to cover the various paths whether defaulted or not.

@woodsp-ibm woodsp-ibm added the type: bug 🐞 Something isn't working label Sep 14, 2021
@jonvet
Copy link
Contributor

jonvet commented Oct 10, 2021

mind if I take this?

@woodsp-ibm
Copy link
Member Author

@jonvet Sure, I assigned it to you

jonvet pushed a commit to jonvet/qiskit-machine-learning that referenced this issue Oct 25, 2021
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
jonvet pushed a commit to jonvet/qiskit-machine-learning that referenced this issue Oct 25, 2021
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
adekusar-drl added a commit that referenced this issue Nov 2, 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```.

Changelog: Bugfix

* 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```.

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]>
gentinettagian pushed a commit to gentinettagian/qiskit-machine-learning that referenced this issue 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
priority: medium type: bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants