Circuits¶
qsp_proc.circuits
¶
Public circuit builders and utilities for QSP constructions.
build_controlled_qsp_circuit(result, oracle, control_qubits=1, num_system_qubits=None)
¶
Build a controlled QSP circuit following Appendix E.1.
Qubit layout is:
[controls(0..c-1), ancilla(c), system(c+1..c+n)].
All signal-processing unitaries (E_0, V_j, V_j^\dagger) are
controlled on the extra control register. The signal oracle is applied only
on [ancilla, system] (i.e., no additional controls), enabling oracle
sharing across controlled branches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Recursive-carving decomposition containing |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal oracle |
required |
control_qubits
|
int
|
Number of additional control qubits. |
1
|
num_system_qubits
|
int | None
|
Number of system qubits. If |
None
|
Returns:
| Type | Description |
|---|---|
QuantumCircuit
|
A Qiskit |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input dimensions or qubit counts are invalid. |
TypeError
|
If |
Source code in src\qsp_proc\circuits\controlled.py
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 | |
build_lcu_circuit(results, oracle, num_system_qubits=None)
¶
Build the general LCU QSP circuit (Theorem 1).
For L = len(results), this constructs an LCU register of
l = ceil(log2(L)) ancillas, one QSP ancilla, and a system register.
The circuit prepares a uniform superposition on the LCU ancillas, applies
branch-local single-qubit basis changes conditioned on |k> with
interleaved/shared oracle layers across branches, pads any unused LCU basis
states with explicit zero-contribution branches, then uncomputes with
Hadamards. Post-selection on |0^l> yields the subnormalized block
(1 / 2^l) * sum_k P_k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[DecompositionResult]
|
Decomposition outputs, one per polynomial/QSP sequence in the LCU sum. |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal oracle as a Qiskit circuit or unitary matrix. |
required |
num_system_qubits
|
int | None
|
Number of system qubits. If |
None
|
Returns:
| Type | Description |
|---|---|
QuantumCircuit
|
A Qiskit circuit implementing the LCU-composed QSP construction. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs are empty, dimensions are invalid, or qubit counts are inconsistent. |
TypeError
|
If |
Source code in src\qsp_proc\circuits\lcu.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 | |
build_real_extraction_circuit(result, result_conj, oracle, num_system_qubits=None)
¶
Build the Appendix E.2 real-part extraction circuit (P + P*) / 2.
Qubit layout is fixed as:
- qubit 0: LCU ancilla,
- qubit 1: QSP ancilla,
- qubits 2..: system register.
The circuit implements the two-branch LCU pattern (Figure 10):
H on LCU ancilla, controlled-P on |0>, controlled-P* on
|1>, final H, and measurement of the LCU ancilla.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Decomposition result for |
required |
result_conj
|
DecompositionResult
|
Decomposition result for the conjugate branch |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal oracle as a Qiskit circuit or unitary matrix. |
required |
num_system_qubits
|
int | None
|
Number of system qubits. If |
None
|
Returns:
| Type | Description |
|---|---|
QuantumCircuit
|
A Qiskit circuit implementing real-part extraction via post-selection |
QuantumCircuit
|
on measured LCU ancilla |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\circuits\lcu.py
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 | |
build_qsp_circuit(result, oracle, num_system_qubits=None)
¶
Build the basic QSP circuit from a decomposition result.
Constructs the Figure-8-style ancilla + system circuit using the decomposition
data (e0, projectors, carve_sides) and a signal oracle U.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Decomposition output containing |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal operator |
required |
num_system_qubits
|
int | None
|
Number of system qubits. Inferred from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
QuantumCircuit
|
class: |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
verify_qsp_circuit(circuit, target_poly, thetas=None, num_samples=64, tol=1e-06, system_basis_index=0)
¶
Verify a QSP circuit against a target Laurent polynomial on sampled angles.
The circuit is evaluated pointwise in theta (binding its single parameter if
present), and the achieved polynomial is compared to target_poly(e^{i theta}).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
QuantumCircuit
|
QSP circuit to verify (optionally parameterized by |
required |
target_poly
|
LaurentPoly
|
Target Laurent polynomial. |
required |
thetas
|
ndarray | None
|
Optional explicit theta grid (radians). If |
None
|
num_samples
|
int
|
Number of uniform samples when |
64
|
tol
|
float
|
Non-negative tolerance used for input validation and optional logging. |
1e-06
|
system_basis_index
|
int
|
Computational-basis index within the postselected
ancilla- |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Maximum absolute error over sampled points. |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
projector_to_su2(projector)
¶
Build the ancilla-basis unitary V associated with a rank-1 projector.
Given P = |p><p| on C^2, this returns the 2x2 unitary
V = [p, p_perp] (columns), where p_perp is any normalized vector
orthogonal to p. Therefore V |0> = |p> and
P = V |0><0| V^\\dagger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projector
|
ndarray
|
Rank-1 projector with shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
qsp_proc.circuits.qsp_circuit
¶
Basic QSP circuit construction (Figure 8, Skelton 2025).
This module provides interfaces for converting decomposition outputs (projectors and constant residue) into an executable ancilla-system QSP circuit.
projector_to_su2(projector)
¶
Build the ancilla-basis unitary V associated with a rank-1 projector.
Given P = |p><p| on C^2, this returns the 2x2 unitary
V = [p, p_perp] (columns), where p_perp is any normalized vector
orthogonal to p. Therefore V |0> = |p> and
P = V |0><0| V^\\dagger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projector
|
ndarray
|
Rank-1 projector with shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
build_qsp_circuit(result, oracle, num_system_qubits=None)
¶
Build the basic QSP circuit from a decomposition result.
Constructs the Figure-8-style ancilla + system circuit using the decomposition
data (e0, projectors, carve_sides) and a signal oracle U.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Decomposition output containing |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal operator |
required |
num_system_qubits
|
int | None
|
Number of system qubits. Inferred from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
QuantumCircuit
|
class: |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
extract_polynomial_from_circuit(circuit, thetas, system_basis_index=0)
¶
Extract achieved QSP polynomial values from a (possibly parameterized) circuit.
For each theta, this function binds the circuit's single free parameter
(if present), computes the full unitary via :class:qiskit.quantum_info.Operator,
extracts the ancilla |0> -> |0> block, and returns one diagonal system-basis
entry from that block. This avoids trace-averaging across different oracle
eigenvalues, which is incorrect for non-symmetric Laurent polynomials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
QuantumCircuit
|
QSP circuit, optionally parameterized by a single angle parameter. |
required |
thetas
|
ndarray
|
Sample points in radians. |
required |
system_basis_index
|
int
|
Computational-basis index within the postselected system
block to read. Must satisfy |
0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex array of achieved polynomial values at each sample. |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
verify_qsp_circuit(circuit, target_poly, thetas=None, num_samples=64, tol=1e-06, system_basis_index=0)
¶
Verify a QSP circuit against a target Laurent polynomial on sampled angles.
The circuit is evaluated pointwise in theta (binding its single parameter if
present), and the achieved polynomial is compared to target_poly(e^{i theta}).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
QuantumCircuit
|
QSP circuit to verify (optionally parameterized by |
required |
target_poly
|
LaurentPoly
|
Target Laurent polynomial. |
required |
thetas
|
ndarray | None
|
Optional explicit theta grid (radians). If |
None
|
num_samples
|
int
|
Number of uniform samples when |
64
|
tol
|
float
|
Non-negative tolerance used for input validation and optional logging. |
1e-06
|
system_basis_index
|
int
|
Computational-basis index within the postselected
ancilla- |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Maximum absolute error over sampled points. |
Source code in src\qsp_proc\circuits\qsp_circuit.py
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 | |
qsp_proc.circuits.controlled
¶
Controlled QSP circuit construction utilities (Skelton 2025, Appendix E.1).
This module defines interfaces for building controlled-QSP circuits where the
QSP signal-processing operators (V_j and E_0) are controlled by
additional control qubits, while the signal oracle is left unchanged with
respect to those extra controls (it remains controlled only by the QSP ancilla,
as in the base construction). This pattern supports parallel execution of
multiple QSP sequences under shared oracle calls.
build_controlled_qsp_circuit(result, oracle, control_qubits=1, num_system_qubits=None)
¶
Build a controlled QSP circuit following Appendix E.1.
Qubit layout is:
[controls(0..c-1), ancilla(c), system(c+1..c+n)].
All signal-processing unitaries (E_0, V_j, V_j^\dagger) are
controlled on the extra control register. The signal oracle is applied only
on [ancilla, system] (i.e., no additional controls), enabling oracle
sharing across controlled branches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Recursive-carving decomposition containing |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal oracle |
required |
control_qubits
|
int
|
Number of additional control qubits. |
1
|
num_system_qubits
|
int | None
|
Number of system qubits. If |
None
|
Returns:
| Type | Description |
|---|---|
QuantumCircuit
|
A Qiskit |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input dimensions or qubit counts are invalid. |
TypeError
|
If |
Source code in src\qsp_proc\circuits\controlled.py
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 | |
qsp_proc.circuits.lcu
¶
LCU circuit-construction interfaces for QSP composition (Skelton 2025, Theorem 1).
This module declares circuit builders for linear-combination-of-unitaries (LCU) composition over multiple QSP sequences and a specialized real-part extraction construction from Appendix E.2 (Figure 10).
build_lcu_circuit(results, oracle, num_system_qubits=None)
¶
Build the general LCU QSP circuit (Theorem 1).
For L = len(results), this constructs an LCU register of
l = ceil(log2(L)) ancillas, one QSP ancilla, and a system register.
The circuit prepares a uniform superposition on the LCU ancillas, applies
branch-local single-qubit basis changes conditioned on |k> with
interleaved/shared oracle layers across branches, pads any unused LCU basis
states with explicit zero-contribution branches, then uncomputes with
Hadamards. Post-selection on |0^l> yields the subnormalized block
(1 / 2^l) * sum_k P_k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[DecompositionResult]
|
Decomposition outputs, one per polynomial/QSP sequence in the LCU sum. |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal oracle as a Qiskit circuit or unitary matrix. |
required |
num_system_qubits
|
int | None
|
Number of system qubits. If |
None
|
Returns:
| Type | Description |
|---|---|
QuantumCircuit
|
A Qiskit circuit implementing the LCU-composed QSP construction. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs are empty, dimensions are invalid, or qubit counts are inconsistent. |
TypeError
|
If |
Source code in src\qsp_proc\circuits\lcu.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 | |
build_real_extraction_circuit(result, result_conj, oracle, num_system_qubits=None)
¶
Build the Appendix E.2 real-part extraction circuit (P + P*) / 2.
Qubit layout is fixed as:
- qubit 0: LCU ancilla,
- qubit 1: QSP ancilla,
- qubits 2..: system register.
The circuit implements the two-branch LCU pattern (Figure 10):
H on LCU ancilla, controlled-P on |0>, controlled-P* on
|1>, final H, and measurement of the LCU ancilla.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Decomposition result for |
required |
result_conj
|
DecompositionResult
|
Decomposition result for the conjugate branch |
required |
oracle
|
QuantumCircuit | ndarray
|
Signal oracle as a Qiskit circuit or unitary matrix. |
required |
num_system_qubits
|
int | None
|
Number of system qubits. If |
None
|
Returns:
| Type | Description |
|---|---|
QuantumCircuit
|
A Qiskit circuit implementing real-part extraction via post-selection |
QuantumCircuit
|
on measured LCU ancilla |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\circuits\lcu.py
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 | |