-
Notifications
You must be signed in to change notification settings - Fork 364
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
Fixes for dependency issues caused by 0.14 release #2094
Changes from 17 commits
30f219a
b82b5ed
27a9ac2
6e47bbd
275e563
3de8921
beb7c16
4873a72
798d9df
8ff089c
60f5333
39aaab8
e8bd270
13fc1fb
e0cf244
ca534ed
53cb44f
177f2f9
1c59382
92f3780
ff1db05
debc66c
0259537
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 |
---|---|---|
|
@@ -605,7 +605,7 @@ def generate_aer_config( | |
return config | ||
|
||
|
||
def assemble_circuit(circuit: QuantumCircuit): | ||
def assemble_circuit(circuit: QuantumCircuit, basis_gates=None): | ||
"""assemble circuit object mapped to AER::Circuit""" | ||
|
||
num_qubits = circuit.num_qubits | ||
|
@@ -687,6 +687,7 @@ def assemble_circuit(circuit: QuantumCircuit): | |
is_conditional, | ||
conditional_reg, | ||
conditional_expr, | ||
basis_gates, | ||
) | ||
index_map.append(num_of_aer_ops - 1) | ||
|
||
|
@@ -792,6 +793,7 @@ def _assemble_op( | |
is_conditional, | ||
conditional_reg, | ||
conditional_expr, | ||
basis_gates, | ||
): | ||
operation = inst.operation | ||
qubits = [qubit_indices[qubit] for qubit in inst.qubits] | ||
|
@@ -812,7 +814,7 @@ def _assemble_op( | |
|
||
num_of_aer_ops = 1 | ||
# fmt: off | ||
if name in { | ||
if basis_gates is None and name in { | ||
"ccx", "ccz", "cp", "cswap", "csx", "cx", "cy", "cz", "delay", "ecr", "h", | ||
"id", "mcp", "mcphase", "mcr", "mcrx", "mcry", "mcrz", "mcswap", "mcsx", | ||
"mcu", "mcu1", "mcu2", "mcu3", "mcx", "mcx_gray", "mcy", "mcz", "p", "r", | ||
|
@@ -912,6 +914,9 @@ def _assemble_op( | |
aer_circ.mark(qubits, params) | ||
elif name == "qerror_loc": | ||
aer_circ.set_qerror_loc(qubits, label if label else name, conditional_reg, aer_cond_expr) | ||
elif basis_gates is not None and name in basis_gates: | ||
aer_circ.gate(name, qubits, params, [], conditional_reg, aer_cond_expr, | ||
label if label else name) | ||
elif name in ("for_loop", "while_loop", "if_else"): | ||
raise AerError( | ||
"control-flow instructions must be converted " f"to jump and mark instructions: {name}" | ||
|
@@ -923,11 +928,12 @@ def _assemble_op( | |
return num_of_aer_ops | ||
|
||
|
||
def assemble_circuits(circuits: List[QuantumCircuit]) -> List[AerCircuit]: | ||
def assemble_circuits(circuits: List[QuantumCircuit], basis_gates: list = None) -> List[AerCircuit]: | ||
"""converts a list of Qiskit circuits into circuits mapped AER::Circuit | ||
|
||
Args: | ||
circuits: circuit(s) to be converted | ||
basis_gates (list): supported gates to be converted | ||
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. As I mentioned the above, |
||
|
||
Returns: | ||
a list of circuits to be run on the Aer backends and | ||
|
@@ -947,5 +953,5 @@ def assemble_circuits(circuits: List[QuantumCircuit]) -> List[AerCircuit]: | |
# Generate AerCircuit from the input circuit | ||
aer_qc_list, idx_maps = assemble_circuits(circuits=[qc]) | ||
""" | ||
aer_circuits, idx_maps = zip(*[assemble_circuit(circuit) for circuit in circuits]) | ||
aer_circuits, idx_maps = zip(*[assemble_circuit(circuit, basis_gates) for circuit in circuits]) | ||
return list(aer_circuits), list(idx_maps) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixes for dependency issues caused by release 0.14. | ||
|
||
Fix for issue in samplingVector.allocate() when > 63 qubits | ||
|
||
Use basis_gates in AerCompiler when AerBackend is made by from_backend | ||
|
||
Setting number of qubits before transpile for Primitives V1 (issue #2084) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from test.terra.reference import ref_measure | ||
from qiskit import QuantumCircuit | ||
from qiskit import transpile | ||
import qiskit.quantum_info as qi | ||
from qiskit_aer import AerSimulator | ||
from qiskit_aer.noise import NoiseModel | ||
from qiskit_aer.noise.errors import ReadoutError, depolarizing_error | ||
|
@@ -265,6 +266,75 @@ def test_measure_stablizer_64bit(self, method, device): | |
|
||
self.assertDictAlmostEqual(output, targets, delta=delta * shots) | ||
|
||
@supported_methods(["stabilizer"], [65, 127, 433]) | ||
def test_measure_sampling_large_stabilizer(self, method, device, num_qubits): | ||
"""Test sampling measure for large stabilizer circuit""" | ||
paulis = qi.PauliList([num_qubits * i for i in ["X", "Y", "Z"]]) | ||
qc = QuantumCircuit(num_qubits) | ||
for pauli in paulis: | ||
for i, p in enumerate(pauli): | ||
if p == qi.Pauli("Y"): | ||
qc.sdg(i) | ||
qc.h(i) | ||
elif p == qi.Pauli("X"): | ||
qc.h(i) | ||
qc.measure_all() | ||
backend = self.backend(method=method) | ||
result = backend.run( | ||
transpile(qc, backend, optimization_level=0), shots=10, seed_simulator=12345 | ||
).result() | ||
counts = result.get_counts() | ||
|
||
ref_counts = {} | ||
if num_qubits == 65: | ||
ref_counts.update( | ||
{ | ||
"00000010101011110100110101101101101100010011000110011100101001010": 1, | ||
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. Just to test whether stabilizer can work for large-qubit circuits, we can use GHZ and then validate result with more simpler counts. |
||
"00110001000010110100000001111110011100110111000000110000010011100": 1, | ||
"10100010101000011000101011111100101010011101000011010111111101011": 1, | ||
"10000011001110111110110001111001100001010111100000001000110011110": 1, | ||
"00011100011000110011001001000011110000010101000111000101111110110": 1, | ||
"00000100000101110111010011011110001101100111111100001001100101011": 1, | ||
"10101011100110001001001100000101000001000010100101001000100010111": 1, | ||
"10000110100111001010101010011100010011110001011001110010100010100": 1, | ||
"00010011011100111010110000100101111101001011110001100110101101000": 1, | ||
"10100100011111100000100111011100101110001100100000111111111111011": 1, | ||
} | ||
) | ||
elif num_qubits == 127: | ||
ref_counts.update( | ||
{ | ||
"0001010101111010011010110110110110001001100011001110010100101000110001000010110100000001111110011100110111000000110000010011100": 1, | ||
"0010111011101001101111000110110011111110000100110010101100011100011000110011001001000011110000010101000111000101111110110100000": 1, | ||
"0000010011101110010111000110010000011111111111101100010011011100111010110000100101111101001011110001100110101101000101010111001": 1, | ||
"1100100000010000100001000010101101101100010110010100001001101101101111110011111001000111011011010010110111100000101001000111111": 1, | ||
"1000100100110000010100000100001010010100100010001011110000110100111001010101010011100010011110001011001110010100010100000001000": 1, | ||
"0000101010110000000011000000100011011100100101100001111101100100011011111111000001011100110111110100101001110000010110101010101": 1, | ||
"0001010110001001011010110001101100100001101100011010011110011101111110001110101110111000000011001000100011001111100000111110100": 1, | ||
"1011101111011100010101110011011111010110011011001001011000111101101100111001000010110010011001100010010111101011110110011011001": 1, | ||
"1100111011111011000111100110000101011110000000100011001111010100010101000011000101011111100101010011101000011010111111101011000": 1, | ||
"0000000000000001101000100001111100000010101001010011001011001101101000110111100110111101111110111100111101000011110110011000110": 1, | ||
} | ||
) | ||
elif num_qubits == 433: | ||
ref_counts.update( | ||
{ | ||
"1010011100010011110001011001110010100010100000001000001011101110100110111100011011001111111000010011001010110001110001100011001100100100001111000001010100011100010111111011010000011001110111110110001111001100001010111100000001000110011110101000101010000110001010111111001010100111010000110101111111010110000001010101111010011010110110110110001001100011001110010100101000110001000010110100000001111110011100110111000000110000010011100": 1, | ||
"0000010001101110010010110000111110110010001101111111100000101110011011111010010100111000001011010101010111001000000100001000010000101011011011000101100101000010011011011011111100111110010001110110110100101101111000001010010001111110000010011101110010111000110010000011111111111101100010011011100111010110000100101111101001011110001100110101101000101010111001100010010011000001010000010000101001010010001000101111000011010011100101010": 1, | ||
"1001010110100111010001000101010000000000111101001100100101011010110111111101010000111101011001001100001110101111101011010011101000111110011100010100111000010000100001100000010110100001111101010000100000100110011101100010000000011110010000100100000111001111010101011110010000011001000101001110100011010100110101111000010001000110001110010011111010101011011000101010110001001110111100001100010101001011000101101110010100001000111010011": 1, | ||
"0011000011110000001010100100010101001111000000100101011000101000010010110100111100101000100100101111101010011110110110011010000010110111110111000000110111111101101000100100101101000001100100010011101011010011111001010100111110000111100111110110010110100101000110110111010001010000001011000100010000000000100101111010101110001001100110011010110000111111101101010011000011011010111110111000101110001001001101110001010111110010001000111": 1, | ||
"0110010101110010011110110111100111111100011111010010001000010101011111101001010011110000011001100111010111000111011010000011011011100101111010111101000010010011111011000011000000111000010101001101101110100100001100010011000001110011011011111000110100100110010100011000110111101010111000101101100101111010101110010010000000111101110000101010101100011101110110000001101100111010110110011000111010101111100001111010000010111000010011000": 1, | ||
"0100111000011011011111101100100000000000000011010001000011111000000101010010100110010110011011010001101111001101111011111101111001111010000111101100110001101011101111011100010101110011011111010110011011001001011000111101101100111001000010110010011001100010010111101011110110011011001000101011000100101101011000110110010000110110001101001111001110111111000111010111011100000001100100010001100111110000011111010000001010101100000000110": 1, | ||
"1101001011100010000010110000111110110011011111000110111111101110010101101001101110011110011101101000101101110010101010111010101100001110111011101001101110010001101111000101110001000110110100010101010101110101100010001010110011010110011100011010010010100100010100111101101101010100101011111010111010110001011100000010000000101000000000010011000100100000100101100011011100110000101010011110101000101110101010101010101101110000010011011": 1, | ||
"0111111110110101111001101110001111101111000110110010110000101111100101010100100010001010110111100110010111000010000101001110011011111010011111100000001010101101010000110110001000001000111101110101101100100100010100010011101001000010001101111101000010000101000010001001000101011011011011101010101111100110000111000100011010110000100011000000000010101011111110011111010010110101100100111001000000100011100000000111101111001101100011101": 1, | ||
"1111000111000110110000010111101110110010110001110110010001110010011110110111111011010110111110011010010011010110010010010011001001001100000000100110010101110100011011100001010010011100001011000000010000010010110101001000010100111011000001011000101111110100011000100011010001101000111111110011110010100010011011100100100011010100110111010101100000101110110111100111101001111000101100110101011011010000111101111001011110101011011000011": 1, | ||
"0100100100011111111001111110100110001100101000011110011010001110001101100111111010010011110010000110011001010001001110110000111011000010000000011111011100001001010001110110111001011100001110101000101101011011010110110011110101111010111101011010000110101010111100110100101101011110100000100000110011100010011001111000010101010000011111001010010100001001101100001010101000101001100000001001110011010011000001011101011110010000110000111": 1, | ||
} | ||
) | ||
|
||
for count in counts: | ||
self.assertIn(count, ref_counts) | ||
|
||
# --------------------------------------------------------------------- | ||
# Test MPS algorithms for measure | ||
# --------------------------------------------------------------------- | ||
|
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.
Aer C++ library supports only the following gates natively.
If
basis_gates
is not subset of the above set, simulation will fail. I think it is better to checkname
is in the above set.Also, I guess
backend.configuration().basis_gate
islist
and notset
.basis_gates
should beset
because this is one of hot loops.I think that at the beginning of
assemble_circuit()
,basis_gates
should be re-created as aset
(while reducingmeasure
,reset
and etc). IfNone
is passed, we can use a default set.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.
When
AerSimulator
is made byfrom_backend()
givenbasis_gates
does not contain all the gates Aer supports, Aer should return error