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

Fix basis gates of Aer backends #1976

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:
run: |
set -e
python -I -m build --wheel --config-setting=--build-option=-- --config-setting=--build-option=-DTEST_JSON=1
pip install --find-links=dist qiskit-aer
pip install -U dist/*.whl
- name: Run Tests
run: |
set -e
Expand Down Expand Up @@ -267,7 +267,7 @@ jobs:
run: |
set -e
python -I -m build --wheel
pip install --find-links=dist qiskit-aer
pip install -U dist/*.whl
shell: bash
- name: Run Tests
env:
Expand Down
13 changes: 13 additions & 0 deletions qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ class AerSimulator(AerBackend):
"while_loop",
"break_loop",
"continue_loop",
"reset",
"switch_case",
]
),
"density_matrix": sorted(
Expand All @@ -538,6 +540,8 @@ class AerSimulator(AerBackend):
"while_loop",
"break_loop",
"continue_loop",
"reset",
"switch_case",
]
),
"matrix_product_state": sorted(
Expand All @@ -562,6 +566,8 @@ class AerSimulator(AerBackend):
"while_loop",
"break_loop",
"continue_loop",
"reset",
"switch_case",
]
),
"stabilizer": sorted(
Expand All @@ -583,6 +589,8 @@ class AerSimulator(AerBackend):
"while_loop",
"break_loop",
"continue_loop",
"reset",
"switch_case",
]
),
"extended_stabilizer": sorted(
Expand All @@ -591,13 +599,15 @@ class AerSimulator(AerBackend):
"qerror_loc",
"roerror",
"save_statevector",
"reset",
]
),
"unitary": sorted(
[
"save_state",
"save_unitary",
"set_unitary",
"reset",
]
),
"superop": sorted(
Expand All @@ -609,6 +619,7 @@ class AerSimulator(AerBackend):
"save_state",
"save_superop",
"set_superop",
"reset",
]
),
"tensor_network": sorted(
Expand All @@ -630,6 +641,8 @@ class AerSimulator(AerBackend):
"save_statevector_dict",
"set_statevector",
"set_density_matrix",
"reset",
"switch_case",
]
),
}
Expand Down
12 changes: 0 additions & 12 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
"pauli",
"mcx_gray",
"ecr",
"reset",
"switch_case",
]
),
"density_matrix": sorted(
Expand Down Expand Up @@ -151,8 +149,6 @@
"delay",
"pauli",
"ecr",
"reset",
"switch_case",
]
),
"matrix_product_state": sorted(
Expand Down Expand Up @@ -195,8 +191,6 @@
"cswap",
"diagonal",
"initialize",
"reset",
"switch_case",
]
),
"stabilizer": sorted(
Expand All @@ -216,12 +210,10 @@
"swap",
"delay",
"pauli",
"reset",
"ecr",
"rx",
"ry",
"rz",
"switch_case",
]
),
"extended_stabilizer": sorted(
Expand All @@ -247,7 +239,6 @@
"ccz",
"delay",
"pauli",
"reset",
]
),
"unitary": sorted(
Expand Down Expand Up @@ -309,7 +300,6 @@
"delay",
"pauli",
"ecr",
"reset",
]
),
"superop": sorted(
Expand Down Expand Up @@ -349,7 +339,6 @@
"diagonal",
"delay",
"pauli",
"reset",
]
),
"tensor_network": sorted(
Expand Down Expand Up @@ -412,7 +401,6 @@
"delay",
"pauli",
"mcx_gray",
"reset",
]
),
}
Expand Down
2 changes: 1 addition & 1 deletion qiskit_aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ class QasmSimulator(AerBackend):
"pauli",
"mcx_gray",
"ecr",
"reset",
]
)

Expand All @@ -389,6 +388,7 @@ class QasmSimulator(AerBackend):
"set_statevector",
"set_density_matrix",
"set_stabilizer",
"reset",
]
)

Expand Down
2 changes: 1 addition & 1 deletion qiskit_aer/backends/statevector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class StatevectorSimulator(AerBackend):
"initialize",
"delay",
"pauli",
"reset",
]
),
"custom_instructions": sorted(
Expand All @@ -231,6 +230,7 @@ class StatevectorSimulator(AerBackend):
"save_amplitudes_sq",
"save_state",
"set_statevector",
"reset",
]
),
"gates": [],
Expand Down
3 changes: 1 addition & 2 deletions qiskit_aer/backends/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ class UnitarySimulator(AerBackend):
"multiplexer",
"delay",
"pauli",
"reset",
]
),
"custom_instructions": sorted(["save_unitary", "save_state", "set_unitary"]),
"custom_instructions": sorted(["save_unitary", "save_state", "set_unitary", "reset"]),
"gates": [],
}

Expand Down
4 changes: 2 additions & 2 deletions qiskit_aer/quantum_info/states/aer_statevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ def _aer_evolve_instruction(aer_state, inst, qubits, basis_gates=None):
aer_state.apply_mcz(qubits[0 : len(qubits) - 1], qubits[len(qubits) - 1])
elif inst.name == "id":
pass
elif inst.name == "reset":
aer_state.apply_reset(qubits)
else:
applied = False
elif inst.name == "reset":
aer_state.apply_reset(qubits)
elif inst.name == "kraus":
aer_state.apply_kraus(qubits, inst.params)
elif inst.name == "barrier":
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/fix_basis_gates-5edf9708e3eec097.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed basis gates sets of Aer backend, moved `reset` and `switch_case`
to custom instructions.
15 changes: 15 additions & 0 deletions test/terra/backends/aer_simulator/test_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from ddt import ddt
from qiskit_aer import noise
import numpy as np

import qiskit.quantum_info as qi
from qiskit import transpile
Expand Down Expand Up @@ -69,6 +70,20 @@ def test_readout_noise(self, method, device):
self.assertSuccess(result)
self.compare_counts(result, [circuit], [target], delta=0.05 * shots)

@supported_methods(ALL_METHODS)
def test_readout_noise_without_basis_gates(self, method, device):
"""Test simulation with classical readout error noise model w/o basis gates."""
backend = self.backend(method=method, device=device)
noise_model = noise.NoiseModel()
noise_model.add_readout_error(np.array([[0.9, 0.1], [0.1, 0.9]]), [0])
backend.set_options(noise_model=noise_model)
circ = QuantumCircuit(1, 1)
circ.reset(0)
circ.measure(0, 0)
circ = transpile(circ, backend)
result = backend.run(circ, shots=1).result()
self.assertSuccess(result)

@supported_methods(ALL_METHODS)
def test_pauli_gate_noise(self, method, device):
"""Test simulation with Pauli gate error noise model."""
Expand Down
Loading