oqc-community / qat

QAT is a quantum compiler and runtime focused on low-level, just-above-driver integration.
Other
42 stars 11 forks source link

Intermittent QiskitError while running Qiskit circuit: 'Data for experiment "circuit-313" could not be found.' #136

Open hamidelmaazouz opened 1 month ago

hamidelmaazouz commented 1 month ago
FAILED src/tests/test_qiskit_backend.py::TestQiskitBackend::test_coupled_qasm_hardware[hardware0] - ValueError: QiskitError while running Qiskit circuit: 'Data for experiment "circuit-313" could not be found.'

Usually happens on CI tests involving a windows runner. Needs more investigation

hamidelmaazouz commented 1 month ago

Full logs for reference

src/tests/test_qiskit_backend.py:38 (TestQiskitBackend.test_coupled_qasm_hardware[hardware0])
self = <qat.purr.backends.qiskit_simulator.QiskitEngine object at 0x78ba2bcbbe80>
builder = <qat.purr.backends.qiskit_simulator.QiskitBuilder object at 0x78ba2beee3d0>

    def execute(self, builder: QiskitBuilder) -> Dict[str, Any]:
        if not isinstance(builder, QiskitBuilder):
            raise ValueError(
                "Contravariance is not possible with QiskitEngine. "
                "execute input must be a QiskitBuilder"
            )

        coupling_map = None
        if any(self.model.qubit_direction_couplings):
            coupling_map = [
                list(coupling.direction)
                for coupling in self.model.qubit_direction_couplings
            ]

        circuit = builder.circuit
        if self.model.strict_placement:
            verify_placement(coupling_map, circuit)

        # With no coupling map the backend defaults to create couplings for qubit count, which
        # defaults to 30. So we change that.
        aer_config = QasmBackendConfiguration.from_dict(AerSimulator._DEFAULT_CONFIGURATION)
        aer_config.n_qubits = self.model.qubit_count
        qasm_sim = AerSimulator(aer_config, noise_model=builder.model.noise_model)

        try:
            job = qasm_sim.run(
                transpile(circuit, qasm_sim, coupling_map=coupling_map),
                shots=builder.shot_count,
            )
            results = job.result()
>           distribution = results.get_counts(circuit)

../QAT/qat/purr/backends/qiskit_simulator.py:250: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../../../.cache/pypoetry/virtualenvs/qat-compiler-zfBtbP6P-py3.9/lib/python3.9/site-packages/qiskit/result/result.py:269: in get_counts
    exp = self._get_experiment(key)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Result(backend_name='aer_simulator', backend_version='0.13.3', qobj_id='', job_id='e164abda-86ce-40c5-ae88-408fc3c982f...ed': True, 'max_gpu_memory_mb': 0, 'max_memory_mb': 55853, 'parallel_experiments': 1}, time_taken=0.016196250915527344)
key = 'circuit-313'

    def _get_experiment(self, key=None):
        """Return a single experiment result from a given key.

        Args:
            key (str or QuantumCircuit or Schedule or int or None): the index of the
                experiment, as specified by ``data()``.

        Returns:
            ExperimentResult: the results for an experiment.

        Raises:
            QiskitError: if there is no data for the experiment, or an unhandled
                error occurred while fetching the data.
        """
        # Automatically return the first result if no key was provided.
        if key is None:
            if len(self.results) != 1:
                raise QiskitError(
                    "You have to select a circuit or schedule when there is more than one available"
                )
            key = 0

        # Key is a QuantumCircuit/Schedule or str: retrieve result by name.
        if isinstance(key, (QuantumCircuit, Schedule)):
            key = key.name
        # Key is an integer: return result by index.
        if isinstance(key, int):
            try:
                exp = self.results[key]
            except IndexError as ex:
                raise QiskitError(f'Result for experiment "{key}" could not be found.') from ex
        else:
            # Look into `result[x].header.name` for the names.
            exp = [
                result
                for result in self.results
                if getattr(getattr(result, "header", None), "name", "") == key
            ]

            if len(exp) == 0:
>               raise QiskitError('Data for experiment "%s" could not be found.' % key)
E               qiskit.exceptions.QiskitError: 'Data for experiment "circuit-313" could not be found.'

../../../../../.cache/pypoetry/virtualenvs/qat-compiler-zfBtbP6P-py3.9/lib/python3.9/site-packages/qiskit/result/result.py:380: QiskitError

During handling of the above exception, another exception occurred:

self = <tests.test_qiskit_backend.TestQiskitBackend object at 0x78ba2c15ad30>
hardware = QiskitHardwareModel

    @pytest.mark.parametrize(
        "hardware",
        [
            get_default_qiskit_hardware(35),
        ],
    )
    def test_coupled_qasm_hardware(self, hardware):
        builder = self.parse_and_apply_optimiziations(hardware, "20qb.qasm")
        runtime = hardware.create_runtime()
>       results = runtime.execute(builder)

test_qiskit_backend.py:48: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../QAT/qat/purr/backends/qiskit_simulator.py:328: in execute
    results = self.engine.execute(builder)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <qat.purr.backends.qiskit_simulator.QiskitEngine object at 0x78ba2bcbbe80>
builder = <qat.purr.backends.qiskit_simulator.QiskitBuilder object at 0x78ba2beee3d0>

    def execute(self, builder: QiskitBuilder) -> Dict[str, Any]:
        if not isinstance(builder, QiskitBuilder):
            raise ValueError(
                "Contravariance is not possible with QiskitEngine. "
                "execute input must be a QiskitBuilder"
            )

        coupling_map = None
        if any(self.model.qubit_direction_couplings):
            coupling_map = [
                list(coupling.direction)
                for coupling in self.model.qubit_direction_couplings
            ]

        circuit = builder.circuit
        if self.model.strict_placement:
            verify_placement(coupling_map, circuit)

        # With no coupling map the backend defaults to create couplings for qubit count, which
        # defaults to 30. So we change that.
        aer_config = QasmBackendConfiguration.from_dict(AerSimulator._DEFAULT_CONFIGURATION)
        aer_config.n_qubits = self.model.qubit_count
        qasm_sim = AerSimulator(aer_config, noise_model=builder.model.noise_model)

        try:
            job = qasm_sim.run(
                transpile(circuit, qasm_sim, coupling_map=coupling_map),
                shots=builder.shot_count,
            )
            results = job.result()
            distribution = results.get_counts(circuit)
        except QiskitError as e:
>           raise ValueError(f"QiskitError while running Qiskit circuit: {str(e)}")
E           ValueError: QiskitError while running Qiskit circuit: 'Data for experiment "circuit-313" could not be found.'