qiskit-aer icon indicating copy to clipboard operation
qiskit-aer copied to clipboard

Initial input of AerState

Open hhorii opened this issue 3 years ago • 3 comments

Summary

A new API for shared library and interactive simulator

Details and comments

This PR adds a new pybind for users to allow interactive access to quantum state.

state = AerState()
state.configure('method', 'statevector')
state.configure('device', 'CPU')

state.allocate_qubits(10)

state.apply_unitary([0, 1], random_unitary(2**2))
state.apply_unitary([1, 2], random_unitary(2**2))
state.apply_unitary([2, 3], random_unitary(2**2))
state.apply_unitary([3, 4], random_unitary(2**2))
state.apply_unitary([4, 5], random_unitary(2**2))
state.apply_unitary([5, 6], random_unitary(2**2))
state.apply_unitary([6, 7], random_unitary(2**2))
state.apply_unitary([7, 8], random_unitary(2**2))
state.apply_unitary([8, 9], random_unitary(2**2))
state.apply_unitary([9, 0], random_unitary(2**2))

print(state.sample_measure(10))
# {669: 1, 941: 1, 61: 1, 876: 1, 172: 1, 535: 1, 428: 1, 615: 1, 44: 1, 1014: 1}

state.clear_qubits()

All of the methods and devices will be available and ndarray of statevector and densitymatrix will be returned with zero-copy. Because the simulator can skip qobj construction and parsing, performance for low-qubits becomes better.

image (Note that currently gate fusion is not supported and performance with 16 or more qubits is worse than AerSimulator).

In addition, standalone build will produce a shared library libaer.so, which wraps AerState for C and C++ programs.

  • [x] Buffer gates and fuse buffered gates
  • [x] Support all the methods
  • [x] Support GPUs
  • [x] Add tests

hhorii avatar May 31 '22 04:05 hhorii

image

Intel(R) Xeon(R) Gold 6140 CPU (18 cores) Ubuntu 18.04 Python 3.9

from qiskit import QuantumCircuit, transpile
from qiskit.circuit.library import QuantumVolume
from qiskit.quantum_info.states import Statevector
from qiskit.providers.aer import AerSimulator

from qiskit.providers.aer.quantum_info.states import AerStatevector

time_sv = []
time_aer_sv = []
time_sim_sv = []
qubits = range(5, 21, 5)

for num_of_qubits in qubits:
    qv = QuantumVolume(num_of_qubits)
    
    result = %timeit -o Statevector(qv)
    time_sv.append(result.average)
    
    result = %timeit -o AerStatevector(qv)
    time_aer_sv.append(result.average)

import matplotlib.pyplot as plt

plt.semilogy(qubits, time_sv, 'o-', label='sv')
plt.semilogy(qubits, time_aer_sv, 'o-', label='aer_sv')
plt.grid()
plt.legend()
plt.xlabel('N qubits')
plt.ylabel('time (s)')
plt.show()

hhorii avatar Jun 29 '22 13:06 hhorii

I would like to ask

  • @ikkoham (and @chriseclectic if possible) to review AerStatevector,
  • @doichanj to review state_controller.hpp and refactoring of state.hpp, state_chunk.hpp, and experiment_result.hpp
  • @mtreinish or @jakelishman to review a new sub-package qiskit.providers.aer.quantum_info.states and other packaging issues.

hhorii avatar Jul 14 '22 04:07 hhorii

@ikkoham thank you for your comments. Initialization of AerStatevector with ndarray is now supported with be85e6d.

hhorii avatar Aug 09 '22 04:08 hhorii

This PR was divided into #1582, #1586, and #1590.

hhorii avatar Sep 13 '22 06:09 hhorii