API Reference
Auto-generated from the library's docstrings.
Core
hdh.hdh.HDH
A Hybrid Dependency Hypergraph: a quantum workload as states (nodes) joined by the operations between them (hyperedges).
Usually built by a model (Circuit, MBQC, QW, QCA) or a
converter such as from_qiskit. Each node is the state of one wire at one
timestep, with ID "<wire>_t<time>". Core attributes have a readable
name and a formal one matching the HDH paper's notation; both refer to the
same object.
Examples:
>>> hdh = HDH()
>>> a = hdh.add_node("q0", 0)
>>> b = hdh.add_node("q0", 1)
>>> edge = hdh.add_hyperedge({a, b}, "q", name="h")
>>> sorted(hdh.nodes)
['q0_t0', 'q0_t1']
>>> hdh.hyperedge_types[edge], hdh.gate_name[edge]
('q', 'h')
| Attributes: |
|
|---|
Source code in hdh\hdh.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
hyperedge_realisation
property
Hyperedge -> "a" or "p" (phi).
hyperedge_types
property
Hyperedge -> "q" or "c" (tau).
hyperedges
property
All hyperedges (C).
node_realisation
property
Node ID -> "a" or "p" (upsilon).
node_types
property
Node ID -> "q" or "c" (sigma).
nodes
property
All node IDs (S in the paper's notation).
timesteps
property
All distinct timesteps (T).
add_hyperedge(node_ids, edge_type, name=None, node_real='a', role=None)
Connect node_ids with a hyperedge representing one operation.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> hdh = HDH()
>>> q, c = hdh.add_node("q0", 0), hdh.add_node("c0", 1, "c")
>>> edge = hdh.add_hyperedge({q, c}, "c", name="measure")
>>> sorted(edge)
['c0_t1', 'q0_t0']
Source code in hdh\hdh.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
add_node(wire, time, node_type=NodeType.QUANTUM, node_real=Realisation.ACTUAL)
Add the state of wire at time and return its node ID.
The ID is "<wire>_t<time>" (see node_id) and the wire is recorded
in wire_of. Re-adding an existing state is a no-op apart from updating
node_real.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> hdh = HDH()
>>> hdh.add_node("q0", 1)
'q0_t1'
>>> hdh.add_node("c0", 2, "c")
'c0_t2'
Source code in hdh\hdh.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
get_ancestry(node)
Return nodes with paths ending at node and earlier time steps.
Source code in hdh\hdh.py
253 254 255 256 257 258 | |
get_lineage(node)
Return nodes reachable from node with later time steps.
Source code in hdh\hdh.py
260 261 262 263 264 265 | |
get_num_qubits()
Return the number of logical qubits (quantum wires).
Circuit-style wires q<index> report max(index) + 1, so a circuit
using only qubits 0 and 4 reports 5, matching the register size a
converter needs. If any quantum wire is named otherwise (MBQC or QCA
labels), the count of distinct quantum wires is returned instead.
| Returns: |
|
|---|
Source code in hdh\hdh.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
node_id(wire, time)
staticmethod
The ID add_node gives the state of wire at time: "<wire>_t<time>".
Source code in hdh\hdh.py
152 153 154 155 | |
hdh.hdh.NodeType
Bases: _StrEnum
Whether a node (or hyperedge) carries quantum or classical information.
Members compare equal to their values, so "q" and
NodeType.QUANTUM are interchangeable wherever a type is expected.
Source code in hdh\hdh.py
14 15 16 17 18 19 20 21 | |
hdh.hdh.Realisation
Bases: _StrEnum
Whether a node (or hyperedge) always happens, or only if a classical condition holds.
Source code in hdh\hdh.py
24 25 26 27 28 | |
hdh.hdh.EdgeRole
Bases: _StrEnum
Distribution primitive assigned to a cut hyperedge.
Source code in hdh\hdh.py
31 32 33 34 | |
Models
hdh.models.base.Model
Bases: Protocol
What a computational model must provide to be used with HDH.
A model is any object that can translate the computation it describes
into an HDH. Circuit, MBQC, QW and QCA all satisfy this
Protocol; a new model only needs a build_hdh method, no base class.
tests/test_model_protocol.py checks every registered model against the
invariants below, so a new model should be added to its registry.
The HDH returned by build_hdh must:
- create every node with
HDH.add_node, so each has a type, a time and a wire (qubit, bit, or model label); - keep each wire a single type (a label used for a classical result is never reused as a quantum state);
- only connect nodes that exist;
- keep quantum hyperedges free of classical nodes.
Examples:
>>> from hdh.models.circuit import Circuit
>>> isinstance(Circuit(), Model)
True
Source code in hdh\models\base.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
build_hdh()
Translate the model's recorded operations into an HDH.
Source code in hdh\models\base.py
31 32 33 | |
hdh.models.circuit.Circuit
Gate-model circuit builder: record gates in order, then call build_hdh.
Examples:
>>> c = Circuit()
>>> c.add_instruction("h", [0])
>>> c.add_instruction("cx", [0, 1])
>>> c.add_instruction("measure", [1])
>>> hdh = c.build_hdh()
>>> hdh.get_num_qubits()
2
>>> sorted({hdh.wire_of[n] for n in hdh.nodes})
['c1', 'q0', 'q1']
Source code in hdh\models\circuit.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
add_conditional_gate(classical_bit, target_qubit, gate_name, additional_qubits=None, modifies_flags=None, params=None)
Append a gate that only applies when classical_bit is 1.
The bit must already hold a value, typically from an earlier
"measure". The gate's output states are marked predicted ("p").
| Parameters: |
|
|---|
Examples:
>>> c = Circuit()
>>> c.add_instruction("h", [0])
>>> c.add_instruction("measure", [0])
>>> c.add_conditional_gate(0, 1, "x")
>>> hdh = c.build_hdh()
>>> sorted(n for n in hdh.nodes if hdh.node_realisation[n] == "p")
['q1_t3']
Source code in hdh\models\circuit.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
add_instruction(name, qubits, bits=None, modifies_flags=None, cond_flag='a', params=None)
Append a gate or measurement.
| Parameters: |
|
|---|
Examples:
>>> c = Circuit()
>>> c.add_instruction("rx", [0], params=[0.5])
>>> hdh = c.build_hdh()
>>> list(hdh.gate_params.values())
[[0.5]]
Source code in hdh\models\circuit.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
build_hdh(hdh_cls=HDH)
Translate the recorded instructions into an HDH.
Qubit i and bit j become wires "q<i>" and "c<j>". A
multi-qubit gate spans three timesteps as three hyperedge layers
(<name>_stage1, _stage2, _stage3), so a partitioner can cut
before, through or after it.
| Parameters: |
|
|---|
Source code in hdh\models\circuit.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
hdh.models.mbqc.MBQC
Measurement-based quantum computing (MBQC) pattern builder.
Record N (prepare), E (entangle), M (measure) and C (classical
correction) operations with add_operation, then call build_hdh.
Labels are free-form and become the HDH's wires; keep each label to one
type (never reuse a measurement result's label as a quantum state).
Examples:
>>> m = MBQC()
>>> m.add_operation("N", [], "a")
>>> m.add_operation("N", [], "b")
>>> m.add_operation("E", ["a", "b"], "b")
>>> m.add_operation("M", ["a"], "m_a")
>>> hdh = m.build_hdh()
>>> sorted({hdh.wire_of[n] for n in hdh.nodes if hdh.node_types[n] == "q"})
['a', 'b']
Source code in hdh\models\mbqc.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
add_operation(op_type, A, b)
Append one N, E, M or C operation.
| Parameters: |
|
|---|
Source code in hdh\models\mbqc.py
33 34 35 36 37 38 39 40 41 | |
build_hdh()
Translate the recorded pattern into an HDH, one timestep per operation.
Source code in hdh\models\mbqc.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
hdh.models.qca.QCA
Quantum cellular automaton builder: cells updated from their neighbors for a number of steps, then optionally measured.
| Parameters: |
|
|---|
Examples:
>>> qca = QCA(topology={"A": ["B"], "B": ["A"]}, measurements={"A"}, steps=1)
>>> sorted(qca.build_hdh().nodes)
['A_t0', 'A_t1', 'B_t0', 'B_t1', 'c_A_t2']
Source code in hdh\models\qca.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
build_hdh()
Build the HDH: per step, one hyperedge per cell joining its and its neighbors' previous states to its new state; then one measurement hyperedge per measured cell.
Source code in hdh\models\qca.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
hdh.models.qw.QW
Discrete-time quantum walk builder: coin and shift steps, then measurement.
add_coin and add_shift return the label of the new walker state, to
pass to the next step.
Examples:
>>> w = QW()
>>> state = w.add_shift(w.add_coin("q0"))
>>> w.add_measurement(state, "m0")
>>> sorted(w.build_hdh().nodes)
['m0_t3', 'q0_t0', 'q1_t1', 'q2_t2']
Source code in hdh\models\qw.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
add_coin(a)
Apply a coin operation to walker state a; returns the new state label.
Source code in hdh\models\qw.py
31 32 33 34 35 | |
add_measurement(a, b)
Measure walker state a into classical label b, which must not already
be used for a quantum state.
Source code in hdh\models\qw.py
43 44 45 46 47 | |
add_shift(a_prime)
Apply a shift operation to walker state a_prime; returns the new state label.
Source code in hdh\models\qw.py
37 38 39 40 41 | |
build_hdh()
Translate the recorded coin/shift/measurement steps into an HDH.
Source code in hdh\models\qw.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Visualization
hdh.visualize.plot_hdh(hdh, save_path='hdh_plot.svg')
Plot an HDH with time on the x-axis and one row per wire.
Circuit wires q<i> and c<i> share row i; any other wire gets a
row of its own.
| Parameters: |
|
|---|
Examples:
>>> from hdh.models.circuit import Circuit
>>> c = Circuit()
>>> c.add_instruction("cx", [0, 1])
>>> plot_hdh(c.build_hdh(), save_path="cx.svg")
Source code in hdh\visualize.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Converters
hdh.converters.qiskit_converter.from_qiskit(qc)
Convert a Qiskit QuantumCircuit to an HDH.
Supports standard gates, measurement, and if_test blocks conditioned on
a single classical bit equal to 1.
| Raises: |
|
|---|
Examples:
>>> from qiskit import QuantumCircuit
>>> qc = QuantumCircuit(2, 1)
>>> _ = qc.h(0); _ = qc.cx(0, 1); _ = qc.measure(1, 0)
>>> from_qiskit(qc).get_num_qubits()
2
Source code in hdh\converters\qiskit_converter.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
hdh.converters.qiskit_converter.to_qiskit(hdh)
Convert an HDH back into a Qiskit QuantumCircuit.
Each multi-qubit gate is rebuilt from its _stage2 hyperedge. Gate
parameters come from HDH.gate_params when recorded (e.g. by
from_qiskit) and default to 0 otherwise.
Examples:
>>> from qiskit import QuantumCircuit
>>> qc = QuantumCircuit(2)
>>> _ = qc.h(0); _ = qc.cx(0, 1)
>>> [inst.operation.name for inst in to_qiskit(from_qiskit(qc)).data]
['h', 'cx']
Source code in hdh\converters\qiskit_converter.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
hdh.converters.qiskit_converter.partitions_to_qiskit(hdh, partitions)
Split a partitioned HDH into one Qiskit circuit per partition.
Each circuit keeps only the gates entirely inside its partition; gates across partitions are the cuts a distributed run must implement with communication primitives.
| Parameters: |
|
|---|
Examples:
>>> from qiskit import QuantumCircuit
>>> from hdh.passes.cut import compute_cut
>>> qc = QuantumCircuit(4)
>>> _ = qc.cx(0, 1); _ = qc.cx(2, 3)
>>> hdh = from_qiskit(qc)
>>> partitions, cut_cost = compute_cut(hdh, k=2, cap=2)
>>> cut_cost, [c.num_qubits for c in partitions_to_qiskit(hdh, partitions)]
(0, [2, 2])
Source code in hdh\converters\qiskit_converter.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
hdh.converters.qasm_converter.from_qasm(input_type, qasm)
Convert OpenQASM 2.0 to an HDH, via Qiskit's parser and from_qiskit.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> src = 'OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; h q[0]; cx q[0], q[1];'
>>> from_qasm("string", src).get_num_qubits()
2
Source code in hdh\converters\qasm_converter.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
hdh.converters.cirq_converter.from_cirq(c)
Convert a Cirq circuit to an HDH.
Supports standard gates and measurement. Classically controlled operations are not supported.
Examples:
>>> import cirq
>>> a, b = cirq.LineQubit.range(2)
>>> circuit = cirq.Circuit([cirq.H(a), cirq.CNOT(a, b), cirq.measure(b)])
>>> from_cirq(circuit).get_num_qubits()
2
Source code in hdh\converters\cirq_converter.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
hdh.converters.pennylane_converter.from_pennylane(circ_like)
Convert a PennyLane QuantumScript (or recorded operations) to an HDH.
Supports standard gates, mid-circuit and terminal measurements, and
qml.cond on a single measurement. Wire labels are renumbered
0..n-1 in declaration order.
| Raises: |
|
|---|
Examples:
>>> import pennylane as qml
>>> script = qml.tape.QuantumScript(
... [qml.Hadamard(0), qml.CNOT([0, 1])], [qml.probs(wires=1)])
>>> from_pennylane(script).get_num_qubits()
2
Source code in hdh\converters\pennylane_converter.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
hdh.converters.pennylane_converter.to_pennylane(hdh)
Convert an HDH back into a PennyLane QuantumScript.
Each multi-qubit gate is rebuilt from its _stage2 hyperedge, as in
to_qiskit. Measurements and conditional gates are replayed through
qml.measure and qml.cond.
Examples:
>>> import pennylane as qml
>>> script = qml.tape.QuantumScript([qml.Hadamard(0), qml.CNOT([0, 1])])
>>> [op.name for op in to_pennylane(from_pennylane(script)).operations]
['Hadamard', 'CNOT']
Source code in hdh\converters\pennylane_converter.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
hdh.converters.braket_converter.from_braket(bk)
Convert an Amazon Braket Circuit to an HDH.
Gates, including noise operations, are mapped by name, and measurements
are supported. Classical control flow raises NotImplementedError.
Examples:
>>> from braket.circuits import Circuit as BraketCircuit
>>> from_braket(BraketCircuit().h(0).cnot(0, 1)).get_num_qubits()
2
Source code in hdh\converters\braket_converter.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
Partitioning
hdh.passes.cut.compute_cut(hdh_graph, k, cap, *, beam_k=3, backtrack_window=0, polish_1swap_budget=0, restarts=1, reserve_frac=0.08, predictive_reject=True, seed=0)
Capacity-aware greedy partitioner: split an HDH across k devices of
cap qubits each, minimising cut hyperedges.
It assigns nodes (timestepped states) rather than whole qubits, so a
qubit's history may be split between devices when that is cheaper.
Capacity counts distinct quantum wires per device, and a split qubit uses
a slot on each device it touches, so splits are only made while enough
slots remain for every qubit not yet placed. This guarantees a complete
assignment whenever k * cap >= n_qubits. The remaining keyword
arguments are accepted for backwards compatibility and ignored.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> from hdh.models.circuit import Circuit
>>> c = Circuit()
>>> for q in range(3):
... c.add_instruction("cx", [q, q + 1])
>>> partitions, cost = compute_cut(c.build_hdh(), k=2, cap=2)
>>> cost
1
Source code in hdh\passes\cut.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
hdh.passes.cut.kahypar_cutter(hdh, k, cap, *, seed=0, config_path=None, suppress_output=True)
Partition by qubit with KaHyPar, keeping each qubit on one device.
Each quantum wire is one KaHyPar vertex, and the balance tolerance is set
so no block exceeds cap qubits. Classical nodes go with a qubit they
share a hyperedge with. Requires the kahypar extra.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> partitions, cut_cost = kahypar_cutter(hdh, k=2, cap=3)
Source code in hdh\passes\cut.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
hdh.passes.cut.kahypar_cutter_nodebalanced(hdh, k, *, seed=0, config_path=None, epsilon=0.03, suppress_output=True)
Partition nodes with KaHyPar, balancing node counts and ignoring qubit capacity.
A capacity-oblivious baseline: every node is a vertex of weight 1, and
blocks are balanced within epsilon in node count, not qubits. Useful for
measuring how often such a partitioner violates qubit capacity. Requires
the kahypar extra.
| Returns: |
|
|---|
Source code in hdh\passes\cut.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
hdh.passes.cut.metis_telegate(hdh, partitions, capacities)
Partition qubits with METIS on the telegate graph, then repair bins over capacity.
The telegate graph has one vertex per quantum wire and edges weighted by how many quantum operations two wires share. Falls back to Kernighan-Lin bisection when METIS is unavailable.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Examples:
>>> from hdh.models.circuit import Circuit
>>> c = Circuit()
>>> c.add_instruction("cx", [0, 1])
>>> c.add_instruction("cx", [2, 3])
>>> bins, cut_cost, fits, method = metis_telegate(c.build_hdh(), 2, 2)
>>> sorted(sorted(b) for b in bins), cut_cost, fits
([['q0', 'q1'], ['q2', 'q3']], 0, True)
Source code in hdh\passes\cut.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 | |
hdh.passes.cut.cost(hdh_graph, partitions)
Count cut hyperedges, separately for quantum and classical ones.
A hyperedge is cut when its nodes lie in more than one partition; nodes in no partition are ignored.
| Returns: |
|
|---|
Examples:
>>> from hdh.models.circuit import Circuit
>>> c = Circuit()
>>> c.add_instruction("cx", [0, 1])
>>> hdh = c.build_hdh()
>>> q0 = {n for n in hdh.nodes if hdh.wire_of[n] == "q0"}
>>> cost(hdh, [q0, hdh.nodes - q0])
(1.0, 0.0)
Source code in hdh\passes\cut.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |