Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
302 changes: 302 additions & 0 deletions algorithms/gqsp/gqsp.ipynb

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions algorithms/gqsp/gqsp.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"friendly_name": "GQSP (Generalized Quantum Signal Processing)",
"description": "Preparing a simple state, cos^3(x), with Generalized Quantum Signal Processing (GQSP)",
"qmod_type": ["algorithms"],
"level": ["basic", "demos"]
}
49 changes: 49 additions & 0 deletions algorithms/gqsp/gqsp.qmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
qfunc _gqsp_r_gate(theta: real, phi: real, _lambda: real, q: qbit) {
within {
X(q);
} apply {
U(2 * theta, phi, _lambda, 0, q);
}
Z(q);
}

qfunc u_func(x: qnum) {
phase (6.28318530718 * x);
}

qfunc main(output x: qnum<7, UNSIGNED, 7>, output ind: qbit) {
allocate(ind);
allocate(x);
hadamard_transform(x);
gqsp(lambda() {
u_func(x);
}, ind, [
[
0.187367215365,
2.117e-09,
0.598030945974,
5.783e-09,
0.5980309466,
2.117e-09,
1.383429110441
],
[
(-3.039e-09),
3.039e-09,
(-4.76e-10),
4.76e-10,
(-0.0),
(-3.14159265359),
0.0
],
[
3.14159265359,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
], 3);
}
44 changes: 44 additions & 0 deletions algorithms/gqsp/gqsp.synthesis_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"custom_hardware_settings": {
"basis_gates": [
"x",
"u2",
"t",
"s",
"u",
"sxdg",
"cz",
"y",
"r",
"z",
"u1",
"rz",
"rx",
"p",
"sx",
"h",
"ry",
"cy",
"sdg",
"tdg",
"id",
"cx"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"machine_precision": 8,
"optimization_level": 1,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 3681292980,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "auto optimize"
}
}
25 changes: 25 additions & 0 deletions tests/notebooks/test_gqsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient
import numpy as np


@wrap_testbook("gqsp", timeout_seconds=60)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test quantum programs
validate_quantum_program_size(
tb.ref_pydantic("qprog"),
expected_width=10, # actual 8
expected_depth=200, # actual 121
)

num_qubits = tb.ref_pydantic("NUM_QUBITS")
x, prob = tb.ref_pydantic("x"), tb.ref_pydantic("prob")
assert (
np.linalg.norm(
(1 / 2 ** (num_qubits / 2) * np.cos(2 * np.pi * x) ** 3) ** 2 - prob
)
< 0.1
)
2 changes: 2 additions & 0 deletions tests/resources/timeouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ facility_location.ipynb: 1656
facility_location.qmod: 1592
glued_trees.ipynb: 500
glued_trees_example.qmod: 200
gqsp.ipynb: 60
gqsp.qmod: 50
grover.ipynb: 120
grover_max_cut.qmod: 60
grover_operator.ipynb: 20
Expand Down
Loading