Квантовый объём модели Athens
Какого максимального квантового объёма вы можете добиться на моделируемом устройстве Athens? Как влияет изменение списка кубитов? Как влияет изменение уровня оптимизации? Можно ли ещё улучшить результат?
Квантовый объём равен $2^{d_{\max}}$, где dmax — наибольшая ширина и модельная глубина случайных схем, проходящих тест тяжёлых выходов. Тяжёлые выходы определяются идеальной симуляцией; на проверяемом устройстве оценивается их суммарная вероятность с исходным статистическим порогом. Исходная функция test_qv дана полностью; он использует FakeSantiago, а задание требует исследовать модель Athens, сохраняя смысл теста. Оценивайте не один случайный результат, а критерий по набору схем и запусков.
Полная исходная программа:
from qiskit.circuit.library import QuantumVolume as QuantumVolumeCircuit
qv_circuit = QuantumVolumeCircuit(4)
qv_circuit.decompose().draw() # .decompose() unrolls the circuit one level
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_histogram
ideal_results = Statevector.from_instruction(
qv_circuit).probabilities_dict()
plot_histogram(ideal_results)
def get_heavy_outputs(counts):
"""Extract heavy outputs from counts dict.
Args:
counts (dict): Output of `.get_counts()`
Returns:
list: All states with measurement probability greater
than the mean.
"""
# sort the keys of `counts` by value of counts.get(key)
sorted_counts = sorted(counts.keys(), key=counts.get)
# discard results with probability < median
heavy_outputs = sorted_counts[len(sorted_counts)//2:]
return heavy_outputs
print(get_heavy_outputs(ideal_results))
def check_threshold(nheavies, ncircuits, nshots):
"""Evaluate adjusted threshold inequality for quantum volume.
Args:
nheavies (int): Total number of heavy outputs measured from device
ncircuits (int): Number of different square circuits run on device
nshots (int): Number of shots per circuit
Returns:
Bool:
True if heavy output probability is > 2/3 with 97% certainty,
otherwise False
"""
from numpy import sqrt
numerator = nheavies - 2*sqrt(nheavies*(nshots-(nheavies/ncircuits)))
return bool(numerator/(ncircuits*nshots) > 2/3)
from qiskit import transpile
def test_qv(device, nqubits, ncircuits, nshots):
"""Try to achieve 2**nqubits quantum volume on device.
Args:
device (qiskit.providers.Backend): Device to test.
nqubits (int): Number of qubits to use for test.
ncircuits (int): Number of different circuits to run on the device.
nshots (int): Number of shots per circuit.
Returns:
Bool
True if device passes test, otherwise False.
"""
def get_ideal_probabilities(circuit):
"""Simulates circuit behaviour on a device with no errors."""
state_vector = Statevector.from_instruction(
circuit.remove_final_measurements(inplace=False)
)
return state_vector.probabilities_dict()
def get_real_counts(circuit, backend, shots):
"""Runs circuit on device and returns counts dict."""
t_circuit = transpile(circuit, backend)
job = backend.run(t_circuit,
shots=shots,
memory=True)
return job.result().get_counts()
# generate set of random circuits
qv_circuits = [
QuantumVolumeCircuit(nqubits) for c in range(ncircuits)
]
nheavies = 0 # number of measured heavy outputs
for circuit in qv_circuits:
# simulate circuit
ideal_heavy_outputs = get_heavy_outputs(
get_ideal_probabilities(circuit)
)
# run circuit on device
circuit.measure_all()
real_counts = get_real_counts(circuit, device, nshots)
# record whether device result is in the heavy outputs
for output, count in real_counts.items():
if output in ideal_heavy_outputs:
nheavies += count
# do statistical check to see if device passes test
is_pass = check_threshold(nheavies, ncircuits, nshots)
# calculate percentage of measurements that are heavy outputs
percent_heavy_outputs = nheavies*100/(ncircuits * nshots)
print(f"Quantum Volume: {2**nqubits}\n"
f"Percentage Heavy Outputs: {percent_heavy_outputs:.1f}%\n"
f"Passed?: {is_pass}\n")
return is_pass
from qiskit.providers.fake_provider import FakeSantiago
santiago = FakeSantiago()
test_qv(santiago, 4, ncircuits=150, nshots=50)Внешний ресурс проверен: это офлайн-модель, действующий процессор не требуется. Конфигурация, параметры ошибок, стандартные импульсы и класс модели сохранены из официального Qiskit 0.25.3. Для воспроизведения нужна совместимая архивная среда; для Boeblingen также qiskit-experiments. Архив модели athens, файлы: fake_athens.py, conf_athens.json, props_athens.json, defs_athens.json, __init__.py. Исходный код моделей при подготовке не исполнялся.
Решения пока нет.
Сообщить об ошибке
Войти, чтобы отправить материал.