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

Support b.num_qubits for BackendV2 Qiskit objects #332

Closed
JMuff22 opened this issue Sep 5, 2023 · 3 comments · Fixed by #514
Closed

Support b.num_qubits for BackendV2 Qiskit objects #332

JMuff22 opened this issue Sep 5, 2023 · 3 comments · Fixed by #514
Milestone

Comments

@JMuff22
Copy link

JMuff22 commented Sep 5, 2023

My feature request is related to a problem of using Qiskit backends which only support BackendV2 objects and don't support backwards compatibility for BackendV1. This is described in the Qiskit documentation.

The current issue is that when running with such a backend fails at this line due to calling b.configuration().n_qubits , for which the Backend object has no configuration() method. The solution would be to use backend.num_qubits.

The solution is not simple however, because many of the tests and backends support by pennylane-qiskit have the opposite functionality in that they don't support BackendV2 and backend.num_qubits cannot be called. The solution should support both BackendV1 and BackendV2 via backend.configuration().n_qubits and backend.num_qubits.

I tried this solution but I considered it hacky.

    def validate_wires_against_backend(self):
        b = self.backend
        
        try:
            num_qubits = int(b.configuration().n_qubits)
        except AttributeError:
            try:
                num_qubits = int(b.num_qubits)
            except AttributeError:
                raise AttributeError("Neither 'b.configuration().n_qubits' nor 'b.num_qubits' exist.")
                
        if len(self.wires) > num_qubits:
            raise ValueError(f"Backend '{b}' supports a maximum of {num_qubits} wires.")

Thanks!

The particular backend I am trying to use is IQMBackend.

@CatalinaAlbornoz
Copy link

Hi @JMuff22, thank you very much for opening this feature request! It's very helpful for us to improve the plugin.

By the way, we have a new PennyLane survey. We would love to know your thoughts about PennyLane in order to keep bringing you amazing features ✨.

@JMuff22
Copy link
Author

JMuff22 commented Apr 16, 2024

Whilst some checks were added in #493 . To support all backends we have been using

	def validate_wires_against_backend(self):
		b = self.backend

		try:
			num_qubits = int(b.configuration().n_qubits)
		except AttributeError:
			try:
				num_qubits = int(b.num_qubits)
			except AttributeError:
				raise AttributeError("Neither 'b.configuration().n_qubits' nor 'b.num_qubits' exist.")

		if len(self.wires) > num_qubits:
			raise ValueError(f"Backend '{b}' supports a maximum of {num_qubits} wires.")

to some success for some time now. So b.num_qubits is still needed

@CatalinaAlbornoz
Copy link

Hi @JMuff22, thank you for your comment! We'll add some improvements to the PennyLane-Qiskit plugin in the next release which should be released in about 3 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants