|
4 | 4 | from datetime import datetime |
5 | 5 | from time import sleep |
6 | 6 | from typing import Any, Callable, ContextManager |
| 7 | +from uuid import UUID |
7 | 8 |
|
8 | 9 | import pandas as pd |
9 | 10 | import pytest |
|
22 | 23 | CompilationResultRef, |
23 | 24 | CompileJobRef, |
24 | 25 | ExecuteJobRef, |
| 26 | + ExecutionResultRef, |
| 27 | + IncompleteJobItemRef, |
25 | 28 | JobRef, |
26 | 29 | Ref, |
27 | 30 | ) |
@@ -205,13 +208,14 @@ def test_submit_compile( |
205 | 208 | compile_results = qnx.jobs.results(compile_job_ref) |
206 | 209 |
|
207 | 210 | assert len(compile_results) == 1 |
208 | | - assert isinstance(compile_results[0], CompilationResultRef) |
209 | | - test_ref_serialisation("compile_result", compile_results[0]) |
| 211 | + compilation_result = compile_results[0] |
| 212 | + assert isinstance(compilation_result, CompilationResultRef) |
| 213 | + test_ref_serialisation("compile_result", compilation_result) |
210 | 214 |
|
211 | | - assert isinstance(compile_results[0].get_input(), CircuitRef) |
212 | | - assert isinstance(compile_results[0].get_output(), CircuitRef) |
| 215 | + assert isinstance(compilation_result.get_input(), CircuitRef) |
| 216 | + assert isinstance(compilation_result.get_output(), CircuitRef) |
213 | 217 |
|
214 | | - first_pass_data = compile_results[0].get_passes()[0] |
| 218 | + first_pass_data = compilation_result.get_passes()[0] |
215 | 219 |
|
216 | 220 | assert isinstance(first_pass_data, CompilationPassRef) |
217 | 221 | assert isinstance(first_pass_data.get_input(), CircuitRef) |
@@ -287,11 +291,25 @@ def test_get_results_for_incomplete_compile( |
287 | 291 | project=proj_ref, |
288 | 292 | backend_config=qnx.AerConfig(), |
289 | 293 | ) |
290 | | - |
| 294 | + # check the job while not complete |
291 | 295 | assert isinstance(compile_job_ref, CompileJobRef) |
292 | 296 | assert qnx.jobs.status(compile_job_ref).status != JobStatusEnum.COMPLETED |
| 297 | + |
| 298 | + with pytest.raises(qnx_exc.ResourceFetchFailed): |
| 299 | + qnx.jobs.results(compile_job_ref) |
| 300 | + |
293 | 301 | compile_results = qnx.jobs.results(compile_job_ref, allow_incomplete=True) |
294 | | - assert len(compile_results) == 0 |
| 302 | + assert len(compile_results) == 1 |
| 303 | + compile_item = compile_results[0] |
| 304 | + assert isinstance(compile_item, IncompleteJobItemRef) |
| 305 | + assert isinstance(compile_item.job_item_integer_id, int) |
| 306 | + assert compile_item.last_status != JobStatusEnum.COMPLETED |
| 307 | + |
| 308 | + # check the job after completion |
| 309 | + qnx.jobs.wait_for(compile_job_ref) |
| 310 | + complete_results = qnx.jobs.results(compile_job_ref, allow_incomplete=True) |
| 311 | + assert len(complete_results) == 1 |
| 312 | + assert isinstance(complete_results[0], CompilationResultRef) |
295 | 313 |
|
296 | 314 |
|
297 | 315 | def test_compile_hypertket( |
@@ -348,6 +366,7 @@ def test_submit_execute( |
348 | 366 | assert len(execute_results) == 1 |
349 | 367 |
|
350 | 368 | first_result = execute_results[0] |
| 369 | + assert isinstance(first_result, ExecutionResultRef) |
351 | 370 | assert isinstance(first_result.get_input(), CircuitRef) |
352 | 371 | assert isinstance(first_result.download_result(), BackendResult) |
353 | 372 | assert isinstance(first_result.download_backend_info(), BackendInfo) |
@@ -432,23 +451,32 @@ def test_get_results_for_incomplete_execute( |
432 | 451 | with pytest.raises(qnx_exc.JobError): |
433 | 452 | qnx.jobs.wait_for(execute_job_ref) |
434 | 453 |
|
| 454 | + with pytest.raises(qnx_exc.ResourceFetchFailed): |
| 455 | + qnx.jobs.results(execute_job_ref) |
| 456 | + |
435 | 457 | incomplete_results = qnx.jobs.results(execute_job_ref, allow_incomplete=True) |
436 | 458 |
|
437 | 459 | # wait for the ZZPhase circuit execution to complete |
438 | 460 | for _ in range(10): |
439 | 461 | incomplete_results = qnx.jobs.results( |
440 | 462 | execute_job_ref, allow_incomplete=True |
441 | 463 | ) |
442 | | - if len(incomplete_results) > 0: |
| 464 | + if any(isinstance(r, ExecutionResultRef) for r in incomplete_results): |
443 | 465 | break |
444 | 466 | sleep(10) |
445 | 467 |
|
446 | 468 | # we expect the CX circuit to fail on H1-1LE, but the ZZPhase circuit should succeed |
447 | | - assert len(incomplete_results) == 1 |
| 469 | + assert len(incomplete_results) == 2 |
| 470 | + first_item, second_item = incomplete_results[0], incomplete_results[1] |
| 471 | + assert isinstance(first_item, IncompleteJobItemRef) |
| 472 | + assert first_item.id == UUID(int=0) |
| 473 | + assert isinstance(first_item.job_item_integer_id, int) |
| 474 | + assert first_item.last_status == JobStatusEnum.ERROR |
448 | 475 |
|
449 | | - assert isinstance(incomplete_results[0].get_input(), CircuitRef) |
450 | | - assert isinstance(incomplete_results[0].download_result(), BackendResult) |
451 | | - assert isinstance(incomplete_results[0].download_backend_info(), BackendInfo) |
| 476 | + assert isinstance(second_item, ExecutionResultRef) |
| 477 | + assert isinstance(second_item.get_input(), CircuitRef) |
| 478 | + assert isinstance(second_item.download_result(), BackendResult) |
| 479 | + assert isinstance(second_item.download_backend_info(), BackendInfo) |
452 | 480 |
|
453 | 481 |
|
454 | 482 | def test_wait_for_raises_on_job_error( |
@@ -523,12 +551,13 @@ def test_results_not_available_error( |
523 | 551 | execute_results = qnx.jobs.results(execute_job_ref) |
524 | 552 |
|
525 | 553 | assert len(execute_results) == 1 |
| 554 | + execution_result = execute_results[0] |
| 555 | + assert isinstance(execution_result, ExecutionResultRef) |
| 556 | + assert isinstance(execution_result.get_input(), CircuitRef) |
526 | 557 |
|
527 | | - assert isinstance(execute_results[0].get_input(), CircuitRef) |
528 | | - |
529 | | - assert isinstance(execute_results[0].download_result(), BackendResult) |
| 558 | + assert isinstance(execution_result.download_result(), BackendResult) |
530 | 559 |
|
531 | | - assert isinstance(execute_results[0].download_backend_info(), BackendInfo) |
| 560 | + assert isinstance(execution_result.download_backend_info(), BackendInfo) |
532 | 561 |
|
533 | 562 |
|
534 | 563 | def test_submit_under_user_group( |
|
0 commit comments