Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
1cb8abe
Add permutation gate
jnadori Oct 27, 2025
4c34e92
Fix permutation bug
jnadori Oct 27, 2025
bd16cb4
Add partition aware mapping synthesis part
jnadori Oct 29, 2025
7a60433
Add functions to find all and unique subtopologies in quantum circuit…
jnadori Oct 29, 2025
881a0af
Import Partition Aware Mapping module to enhance circuit optimization…
jnadori Oct 29, 2025
fb402d1
fix init
jnadori Oct 29, 2025
853b319
fix type
jnadori Oct 29, 2025
8a5fa97
Implement decomposition strategy selection in DecomposePartition_and_…
jnadori Oct 29, 2025
579d778
Partial commit
jnadori Oct 30, 2025
f649965
reowrk permutation gate to be more efficient
jnadori Oct 30, 2025
9001704
Reowrk PartAM
jnadori Oct 30, 2025
829535e
Change example + remove resynthesis
jnadori Oct 31, 2025
f8341fd
Refactor circuit optimization process by streamlining partition handl…
jnadori Oct 31, 2025
7e5a94b
Partial work on PartAM
jnadori Nov 1, 2025
99d2f4d
Move auxiliary functions to PartAM utils
jnadori Nov 3, 2025
c2192cd
Move back to two synthesis method for now
jnadori Nov 3, 2025
e031182
Expand utils and partial work on PartAM
jnadori Nov 3, 2025
fb739f9
Generate partition candidates
jnadori Nov 5, 2025
e6ad7f9
Create heuristic search with basic cost function
jnadori Nov 14, 2025
0207216
Refactor PartAM_example and PartAM to improve partition mapping and u…
jnadori Nov 14, 2025
33a15e8
Rework scoring
jnadori Nov 14, 2025
6136c6f
Fix minor bugs
jnadori Nov 14, 2025
ecb52fc
Add device checking and extended gate set
jnadori Nov 20, 2025
3a74492
rework example
jnadori Nov 20, 2025
73ad819
merge
jnadori Nov 20, 2025
d2f477b
Resolve merge error
jnadori Nov 20, 2025
db30f89
Fix PartAM utils and add consistent naming to qgd_Circuit
jnadori Nov 20, 2025
01737ed
Add state checking to example
jnadori Nov 20, 2025
ce7e1c7
Remake example
jnadori Nov 20, 2025
29dd806
Rework comments
jnadori Nov 21, 2025
9366bd4
Add temporary diagnostics
jnadori Nov 21, 2025
080faf9
Remove unneeded diagnostics
jnadori Nov 21, 2025
f4ba375
Fix error....
jnadori Nov 27, 2025
87dfee6
Add in caching and progressbar
jnadori Nov 27, 2025
90d5431
add progressbar to config
jnadori Nov 27, 2025
bd356ac
Remove state diagnostics from example
jnadori Nov 27, 2025
b38e48d
Increase core count for scoring
jnadori Nov 27, 2025
e975b3c
Add in progressbar verbosity
jnadori Nov 27, 2025
f47de98
Merge remote-tracking branch 'origin/jn_ParAM' into jn_ParAM
jnadori Nov 27, 2025
01e38e7
Remove bad parallelization
jnadori Nov 28, 2025
dcecb74
Parallelize cost function evaluation
jnadori Dec 2, 2025
ca361f2
fix non static function calls
jnadori Dec 2, 2025
b1595dd
re-try parallelization
jnadori Dec 2, 2025
0348423
Change scoring to minimum count
jnadori Dec 2, 2025
68251c0
Fix runtime error in partam utils
jnadori Dec 2, 2025
ecd1dc5
Rework multi threading again
jnadori Dec 2, 2025
c87cd92
Add permutation tests
jnadori Dec 4, 2025
e10c28f
rework cost calculation
jnadori Dec 4, 2025
0d04d13
Add less dependence for initial layout
jnadori Dec 5, 2025
d54d577
Revert scoring mistake
jnadori Dec 5, 2025
488c989
Rework used qubits feature
jnadori Dec 5, 2025
fabba27
Add error handling and circuit check
jnadori Dec 5, 2025
dff4d21
Refactor cost calculation
jnadori Dec 5, 2025
5e12e83
Add token swapping based search
jnadori Dec 6, 2025
3abe25b
Add in ILP swaps
jnadori Dec 7, 2025
fb34b03
Rename functions
jnadori Dec 7, 2025
0044111
rename
jnadori Dec 7, 2025
2415da9
Add in second children to heuristic cost function
jnadori Dec 7, 2025
22ed024
Rename again
jnadori Dec 7, 2025
326c98c
fix typo
jnadori Dec 7, 2025
ca4cf2d
Move back to old heuristic A_star search
jnadori Dec 8, 2025
37503d2
Change scoring
jnadori Dec 8, 2025
a8db198
Refactor and reorganize PartAM_utils and PartAM for improved structur…
jnadori Dec 8, 2025
0eefb76
Add in new lookahead functionality and SWAP penalty
jnadori Dec 9, 2025
4b29853
Update P_o
jnadori Dec 9, 2025
dda5546
Revert stupid change
jnadori Dec 9, 2025
00826f1
Add in single qubit partition handling
jnadori Dec 10, 2025
d357d7d
Add in SWAP weight to cost function
jnadori Dec 11, 2025
bf5f6a8
Remove priting
jnadori Dec 11, 2025
bfa7a27
Merge branch 'jn_ParAM' of https://github.com/rakytap/sequential-quan…
jnadori Dec 11, 2025
7f0f0ba
Remove unneeded printing
jnadori Dec 12, 2025
cb457a1
Rework wide circuit example
jnadori Jan 13, 2026
96fa37c
add generate DAG levels function
jnadori Feb 27, 2026
795b1f5
Merge remote-tracking branch 'origin/master' into jn_ParAM
jnadori Feb 27, 2026
485ca21
Remove bugs, clean up codebase and add new circuit function
jnadori Feb 27, 2026
8c22d4a
Add copy method to qgd_Circuit
jnadori Feb 27, 2026
cff6eb5
Add windowed synthesis
jnadori Feb 27, 2026
fc249ad
Fix get all partitions
jnadori Feb 27, 2026
6fec10e
Fix again
jnadori Feb 27, 2026
61f9181
Update window size remove OSR
jnadori Feb 27, 2026
0e93f38
Add DAG position based partition weight
jnadori Feb 27, 2026
9db7f56
Add proper free routing
jnadori Feb 27, 2026
5427fbb
Add Basin-hopping and OSR to PartAM
jnadori Feb 27, 2026
7bb8b9e
fix bug
jnadori Feb 27, 2026
cffc8c6
add interpartition scores
jnadori Feb 28, 2026
bfb4dc2
Clean up
jnadori Feb 28, 2026
f445192
Add verbosity to wide circuit optimization
jnadori Mar 2, 2026
d063332
Remove transition costs (no effect on results)
jnadori Mar 2, 2026
4dc8e76
Remove hard qubit limit
jnadori Mar 3, 2026
6fef61c
Switch back to classical forwards backwards initial mapping heuristic
jnadori Mar 3, 2026
1610e9c
Merge branch 'jn_PartAM_experimental' into jn_ParAM
jnadori Mar 3, 2026
07523d1
Add routing time benchmarking tool
jnadori Mar 8, 2026
d0aa536
modify gitignore
jnadori Mar 8, 2026
4992d19
Fix routing logic
jnadori Mar 9, 2026
0cab2ad
Try to remove second synthesis
jnadori Mar 9, 2026
5150370
Fix reversal traversal single qubit logci
jnadori Mar 9, 2026
7e5ffda
paritition automorphism
jnadori Mar 10, 2026
4398cf3
Remove decomp auto
jnadori Mar 10, 2026
96bd79a
Add in new parallel config
jnadori Mar 11, 2026
6fb009f
Revert "Add in new parallel config"
jnadori Mar 11, 2026
dd29579
Merge branch 'jn_ParAM' of https://github.com/rakytap/sequential-quan…
jnadori Mar 17, 2026
eb6f72d
async Parallel for wide circuits
jnadori Mar 17, 2026
d77c88b
Merge remote-tracking branch 'origin/jn_ParAM' into jn_ParAM
jnadori Mar 17, 2026
ed1c90d
c++ cpu pooling
jnadori Mar 17, 2026
474ec5f
Remove parallel experiments
jnadori Mar 18, 2026
2baa115
remove stupid pool redundancy
jnadori Mar 18, 2026
7b74b1b
Add better granularity to PartAM
jnadori Mar 19, 2026
adf164e
Organize and clean up PartAM
jnadori Mar 20, 2026
341e749
Routing speedup
jnadori Mar 20, 2026
7fe9983
Add cleanup in between routing passes
jnadori Mar 20, 2026
3ea5ac7
Add in improvements
jnadori Apr 17, 2026
db23dcd
Merge remote-tracking branch 'origin/master' into jn_ParAM
jnadori Apr 17, 2026
5e61d5f
WCO merge
jnadori Apr 17, 2026
640b130
Fix gates wrapper
jnadori Apr 17, 2026
28ab660
Rework PartAM
jnadori Apr 17, 2026
9846f73
Fix
jnadori Apr 17, 2026
bee6380
Fix new error
jnadori Apr 17, 2026
b3a6515
Fix another error + update toml
jnadori Apr 17, 2026
d8fb4e1
add tqdm to cli
jnadori Apr 17, 2026
8951ef0
Remove silly test
jnadori Apr 17, 2026
c1e81be
Ease verbosity
jnadori Apr 17, 2026
ff244a4
Try to rework cost function
jnadori Apr 18, 2026
da06853
Fix single-qubit partition remapping to use original qubits
jnadori Apr 18, 2026
5ba551d
Add original_qubits parameter to SingleQubitPartitionResult
jnadori Apr 18, 2026
e6af0ba
Try to improve Routing
jnadori Apr 18, 2026
68ff536
Streamline routing: remove valve from layout-only mode, drop dead con…
jnadori Apr 18, 2026
d2f24c2
Add VF2Layout/SabrePreLayout seeded layouts and configurable swap cost
jnadori Apr 19, 2026
d25c85b
Only clean up top k trials during routing
jnadori Apr 19, 2026
be457dc
Fall back on qiskit routing if synthesis fails
jnadori Apr 19, 2026
732d1e5
Remove priting
jnadori Apr 19, 2026
b3aaf5e
speed up routing
jnadori Apr 21, 2026
4a1790e
set global min to true for cleanup
jnadori Apr 21, 2026
0bfd35f
dont include cleanup in routing time
jnadori Apr 21, 2026
021b870
Fix tests
jnadori Apr 21, 2026
4e4c3cd
Merge branch 'jn_Partam_Dev' into jn_ParAM
jnadori Apr 21, 2026
4ba0eba
Make PartAM cover larger initial layouts
jnadori Apr 21, 2026
18a1764
add vf2 cutoff
jnadori Apr 21, 2026
ab8f1d5
Merge branch 'jn_ParAM' into jn_Partam_Dev
jnadori Apr 22, 2026
290f546
Add C++ SABRE routing engine (31x speedup)
jnadori Apr 22, 2026
0fadf3b
Use os.sched_getaffinity instead of mp.cpu_count for pool sizing
jnadori Apr 22, 2026
58a34a4
Fix C++ SABRE routing to match Python behavior (3 fixes)
jnadori Apr 22, 2026
aab861e
Revert "Fix C++ SABRE routing to match Python behavior (3 fixes)"
jnadori Apr 22, 2026
28d2146
Fix extended set generation to match Python behavior
jnadori Apr 22, 2026
5dc6ec3
Fix C++ prefilter to match Python cost-weighted formula
jnadori Apr 22, 2026
58d5ef8
Minor fixes
jnadori Apr 22, 2026
5306a30
minor bugfixes
jnadori Apr 22, 2026
4510066
fix lookahead and swap cost
jnadori Apr 22, 2026
2ae0b0d
Fix cost function bug
jnadori Apr 23, 2026
36b2043
fix bindings
jnadori Apr 23, 2026
da0be53
fix cpp side
jnadori Apr 23, 2026
bf1b0ba
speed up routing
jnadori Apr 23, 2026
31e8c86
Better estimation
jnadori Apr 23, 2026
bfa70d8
Try new routing things
jnadori Apr 23, 2026
bb3d08a
update routing
jnadori Apr 23, 2026
a674041
speedup
jnadori Apr 23, 2026
597f15e
better seeding
jnadori Apr 24, 2026
1adea7e
Routing changes
jnadori Apr 24, 2026
3e18e4a
Fix oopsie
jnadori Apr 24, 2026
ac798ba
Refine PartAM routing heuristics
jnadori Apr 24, 2026
29f2800
fix partitioning
jnadori Apr 24, 2026
5e7c29b
Fix remove fullpass config
jnadori Apr 24, 2026
473a62b
Fix routing bugs
jnadori Apr 24, 2026
7569913
Fix
jnadori Apr 24, 2026
e3feb8c
Rework
jnadori Apr 24, 2026
2a7f8f4
Fix
jnadori Apr 24, 2026
21b1617
improve partition scoring
jnadori Apr 25, 2026
1572c44
better routing and cost function
jnadori Apr 25, 2026
318c987
Use BQSKit-style canonical-edge cost for routing future context
jnadori Apr 25, 2026
10cabba
Remove pre filtering
jnadori Apr 25, 2026
c2a85ae
Add 3q exit routing penalty
jnadori Apr 25, 2026
94c20f4
more sabre iter
jnadori Apr 25, 2026
7e9e95d
new partition weights
jnadori Apr 27, 2026
993becd
update benchmark
jnadori Apr 27, 2026
fabf287
Add back in printing
jnadori Apr 27, 2026
b4662bd
Speedup
jnadori Apr 27, 2026
8f4e73f
try new things
jnadori Apr 28, 2026
cf2ec05
Fix
jnadori Apr 28, 2026
cca7911
fix
jnadori Apr 29, 2026
6f0e5a9
try new things
jnadori Apr 29, 2026
1bb85a1
Boundary beam routing
jnadori Apr 29, 2026
8d71cd3
new partitioning
jnadori Apr 30, 2026
f2e90f4
rework partitioning
jnadori Apr 30, 2026
ee0987f
revert partitioning
jnadori Apr 30, 2026
64787d9
more config stuff
jnadori Apr 30, 2026
a2bd2c0
new partitioning
jnadori Apr 30, 2026
1f76563
new weights
jnadori Apr 30, 2026
2068a09
better cost
jnadori Apr 30, 2026
e7b0638
Fix
jnadori Apr 30, 2026
0589f0d
hot swapping
jnadori May 1, 2026
05b0f5c
Revert "hot swapping"
jnadori May 1, 2026
c41b8c5
cleanup changes
jnadori May 1, 2026
a50133e
remove benchmark
jnadori May 2, 2026
c964636
fix cleanup
jnadori May 2, 2026
fc68b1c
better cleanup
jnadori May 2, 2026
54a43d1
fix cleanup time
jnadori May 2, 2026
7fb9380
Add in OSR compression
jnadori May 2, 2026
66c9863
missing init
jnadori May 2, 2026
a0028b6
fix topology
jnadori May 2, 2026
762a283
Revert "fix topology"
jnadori May 2, 2026
29f3d1e
Revert "missing init"
jnadori May 2, 2026
d6b522f
Revert "Add in OSR compression"
jnadori May 2, 2026
58d53fb
fix utils
jnadori May 3, 2026
25e1817
Remove other partitioning strategies
jnadori May 4, 2026
d4ac03d
improve partitioning
jnadori May 4, 2026
d9e1d1a
update yaml to use pybind
jnadori May 6, 2026
60835d9
seqpam-ilp uses squander seqpam workflow with simple ILP partitioning
jnadori May 7, 2026
a1e2f7e
Fix error
jnadori May 8, 2026
3af90b9
Fix core counts
jnadori May 9, 2026
bc1ca53
Improve PartAM routing layout heuristics
jnadori May 9, 2026
c334197
Fix SeqPAM ILP BQSKit block emission
jnadori May 9, 2026
6c38deb
Fix SeqPAM ILP PAM permutation blocks
jnadori May 9, 2026
824ffa4
Add PartAM routing trace and random trials
jnadori May 9, 2026
7478d42
Skip routing for zero-CNOT PartAM partitions
jnadori May 9, 2026
83a8a5d
Use body structure for transparent PartAM routing
jnadori May 10, 2026
701c6f8
Disable adaptive PartAM beam by default
jnadori May 10, 2026
a11a134
Revert PartAM seed layout heuristics
jnadori May 10, 2026
54354c1
Restore PartAM routing baseline
jnadori May 10, 2026
7950f7f
Parallelize PartAM actual route ranking
jnadori May 10, 2026
b204545
Split PartAM layout and final routing beams
jnadori May 10, 2026
deafd78
Restore seqpam ILP partitioning
jnadori May 11, 2026
8e31cd3
Use flat circuit structure for PartAM candidates
jnadori May 11, 2026
29c3bfd
fix topology check
jnadori May 12, 2026
d58979b
Restore PartAM routing trace
jnadori May 12, 2026
90ed99d
Normalize PartAM partitions to CNOT basis
jnadori May 12, 2026
b4786ea
Add ilp partition weight model
jnadori May 13, 2026
2713ea7
Auto stash before merge of "jn_partam_final" and "origin/jn_partam_fi…
jnadori May 14, 2026
43f1423
Add routing aware partitioning
jnadori May 14, 2026
752a264
recalibrate
jnadori May 14, 2026
4717921
refine partitioning
jnadori May 14, 2026
905be03
vft seeded layout
jnadori May 15, 2026
3700877
reowrk
jnadori May 15, 2026
49835f6
partitioning change
jnadori May 15, 2026
e0fdddd
boundary rework
jnadori May 16, 2026
c5c1644
Add anti-chain penalty for wide low-triangle partitions
jnadori May 17, 2026
33bf947
Add separate chain penalty threshold knob
jnadori May 19, 2026
efe98c1
Revert "Add separate chain penalty threshold knob"
jnadori May 20, 2026
5c999b6
depth balance exponetnial
jnadori May 20, 2026
2378d3b
Clean up PartAM and simplify cleanup phase
jnadori Jun 4, 2026
a673509
Merge branch 'jn_partam_final' into origin/jn_ParAM
jnadori Jun 4, 2026
37b863e
Rework example
jnadori Jun 4, 2026
ad57c0a
add missing pip install from windows actions
jnadori Jun 4, 2026
c154b1f
Merge branch 'jn_fix_windows_actions' into jn_ParAM
jnadori Jun 4, 2026
72e0050
update chain penalty
jnadori Jun 4, 2026
3581524
Fix code issues to work with MSVC as well
jnadori Jun 4, 2026
6fd319e
Merge origin/master into jn_ParAM
jnadori Jun 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -q numpy scipy scikit-build pybind11 qiskit qiskit-aer pytest
python -m pip install -q numpy scipy scikit-build pybind11 qiskit qiskit-aer pytest tqdm
python -m pip install -e . -q

- name: Build
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -q numpy scipy scikit-build pybind11 qiskit qiskit-aer pytest
python -m pip install -q numpy scipy scikit-build pybind11 qiskit qiskit-aer pytest tqdm
python -m pip install -e . -q

- name: Build
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -q numpy scipy scikit-build pybind11 qiskit qiskit-aer pytest
python -m pip install -q numpy scipy scikit-build pybind11 qiskit qiskit-aer pytest tqdm
python -m pip install -e . -q

- name: Build
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ list(APPEND qgd_files
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/CR.cpp
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/Adaptive.cpp
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/R.cpp
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/Permutation.cpp
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/kernels/apply_kernel_to_input.cpp
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/kernels/apply_kernel_to_state_vector_input.cpp
${PROJECT_SOURCE_DIR}/squander/src-cpp/gates/kernels/apply_large_kernel_to_input.cpp
Expand Down Expand Up @@ -1040,6 +1041,12 @@ add_subdirectory (squander/VQA)

add_subdirectory (squander/src-cpp/density_matrix)

# ===================================================================
# SABRE Router Module
# ===================================================================

add_subdirectory (squander/src-cpp/sabre_router)

if(DEFINED ENV{QGD_CTEST})
# adding CMAKE files for executables
add_subdirectory (test_standalone)
Expand Down
1 change: 1 addition & 0 deletions conda_env_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- numpy
- scipy
- tbb-devel
- pybind11
- pip:
- gurobipy
- matplotlib
Expand Down
162 changes: 162 additions & 0 deletions examples/decomposition/PartAM_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 26 14:42:56 2020
Copyright 2020 Peter Rakyta, Ph.D.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@author: Peter Rakyta, Ph.D.
"""
## \file PartAM_example.py
## \brief Simple example python code demonstrating Partition Aware Mapping

import time
import numpy as np

from squander import Partition_Aware_Mapping
from squander import utils
from squander import Circuit
from squander.decomposition.qgd_Wide_Circuit_Optimization import (
qgd_Wide_Circuit_Optimization,
)


def make_linear_topology(n_qubits):
return [(i, i + 1) for i in range(n_qubits - 1)]


def validate_result(circ_orig, parameters_orig, circ, params, input_perm, output_perm):
"""Apply both circuits to a random state and return ``1 - |<psi|phi>|``."""
num_qubits = circ.get_Qbit_Num()
matrix_size = 1 << num_qubits
rng = np.random.RandomState(0)
initial_state = (
rng.uniform(-1, 1, (matrix_size,))
+ 1j * rng.uniform(-1, 1, (matrix_size,))
)
initial_state /= np.linalg.norm(initial_state)

original_state = initial_state.copy()
circ_orig.apply_to(parameters_orig, original_state)

circ_Final = Circuit(num_qubits)
output_perm_T = [0] * num_qubits
for i, j in enumerate(output_perm):
output_perm_T[j] = i
circ_Final.add_Permutation([int(x) for x in input_perm])
circ_Final.add_Circuit(circ)
circ_Final.add_Permutation(output_perm_T)

state = initial_state.copy()
circ_Final.apply_to(params, state)
return 1 - abs(np.vdot(state, original_state))


if __name__ == '__main__':

filename = "bv_n14.qasm"

# load the circuit from a file
circ_orig, parameters_orig = utils.qasm_to_squander_circuit(filename)
N = circ_orig.get_Qbit_Num()
topology = make_linear_topology(N)

initial_cnot = circ_orig.get_Gate_Nums().get('CNOT', 0)
print(f"Qubits: {N}, initial CNOTs: {initial_cnot}")

start_time = time.time()

# one-shot WCO pass before PartAM (topology=None, max_partition_size=3,
# part_size_end=4) to fuse trivially-mergeable blocks
pre_partam_cleanup_config = {
'strategy': 'TreeSearch',
'pre-opt-strategy': 'TreeSearch',
'partition_strategy': 'ilp',
'test_subcircuits': False,
'test_final_circuit': False,
'max_partition_size': 3,
'topology': None,
'verbosity': 0,
'tolerance': 1e-8,
'parallel': 0,
'part_size_end': 4,
}
wco = qgd_Wide_Circuit_Optimization(pre_partam_cleanup_config)
pre_partam_circ, pre_partam_params = wco.OptimizeWideCircuit(
circ_orig.get_Flat_Circuit(),
parameters_orig,
)
pre_partam_cleanup_cnot = pre_partam_circ.get_Gate_Nums().get('CNOT', 0)
print(f"PartAM input CNOTs after pre-cleanup: {pre_partam_cleanup_cnot}")

# PartAM config
config = {
'strategy': "TreeSearch",
'test_subcircuits': False,
'test_final_circuit': False,
'max_partition_size': 3,
'progressbar': False,
'topology': topology,
'verbosity': 0,
'cleanup': True,
'sabre_iterations': 20,
'n_layout_trials': 128,
'random_seed': 42,
# Cheap candidate prefilter before full A* scoring.
'prefilter_top_k': 400,
'prefilter_min_per_partition': 2,
'prefilter_min_3q': 12,
# Rank every layout trial by actual constructed routing, not only by
# the heuristic trial cost. QFT is sensitive to this cap.
'actual_routing_rank_top_k': None,
# Boundary-state beam routing runs in the C++ SABRE router.
'use_cpp_router': True,
'layout_boundary_beam_width': 4,
'layout_boundary_beam_depth': 3,
'boundary_beam_width': 4,
'boundary_beam_depth': 3,
'cnot_cost': 0.5 / 3.0,
'cleanup_top_k': 3,
'parallel_layout_trials': True,
'layout_trial_workers': 0,
'max_E_size': 40,
'max_lookahead': 6,
'E_weight': 0.3,
'E_alpha': 1.0, # LightSABRE-style uniform lookahead (no per-depth decay)
'decay_delta': 0.001,
'swap_burst_budget': 0,
'path_tiebreak_weight': 0.2,
'three_qubit_exit_weight': 1.5,
'partition_weight_model': 'window_turnover',
'pack_credit_weight': 1.0,
'partition_chain_penalty_weight': 2.5,
}

# instantiate the object for Partition Aware Mapping
pam = Partition_Aware_Mapping(config)

# run Partition Aware Mapping
circ, params, input_perm, output_perm = pam.Partition_Aware_Mapping(
pre_partam_circ.get_Flat_Circuit(), pre_partam_params
)

elapsed = time.time() - start_time

error = validate_result(
circ_orig, parameters_orig, circ, params, input_perm, output_perm
)

print(f"CNOTs pre-cleanup: {pam._cnot_pre_cleanup}")
print(f"CNOTs post-cleanup: {circ.get_Gate_Nums().get('CNOT', 0)}")
print(f"Decomposition error: {error:.10f}")
print("--- %s seconds elapsed during optimization ---" % elapsed)
54 changes: 19 additions & 35 deletions examples/decomposition/example_SABRE.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from squander import SABRE
from squander import Qiskit_IO
from squander import utils
from squander import Circuit

from qiskit import transpile
from qiskit import QuantumCircuit
from qiskit.circuit import CircuitInstruction
from qiskit.circuit.library import PermutationGate
from qiskit_aer import AerSimulator
from qiskit.quantum_info import Operator
from qiskit import QuantumRegister, ClassicalRegister
import numpy as np
parameters = np.array([])

Expand Down Expand Up @@ -39,13 +35,14 @@
print("INITIAL CIRCUIT:")
#print( circuit_qiskit )
print("mapping (q -> Q):", pi)
print("Final mapping:", final_pi)
qubits = list(range(N))
Qiskit_circuit = QuantumCircuit(N)
pi_map = list(np.array(sabre.get_inverse_pi(pi)))
Qiskit_circuit.append(CircuitInstruction( PermutationGate(pi_map),qubits))
Qiskit_circuit &= Qiskit_IO.get_Qiskit_Circuit( Squander_remapped_circuit, parameters_remapped_circuit )
Qiskit_circuit.append(CircuitInstruction( PermutationGate(list(final_pi)),qubits))
pi_map = list(np.array(sabre.get_inverse_pi(final_pi)))
print("Final mapping:", final_pi)
final_circuit = Circuit(N)
final_circuit.add_Permutation(list(pi))
final_circuit.add_Circuit(Squander_remapped_circuit)
final_circuit.add_Permutation(list(pi_map))
Qiskit_circuit = Qiskit_IO.get_Qiskit_Circuit( final_circuit.get_Flat_Circuit(), parameters_remapped_circuit )
print("CIRCUIT MAPPED WITH SABRE:")
#print( Qiskit_circuit )
print("SABRE SWAP COUNT:", swap_count)
Expand All @@ -61,27 +58,14 @@
print("CIRCUIT MAPPED WITH QISKIT:")
#print( Qiskit_circuit_mapped )
print("QISKIT SWAP COUNT:", dict(Qiskit_circuit_mapped.count_ops())['swap'])

# test the generated squander circuits
#matrix_size = 1 << Squander_initial_circuit.get_Qbit_Num()
#unitary_squander_initial = utils.get_unitary_from_qiskit_circuit_operator(circuit_qiskit)

#unitary_squander_remapped_circuit = np.eye( 1 << Squander_initial_circuit.get_Qbit_Num(), dtype=np.complex128 )
#Squander_remapped_circuit.apply_to( parameters_remapped_circuit, unitary_squander_remapped_circuit)
"""
unitary_squander_remapped_circuit = utils.get_unitary_from_qiskit_circuit_operator(Qiskit_circuit)


product_matrix = np.dot(unitary_squander_initial.conj().T, unitary_squander_remapped_circuit)
phase = np.angle(product_matrix[0,0])
product_matrix = product_matrix*np.exp(-1j*phase)


product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T

# the error of the decomposition
decomposition_error = (np.real(np.trace(product_matrix)))/2

print('The error of the decomposition is ' + str(decomposition_error))

"""
num_qubits = final_circuit.get_Qbit_Num()
matrix_size = 1 << num_qubits
initial_state_real = np.random.uniform(-1.0,1.0, (matrix_size,) )
initial_state_imag = np.random.uniform(-1.0,1.0, (matrix_size,) )
initial_state = initial_state_real + initial_state_imag*1j
initial_state = initial_state/np.linalg.norm(initial_state)
original_state = initial_state.copy()
Squander_initial_circuit.apply_to(parameters_initial,original_state)
SABRE_state = initial_state.copy()
final_circuit.apply_to(parameters_remapped_circuit,SABRE_state)
print(f"ERROR: {1-abs(np.vdot(SABRE_state,original_state))}")
Loading
Loading