Skip to content

Commit

Permalink
Set the number of qubits with the coupling map (Qiskit#1825)
Browse files Browse the repository at this point in the history
* Set n_qubits from coupling map

* Add a test and release notes

* Fix lint

---------

Co-authored-by: Hiroshi Horii <[email protected]>
  • Loading branch information
hitomitak and hhorii authored May 31, 2023
1 parent 3954278 commit 0fc19fd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,5 +940,9 @@ def _set_method_config(self, method=None):
# Clear options to default
description = None
n_qubits = None

if self._configuration.coupling_map:
n_qubits = max(list(map(max, self._configuration.coupling_map))) + 1

self._set_configuration_option("description", description)
self._set_configuration_option("n_qubits", n_qubits)
7 changes: 7 additions & 0 deletions releasenotes/notes/fix-number-qubits-a417ca6afa64264f.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fix an issue even if the number of qubits is set by a coupling map
or device's configuration, when the simulation method is configured,
the number of qubits is overwritten in accordance with the method.
Fixed `#1769 <https://github.com/Qiskit/qiskit-aer/issues/1769>`__
20 changes: 20 additions & 0 deletions test/terra/backends/aer_simulator/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from test.terra.backends.simulator_test_case import SimulatorTestCase, supported_methods
from qiskit.quantum_info.random import random_unitary
from qiskit.quantum_info import state_fidelity
from qiskit.providers.fake_provider import FakeMontreal

from qiskit_aer import AerSimulator


@ddt
Expand Down Expand Up @@ -282,3 +285,20 @@ def test_statevector_memory(self):
"Required memory: {}".format(2 ** (n - 20) * 16) in result.results[0].status
)
self.assertTrue("max memory: {}".format(max_memory_mb) in result.results[0].status)

@data(
"automatic",
"stabilizer",
"statevector",
"density_matrix",
"matrix_product_state",
"extended_stabilizer",
"unitary",
"superop",
)
def test_num_qubits(self, method):
"""Test number of qubits is correctly checked"""

num_qubits = FakeMontreal().configuration().num_qubits
backend = AerSimulator.from_backend(FakeMontreal(), method=method)
self.assertGreaterEqual(backend.configuration().num_qubits, num_qubits)

0 comments on commit 0fc19fd

Please sign in to comment.