1
$\begingroup$

I was trying to use qiskit with cuQuantum. And was able to build Qiskit Aer with cuQuantum without any errors, but cuStateVec is still not used for simulations.

When I pass the cuStateVec_enable=True parameter in AerSimulator, I get an error.

sim = AerSimulator()
sim.set_options(method='statevector', device='GPU',cuStateVec_enable=True)

The Error -

Input In [9], in <cell line: 6>()
      4
      5 sim = AerSimulator()
----> 6 sim.set_options(method='statevector', device='GPU',cuStateVec_enable=True)
      9  

File ~/anaconda3/envs/qis1/lib/python3.8/site-packages/qiskit/providers/aer/backends/aerbackend.py:551, in AerBackend.set_options(self, **fields)
    549 """Set the simulator options"""
    550 for key, value in fields.items():
--> 551     self.set_option(key, value)

File ~/anaconda3/envs/qis1/lib/python3.8/site-packages/qiskit/providers/aer/backends/aer_simulator.py:644, in AerSimulator.set_option(self, key, value)
    640         raise AerError(
    641             "Invalid simulation method {}. Available methods"
    642             " are: {}".format(value, self.available_methods()))
    643     self._set_method_config(value)
--> 644 super().set_option(key, value)
    645 if key in ["method", "noise_model", "basis_gates"]:
    646     self._cached_basis_gates = self._basis_gates()

File ~/anaconda3/envs/qis1/lib/python3.8/site-packages/qiskit/providers/aer/backends/aerbackend.py:538, in AerBackend.set_option(self, key, value)
    536 else:
    537     if not hasattr(self._options, key):
--> 538         raise AerError("Invalid option %s" % key)
    539     if value is not None:
    540         # Only add an option if its value is not None
    541         setattr(self._options, key, value)

AerError: 'Invalid option cuStateVec_enable'

But, if I pass cuStateVec_enable=True in the execute() method instead of passing it to AerSimulator(), the program runs without throwing an error. However, cuStateVec is never invoked.

result = execute(circuit,sim,shots=shots,seed_simulator=12345, cuStateVec_enable=True).result()

I tried running the following program - (taken from this medium article)

from qiskit import *
from qiskit.circuit.library import *
from qiskit.providers.aer import *


sim = AerSimulator()
sim.set_options(method='statevector', device='GPU')

qubits = 15
depth=10
shots = 10

circuit = QuantumVolume(qubits, depth, seed=0)
circuit.measure_all()
circuit = transpile(circuit, sim)
result = execute(circuit,sim,shots=shots,seed_simulator=12345, cuStateVec_enable=True).result()

metadata = result.to_dict()['results'][0]['metadata']
print(metadata)

if 'cuStateVec_enable' in metadata and metadata['cuStateVec_enable']:
    print("cuStateVector is used for the simulation")
print("{0} qubits, Time = {1} sec".format(qubits,result.to_dict()['results'][0]['time_taken']))
counts = result.get_counts()
print(counts)

Here's the output -


{'parallel_state_update': 40, 'noise': 'ideal', 'batched_shots_optimization': False, 'measure_sampling': True, 'device': 'GPU',
'num_qubits': 15, 'parallel_shots': 1, 'remapped_qubits': False, 'method': 'statevector', 'active_input_qubits': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'num_clbits': 15, 
'input_qubit_map': [[14, 14], [13, 13], [12, 12], [11, 11], [10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [1, 1], [0, 0], [2, 2], [3, 3], [4, 4], [5, 5]], 
'fusion': {'time_taken': 0.001813286, 'applied': True, 'threshold': 14, 'max_fused_qubits': 5, 'method': 'unitary', 
'parallelization': 1, 'enabled': True, 'cost_factor': 1.8}}
========================================================================
15 qubits, Time = 0.004057602 sec
{'010111001000001': 1, '011010000111101': 1, '100100010100111': 1, '011110101110001': 1, '101100010110011': 1, '000001110000100': 1, '001101110011000': 1, '001101110000100': 1, '101100010101010': 1, '100101001000001': 1}

And as evident from the metadata printed cuStateVec is never invoked. I have tried building qiskit-aer with cuQuantum multiple times in multiple conda environvemts and I don't get any errors while building. But every time I have the same issue.

What am I missing here? Any help would be appreciated.

$\endgroup$
1
  • $\begingroup$ did you check the qiskit Aer version? $\endgroup$
    – poig
    Jun 13 at 19:18

1 Answer 1

0
$\begingroup$

I think it is related to this pr, it is related to Aer 0.10.4, it is release at april 6, so I think you might need to install the latest version of qiskit aer with pip install qiskit-aer==0.10.4

$\endgroup$
3
  • $\begingroup$ I'm already working with qiskit-aer 0.10.4 and cuQuantum 22.5.0 $\endgroup$ Jun 14 at 12:35
  • $\begingroup$ @DexterMandark check the source code, or try to reinstall. if still don't work, consider report the bug to github repo. $\endgroup$
    – poig
    Jun 14 at 15:21
  • $\begingroup$ I have tried multiple times, looks like I'll have to report it. $\endgroup$ Jun 14 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.