Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_partitioned_runtime_fusion.py
Go to the documentation of this file.
1 from pathlib import Path
2 import sys
3 
4 import numpy as np
5 import pytest
6 
7 REPO_ROOT = Path(__file__).resolve().parents[2]
8 if str(REPO_ROOT) not in sys.path:
9  sys.path.insert(0, str(REPO_ROOT))
10 
11 from squander.partitioning.noisy_runtime import (
12  PHASE3_RUNTIME_PATH_BASELINE,
13  PHASE3_RUNTIME_PATH_FUSED_UNITARY_ISLANDS,
14  execute_partitioned_density,
15  execute_partitioned_density_fused,
16 )
17 from tests.partitioning.fixtures.fusion_cases import iter_fusion_structured_cases
19  PHASE3_RUNTIME_DENSITY_TOL,
20  execute_fused_with_reference,
21 )
22 
23 
25  return next(iter(iter_fusion_structured_cases()))
26 
27 
29  _metadata, descriptor_set, parameters = _first_structured_case()
30  baseline_result = execute_partitioned_density(descriptor_set, parameters)
31  fused_result = execute_partitioned_density_fused(descriptor_set, parameters)
32 
33  assert baseline_result.runtime_path == PHASE3_RUNTIME_PATH_BASELINE
34  assert baseline_result.requested_runtime_path == PHASE3_RUNTIME_PATH_BASELINE
35  assert fused_result.actual_fused_execution is True
36  assert fused_result.runtime_path == PHASE3_RUNTIME_PATH_FUSED_UNITARY_ISLANDS
37  assert fused_result.requested_runtime_path == PHASE3_RUNTIME_PATH_FUSED_UNITARY_ISLANDS
38  assert fused_result.fused_region_count > 0
39 
40 
42  """Fused kernels and sequential NoisyCircuit lowering share gate semantics."""
43  _, descriptor_set, parameters = _first_structured_case()
44  fused = execute_partitioned_density(descriptor_set, parameters, allow_fusion=True)
45  unfused = execute_partitioned_density(descriptor_set, parameters, allow_fusion=False)
46  np.testing.assert_allclose(
47  fused.density_matrix_numpy(),
48  unfused.density_matrix_numpy(),
49  atol=PHASE3_RUNTIME_DENSITY_TOL,
50  rtol=0.0,
51  )
52 
53 
55  _metadata, descriptor_set, parameters = _first_structured_case()
56  result, _, density_metrics = execute_fused_with_reference(descriptor_set, parameters)
57 
58  assert result.actual_fused_execution is True
59  assert density_metrics["frobenius_norm_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
60  assert density_metrics["max_abs_diff"] <= PHASE3_RUNTIME_DENSITY_TOL