Skip to content
Merged

Qlbm #1270

Show file tree
Hide file tree
Changes from 4 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
1,547 changes: 1,547 additions & 0 deletions applications/cfd/qlbm/qlbm.ipynb

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions applications/cfd/qlbm/qlbm.qmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
qstruct PhaseSpaceStruct {
g_x: qnum<3>;
g_y: qnum<3>;
v_dir_x: qbit;
v_dir_y: qbit;
u_x: qnum<2>;
u_y: qnum<2>;
}

qfunc init_state2D_expanded___0(qs: PhaseSpaceStruct, g_dist_x: real[], g_dist_y: real[], u_dist: real[]) {
inplace_prepare_amplitudes(g_dist_x, 0, qs.g_x);
inplace_prepare_amplitudes(g_dist_y, 0, qs.g_y);
inplace_prepare_amplitudes(u_dist, 0, qs.u_x);
inplace_prepare_amplitudes(u_dist, 0, qs.u_y);
X(qs.v_dir_x);
H(qs.v_dir_y);
}

qfunc stream_expanded___0(qs: PhaseSpaceStruct) {
control (qs.u_x == 3) {
control (qs.v_dir_x) {
qs.g_x += 1;
} else {
qs.g_x += -1;
}
}
control (qs.u_y == 3) {
control (qs.v_dir_y) {
qs.g_y += 1;
} else {
qs.g_y += -1;
}
}
}

qfunc flip_velocity_expanded___0(change_pos: qnum<3, False, 0>, fixed_pos: qnum<3, False, 0>, change_u: qnum<2, False, 0>, change_v_dir: qbit, arr: real[]) {
control (((((change_pos == arr[0]) | (change_pos == arr[1])) & (fixed_pos >= arr[2])) & (fixed_pos <= arr[3])) & (change_u == 3)) {
X(change_v_dir);
}
}

qfunc reflection_expanded___0(qs: PhaseSpaceStruct, limits: real[]) {
flip_velocity_expanded___0(qs.g_y, qs.g_x, qs.u_y, qs.v_dir_y, [
limits[2],
limits[3],
limits[0],
limits[1]
]);
flip_velocity_expanded___0(qs.g_x, qs.g_y, qs.u_x, qs.v_dir_x, limits);
}

qfunc stream_expanded___1(qs: PhaseSpaceStruct) {
control (qs.u_x == 2) {
control (qs.v_dir_x) {
qs.g_x += 1;
} else {
qs.g_x += -1;
}
}
control (qs.u_y == 2) {
control (qs.v_dir_y) {
qs.g_y += 1;
} else {
qs.g_y += -1;
}
}
}

qfunc flip_velocity_expanded___1(change_pos: qnum<3, False, 0>, fixed_pos: qnum<3, False, 0>, change_u: qnum<2, False, 0>, change_v_dir: qbit, arr: real[]) {
control (((((change_pos == arr[0]) | (change_pos == arr[1])) & (fixed_pos >= arr[2])) & (fixed_pos <= arr[3])) & (change_u == 2)) {
X(change_v_dir);
}
}

qfunc reflection_expanded___1(qs: PhaseSpaceStruct, limits: real[]) {
flip_velocity_expanded___1(qs.g_y, qs.g_x, qs.u_y, qs.v_dir_y, [
limits[2],
limits[3],
limits[0],
limits[1]
]);
flip_velocity_expanded___1(qs.g_x, qs.g_y, qs.u_x, qs.v_dir_x, limits);
}

qfunc stream_expanded___2(qs: PhaseSpaceStruct) {
control (qs.u_x == 1) {
control (qs.v_dir_x) {
qs.g_x += 1;
} else {
qs.g_x += -1;
}
}
control (qs.u_y == 1) {
control (qs.v_dir_y) {
qs.g_y += 1;
} else {
qs.g_y += -1;
}
}
}

qfunc flip_velocity_expanded___2(change_pos: qnum<3, False, 0>, fixed_pos: qnum<3, False, 0>, change_u: qnum<2, False, 0>, change_v_dir: qbit, arr: real[]) {
control (((((change_pos == arr[0]) | (change_pos == arr[1])) & (fixed_pos >= arr[2])) & (fixed_pos <= arr[3])) & (change_u == 1)) {
X(change_v_dir);
}
}

qfunc reflection_expanded___2(qs: PhaseSpaceStruct, limits: real[]) {
flip_velocity_expanded___2(qs.g_y, qs.g_x, qs.u_y, qs.v_dir_y, [
limits[2],
limits[3],
limits[0],
limits[1]
]);
flip_velocity_expanded___2(qs.g_x, qs.g_y, qs.u_x, qs.v_dir_x, limits);
}

qfunc main(output qs: PhaseSpaceStruct) {
allocate(12, qs);
init_state2D_expanded___0(qs, [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0.25, 0.25, 0.25, 0.25]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
stream_expanded___1(qs);
reflection_expanded___1(qs, [2, 5, 1, 5]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
stream_expanded___2(qs);
reflection_expanded___2(qs, [2, 5, 1, 5]);
stream_expanded___1(qs);
reflection_expanded___1(qs, [2, 5, 1, 5]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
stream_expanded___1(qs);
reflection_expanded___1(qs, [2, 5, 1, 5]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
stream_expanded___2(qs);
reflection_expanded___2(qs, [2, 5, 1, 5]);
stream_expanded___1(qs);
reflection_expanded___1(qs, [2, 5, 1, 5]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
stream_expanded___0(qs);
reflection_expanded___0(qs, [2, 5, 1, 5]);
}
44 changes: 44 additions & 0 deletions applications/cfd/qlbm/qlbm.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": [
"sxdg",
"ry",
"tdg",
"sx",
"z",
"u",
"t",
"p",
"r",
"rx",
"s",
"u1",
"u2",
"x",
"rz",
"cy",
"id",
"h",
"y",
"cz",
"cx",
"sdg"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"machine_precision": 8,
"optimization_level": 1,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 1756940809,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "auto optimize"
}
}
Binary file added applications/cfd/qlbm/reflection_scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tests/notebooks/test_qlbm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from tests.utils_for_testbook import (
validate_quantum_program_size,
wrap_testbook,
)
from testbook.client import TestbookNotebookClient


@wrap_testbook("qlbm", timeout_seconds=400)
def test_notebook(tb: TestbookNotebookClient) -> None:
# test quantum programs
validate_quantum_program_size(
tb.ref_pydantic("qprog"),
expected_width=30,
expected_depth=45000,
)

# test notebook content
pass # Todo
2 changes: 2 additions & 0 deletions tests/resources/timeouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ qft.qmod: 10
qgan_bars_and_strips.ipynb: 360
qiskit_discrete_quantum_walk.ipynb: 300
qiskit_qsvt.ipynb: 300
qlbm.ipynb: 400
qlbm.qmod: 400
qls_chebyshev_lcu.ipynb: 800
qls_qsvt.ipynb: 600
qmc_user_defined.ipynb: 176
Expand Down
Loading