From b630a1fcf1ca7610d9835413d17395d6a78d1709 Mon Sep 17 00:00:00 2001 From: OkuyanBoga Date: Thu, 12 Dec 2024 13:23:57 +0000 Subject: [PATCH] Added checks for different transpiler types --- qiskit_machine_learning/neural_networks/estimator_qnn.py | 5 ++++- qiskit_machine_learning/neural_networks/sampler_qnn.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qiskit_machine_learning/neural_networks/estimator_qnn.py b/qiskit_machine_learning/neural_networks/estimator_qnn.py index 9853ac645..99409afe1 100644 --- a/qiskit_machine_learning/neural_networks/estimator_qnn.py +++ b/qiskit_machine_learning/neural_networks/estimator_qnn.py @@ -182,7 +182,10 @@ def __init__( self.num_virtual_qubits = circuit.num_qubits else: circuit = pass_manager.run(circuit) - self.num_virtual_qubits = circuit.layout._input_qubit_count + if hasattr(circuit.layout, "_input_qubit_count"): + self.num_virtual_qubits = circuit.layout._input_qubit_count + else: + self.num_virtual_qubits = circuit.num_qubits self._org_circuit = circuit diff --git a/qiskit_machine_learning/neural_networks/sampler_qnn.py b/qiskit_machine_learning/neural_networks/sampler_qnn.py index b6a1eb911..ad2a17870 100644 --- a/qiskit_machine_learning/neural_networks/sampler_qnn.py +++ b/qiskit_machine_learning/neural_networks/sampler_qnn.py @@ -209,7 +209,10 @@ def __init__( self.num_virtual_qubits = circuit.num_qubits else: circuit = pass_manager.run(circuit) - self.num_virtual_qubits = circuit.layout._input_qubit_count + if hasattr(circuit.layout, "_input_qubit_count"): + self.num_virtual_qubits = circuit.layout._input_qubit_count + else: + self.num_virtual_qubits = circuit.num_qubits self._org_circuit = circuit