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

Add validate_wires_against_backend function #335

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,29 @@
self._capabilities["returns_state"] = self.backend_name in self._state_backends

# Perform validation against backend
b = self.backend
if len(self.wires) > int(b.configuration().n_qubits):
raise ValueError(
f"Backend '{backend}' supports maximum {b.configuration().n_qubits} wires"
)

self.validate_wires_against_backend()

Check notice on line 188 in pennylane_qiskit/qiskit_device.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/qiskit_device.py#L188

Trailing whitespace (trailing-whitespace)
# Initialize inner state
self.reset()

self.process_kwargs(kwargs)


def validate_wires_against_backend(self):

Check notice on line 195 in pennylane_qiskit/qiskit_device.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/qiskit_device.py#L195

Missing function or method docstring (missing-function-docstring)
b = self.backend

Check notice on line 197 in pennylane_qiskit/qiskit_device.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/qiskit_device.py#L197

Trailing whitespace (trailing-whitespace)
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.")

Check notice on line 204 in pennylane_qiskit/qiskit_device.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/qiskit_device.py#L204

Consider explicitly re-raising using 'except AttributeError as exc' and 'raise AttributeError("Neither 'b.configuration().n_qubits' nor 'b.num_qubits' exist.") from exc' (raise-missing-from)

Check notice on line 205 in pennylane_qiskit/qiskit_device.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/qiskit_device.py#L205

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


def process_kwargs(self, kwargs):
"""Processing the keyword arguments that were provided upon device initialization.

Expand Down