Qiskit / qiskit-aer

Aer is a high performance simulator for quantum circuits that includes noise models
https://qiskit.github.io/qiskit-aer/
Apache License 2.0
480 stars 354 forks source link

encounter ERROR on LinuxONE Linux: Failed to load qobj: "unitary" matrix is not unitary. #1506

Closed dongcc closed 1 year ago

dongcc commented 2 years ago

Informations

What is the current behavior?

When I'm trying to run quantum volume measurement(https://github.com/Qiskit/qiskit-experiments/blob/main/docs/tutorials/quantum_volume.ipynb) on the LinuxONE Linux, I encountered following error :

image
QiskitError                               Traceback (most recent call last)
/tmp/ipykernel_2232758/2280933431.py in <module>
      7 
      8 # Run experiment
----> 9 expdata = qv_exp.run(backend).block_for_results()

~/anaconda3/envs/qiskit/lib/python3.8/site-packages/qiskit_experiments/framework/base_experiment.py in run(self, backend, analysis, experiment_data, **run_options)
    126         transpile_opts = copy.copy(self.transpile_options.__dict__)
    127         transpile_opts["initial_layout"] = list(self._physical_qubits)
--> 128         circuits = transpile(self.circuits(backend), backend, **transpile_opts)
    129         self._postprocess_transpiled_circuits(circuits, backend, **run_options)
    130 

~/anaconda3/envs/qiskit/lib/python3.8/site-packages/qiskit_experiments/library/quantum_volume/qv_experiment.py in circuits(self, backend)
    165                 "trial": trial,
    166                 "qubits": self.physical_qubits,
--> 167                 "ideal_probabilities": self._get_ideal_data(qv_circ),
    168             }
    169             circuits.append(qv_circ)

~/anaconda3/envs/qiskit/lib/python3.8/site-packages/qiskit_experiments/library/quantum_volume/qv_experiment.py in _get_ideal_data(self, circuit, **run_options)
    144 
    145             ideal_result = self._simulation_backend.run(ideal_circuit, **run_options).result()
--> 146             probabilities = ideal_result.data().get("probabilities")
    147         else:
    148             from qiskit.quantum_info import Statevector

~/anaconda3/envs/qiskit/lib/python3.8/site-packages/qiskit/result/result.py in data(self, experiment)
    196         """
    197         try:
--> 198             return self._get_experiment(experiment).data.to_dict()
    199         except (KeyError, TypeError) as ex:
    200             raise QiskitError(f'No data for experiment "{repr(experiment)}"') from ex

~/anaconda3/envs/qiskit/lib/python3.8/site-packages/qiskit/result/result.py in _get_experiment(self, key)
    366         if key is None:
    367             if len(self.results) != 1:
--> 368                 raise QiskitError(
    369                     "You have to select a circuit or schedule when there is more than one available"
    370                 )

QiskitError: 'You have to select a circuit or schedule when there is more than one available'

Not sure whether it is a qiskit-experiment issue or qiskit-Aer issue as I do noticed that the error was reported from https://github.com/Qiskit/qiskit-aer/blob/main/src/framework/operations.hpp#L1002

Steps to reproduce the problem

Run the notebook https://github.com/Qiskit/qiskit-experiments/blob/main/docs/tutorials/quantum_volume.ipynb on LinuxONE Linux.

What is the expected behavior?

The measurement can be successfully performed.

Suggested solutions

mtreinish commented 2 years ago

I took a look at this while testing the output of https://github.com/Qiskit/qiskit-aer/pull/1504. I'm pretty sure this is an aer bug around running on big endian platforms (which in practice s390x linux is probably the only one). Probably specifically around around https://github.com/Qiskit/qiskit-aer/blob/main/src/framework/pybind_json.hpp#L241 and https://github.com/Qiskit/qiskit-aer/blob/main/src/framework/pybind_json.hpp#L143-L165 I think aer is interpreting the endianess of the input unitary 2d array from the circuit/qobj incorrectly and that's causing it to fail it's internal is_unitary() function. You can easily reproduce this same error without qiskit-experiments using:

from qiskit import Aer
from qiskit.quantum_info import random_unitary
from qiskit.circuit import QuantumCircuit

backend = Aer.get_backend("aer_simulator")
qc = QuantumCircuit(2)
qc.unitary(random_unitary(4), [0, 1])
qc.measure_all()
backend.run(qc)
hhorii commented 1 year ago

Please open a new issue if the above workaround doesn't work.