-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix backend_util.py and test cases to support Aer 0.13 #11172
Changes from all commits
f5a2ea9
c7835f2
43ec21f
0ba7815
355f3ce
41e3676
dd98618
539ebd6
ed759e7
43d7e59
f08a9f9
f8f3506
ba181f4
7722011
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fix `backend_utils.py` for simulator backends with BackendV2. | ||
`is_simulator_backend` and `is_local_backend` returns `True` | ||
if backend name that contains `simulator`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1021,12 +1021,13 @@ def test_standard_base_gate_setting(self, gate_class): | |
""" | ||
if gate_class in {SingletonControlledGate, _SingletonControlledGateOverrides}: | ||
self.skipTest("SingletonControlledGate isn't directly instantiated.") | ||
num_free_params = len(_get_free_params(gate_class.__init__, ignore=["self"])) | ||
gate_params = _get_free_params(gate_class.__init__, ignore=["self"]) | ||
num_free_params = len(gate_params) | ||
free_params = [0.1 * i for i in range(num_free_params)] | ||
if gate_class in [MCU1Gate, MCPhaseGate]: | ||
free_params[1] = 3 | ||
elif gate_class in [MCXGate]: | ||
free_params[0] = 3 | ||
# set number of control qubits | ||
for i in range(num_free_params): | ||
if gate_params[i] == "num_ctrl_qubits": | ||
free_params[i] = 3 | ||
Comment on lines
+1027
to
+1030
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that this change is to make the code a bit general and not only work for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test discovery attempts to discover every registered subclass of We ideally should probably fix the test discovery to limit it only to controlled gates defined in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you are suggesting changing the current code on line 1017: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a huge fan of the automatic discovery in its current form at all, but given the current file, yeah, something like that would be fine. Something a little less magic would be from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping
standard_controlled_types = [x.base_class for x in get_standard_gate_name_mapping().values() if isinstance(x, ControlledGate)] That would exclude the multi-controlled gates, which imo should be handled specially if they're not going to follow the conventions of standard-library gates. (really, I don't think the mcx etc gates should be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that it looks like there is a lot of room for improvement in these tests, let's keep the current fix as-is and consider improving the tests in a follow-up. |
||
|
||
base_gate = gate_class(*free_params) | ||
cgate = base_gate.control() | ||
|
@@ -1153,12 +1154,13 @@ def test_base_gate_params_reference(self): | |
with self.subTest(i=repr(gate_class)): | ||
if gate_class in {SingletonControlledGate, _SingletonControlledGateOverrides}: | ||
self.skipTest("Singleton class isn't intended to be created directly.") | ||
num_free_params = len(_get_free_params(gate_class.__init__, ignore=["self"])) | ||
free_params = [0.1 * (i + 1) for i in range(num_free_params)] | ||
if gate_class in [MCU1Gate, MCPhaseGate]: | ||
free_params[1] = 3 | ||
elif gate_class in [MCXGate]: | ||
free_params[0] = 3 | ||
gate_params = _get_free_params(gate_class.__init__, ignore=["self"]) | ||
num_free_params = len(gate_params) | ||
free_params = [0.1 * i for i in range(num_free_params)] | ||
# set number of control qubits | ||
for i in range(num_free_params): | ||
if gate_params[i] == "num_ctrl_qubits": | ||
free_params[i] = 3 | ||
|
||
base_gate = gate_class(*free_params) | ||
if base_gate.params: | ||
|
@@ -1379,12 +1381,13 @@ def test_open_controlled_to_matrix(self, gate_class, ctrl_state): | |
"""Test open controlled to_matrix.""" | ||
if gate_class in {SingletonControlledGate, _SingletonControlledGateOverrides}: | ||
self.skipTest("SingletonGateClass isn't intended for direct initalization") | ||
num_free_params = len(_get_free_params(gate_class.__init__, ignore=["self"])) | ||
gate_params = _get_free_params(gate_class.__init__, ignore=["self"]) | ||
num_free_params = len(gate_params) | ||
free_params = [0.1 * i for i in range(1, num_free_params + 1)] | ||
if gate_class in [MCU1Gate, MCPhaseGate]: | ||
free_params[1] = 3 | ||
elif gate_class in [MCXGate]: | ||
free_params[0] = 3 | ||
# set number of control qubits | ||
for i in range(num_free_params): | ||
if gate_params[i] == "num_ctrl_qubits": | ||
free_params[i] = 3 | ||
cgate = gate_class(*free_params) | ||
cgate.ctrl_state = ctrl_state | ||
|
||
|
@@ -1487,14 +1490,21 @@ def test_controlled_standard_gates(self, num_ctrl_qubits, gate_class): | |
ctrl_state_zeros = 0 | ||
ctrl_state_mixed = ctrl_state_ones >> int(num_ctrl_qubits / 2) | ||
|
||
numargs = len(_get_free_params(gate_class)) | ||
gate_params = _get_free_params(gate_class) | ||
numargs = len(gate_params) | ||
args = [theta] * numargs | ||
if gate_class in [MSGate, Barrier]: | ||
args[0] = 2 | ||
elif gate_class in [MCU1Gate, MCPhaseGate]: | ||
args[1] = 2 | ||
elif issubclass(gate_class, MCXGate): | ||
args = [5] | ||
else: | ||
# set number of control qubits | ||
for i in range(numargs): | ||
if gate_params[i] == "num_ctrl_qubits": | ||
args[i] = 2 | ||
|
||
gate = gate_class(*args) | ||
|
||
for ctrl_state in (ctrl_state_ones, ctrl_state_zeros, ctrl_state_mixed): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern with this would the that the remote simulator "ibmq_qasm_simulator" would now be treated as local simulator wouldn't it. There is logic in run_circuits that dealt with max circuits around whether things were being run locally or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that with the upcoming changes in runtime simulators we shouldn't worry about this too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈