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