Skip to content

Commit

Permalink
Updates for 0.43.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-naveh committed Jul 2, 2024
1 parent 9a61bf4 commit f3d45e2
Show file tree
Hide file tree
Showing 345 changed files with 19,145 additions and 38,903 deletions.
126 changes: 35 additions & 91 deletions algorithms/algebraic/discrete_log/discrete_log.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"id": "2bbc4aa3-8f61-433d-a1cd-c58df445a2fd",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:37:07.913701Z",
"iopub.status.busy": "2024-05-07T14:37:07.912478Z",
"iopub.status.idle": "2024-05-07T14:37:11.003827Z",
"shell.execute_reply": "2024-05-07T14:37:11.003192Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"from classiq.qmod import (\n",
Expand Down Expand Up @@ -122,16 +115,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"id": "d7fb63ac-023d-40ac-9395-13c1274d446f",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:37:11.006726Z",
"iopub.status.busy": "2024-05-07T14:37:11.006374Z",
"iopub.status.idle": "2024-05-07T14:37:11.011232Z",
"shell.execute_reply": "2024-05-07T14:37:11.010657Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"from classiq.qmod import hadamard_transform, invert, qft\n",
Expand All @@ -140,9 +126,9 @@
"\n",
"@qfunc\n",
"def discrete_log(\n",
" g_generator: CInt,\n",
" x_element: CInt,\n",
" N_modulus: CInt,\n",
" g: CInt,\n",
" x: CInt,\n",
" N: CInt,\n",
" order: CInt,\n",
" x1: Output[QArray[QBit]],\n",
" x2: Output[QArray[QBit]],\n",
Expand All @@ -155,7 +141,7 @@
" hadamard_transform(x1)\n",
" hadamard_transform(x2)\n",
"\n",
" discrete_log_oracle(g_generator, x_element, N_modulus, order, x1, x2, func_res)\n",
" discrete_log_oracle(g, x, N, order, x1, x2, func_res)\n",
"\n",
" invert(lambda: qft(x1))\n",
" invert(lambda: qft(x2))"
Expand Down Expand Up @@ -209,16 +195,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "8ef24bb4-b063-42d6-a5ea-ddcd5310ae13",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:37:11.014022Z",
"iopub.status.busy": "2024-05-07T14:37:11.013527Z",
"iopub.status.idle": "2024-05-07T14:37:11.017516Z",
"shell.execute_reply": "2024-05-07T14:37:11.016883Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"from classiq import Constraints, create_model\n",
Expand All @@ -240,22 +219,15 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"id": "8e9d0b08-f3f8-4e95-a468-bfeec010d97c",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:37:11.019590Z",
"iopub.status.busy": "2024-05-07T14:37:11.019416Z",
"iopub.status.idle": "2024-05-07T14:40:05.740675Z",
"shell.execute_reply": "2024-05-07T14:40:05.739982Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Opening: https://platform.classiq.io/circuit/2f88183e-39d4-4d7d-8a4c-fc6acdce4b40?version=0.41.0.dev39%2B79c8fd0855\n"
"Opening: http://localhost:4200/circuit/41ec5ffb-0221-449a-962a-a438c8c1a193?version=0.0.0\n"
]
}
],
Expand All @@ -272,36 +244,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "0aef2760-aa9a-4710-8c60-08333a0a9b0b",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:40:05.743207Z",
"iopub.status.busy": "2024-05-07T14:40:05.742818Z",
"iopub.status.idle": "2024-05-07T14:40:17.227966Z",
"shell.execute_reply": "2024-05-07T14:40:17.227272Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'x1': 2.0, 'x2': 2.0, 'func_res': 2.0}: 78,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 1.0}: 77,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 2.0}: 73,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 2.0}: 72,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 1.0}: 69,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 4.0}: 68,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 4.0}: 62,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 2.0}: 60,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 4.0}: 60,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 4.0}: 58,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 3.0}: 58,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 3.0}: 57,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 3.0}: 54,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 3.0}: 54,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 1.0}: 53,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 1.0}: 47]"
"[{'x1': 3.0, 'x2': 1.0, 'func_res': 4.0}: 79,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 1.0}: 67,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 1.0}: 66,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 3.0}: 66,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 2.0}: 66,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 3.0}: 66,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 2.0}: 64,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 2.0}: 63,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 4.0}: 62,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 1.0}: 62,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 2.0}: 61,\n",
" {'x1': 0.0, 'x2': 0.0, 'func_res': 4.0}: 60,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 3.0}: 57,\n",
" {'x1': 1.0, 'x2': 3.0, 'func_res': 4.0}: 56,\n",
" {'x1': 3.0, 'x2': 1.0, 'func_res': 3.0}: 55,\n",
" {'x1': 2.0, 'x2': 2.0, 'func_res': 1.0}: 50]"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -332,14 +297,7 @@
"cell_type": "code",
"execution_count": 6,
"id": "4aa286cd-7e4e-408f-90ed-910485becd71",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:40:17.230735Z",
"iopub.status.busy": "2024-05-07T14:40:17.230196Z",
"iopub.status.idle": "2024-05-07T14:40:17.234073Z",
"shell.execute_reply": "2024-05-07T14:40:17.233495Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -357,14 +315,7 @@
"cell_type": "code",
"execution_count": 7,
"id": "444d0916-e611-49fa-afc4-324e65240b34",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:40:17.236527Z",
"iopub.status.busy": "2024-05-07T14:40:17.236174Z",
"iopub.status.idle": "2024-05-07T14:40:17.239674Z",
"shell.execute_reply": "2024-05-07T14:40:17.239031Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -382,14 +333,7 @@
"cell_type": "code",
"execution_count": 8,
"id": "cbb1b0b3-6091-421b-85bb-7b9b8da0b724",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-07T14:40:17.242019Z",
"iopub.status.busy": "2024-05-07T14:40:17.241522Z",
"iopub.status.idle": "2024-05-07T14:40:17.245044Z",
"shell.execute_reply": "2024-05-07T14:40:17.244483Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -447,7 +391,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
5 changes: 2 additions & 3 deletions algorithms/algebraic/discrete_log/discrete_log.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ qfunc discrete_log_oracle<g_generator: int, x_element: int, N_modulus: int, orde
modular_exp<N_modulus, g_generator>(func_res, x2);
}

qfunc discrete_log<g_generator: int, x_element: int, N_modulus: int, order: int>(output x1: qbit[], output x2: qbit[], output func_res: qbit[]) {
qfunc discrete_log<g: int, x: int, N: int, order: int>(output x1: qbit[], output x2: qbit[], output func_res: qbit[]) {
allocate<ceiling(log(order, 2))>(x1);
allocate<ceiling(log(order, 2))>(x2);
hadamard_transform(x1);
hadamard_transform(x2);
discrete_log_oracle<g_generator, x_element, N_modulus, order>(x1, x2, func_res);
discrete_log_oracle<g, x, N, order>(x1, x2, func_res);
invert {
qft(x1);
}
Expand All @@ -22,4 +22,3 @@ qfunc discrete_log<g_generator: int, x_element: int, N_modulus: int, order: int>
qfunc main(output x1: qnum, output x2: qnum, output func_res: qnum) {
discrete_log<3, 2, 5, 4>(x1, x2, func_res);
}

16 changes: 8 additions & 8 deletions algorithms/algebraic/hidden_shift/hidden_shift_complex.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ qfunc hidden_shift<oracle: qfunc (arg0: qbit[]), oracle_shifted: qfunc (arg0: qb

qfunc main(output s: qbit[]) {
allocate<16>(s);
hidden_shift<lambda(arg0) {
phase_oracle<lambda(arg0, arg1) {
f_dual_qfunc(arg0, arg1);
}>(arg0);
}, lambda(arg0) {
phase_oracle<lambda(arg0, arg1) {
g_qfunc(arg0, arg1);
}>(arg0);
hidden_shift<lambda(y) {
phase_oracle<lambda(vars, result) {
f_dual_qfunc(vars, result);
}>(y);
}, lambda(y) {
phase_oracle<lambda(vars, result) {
g_qfunc(vars, result);
}>(y);
}>(s);
}
8 changes: 4 additions & 4 deletions algorithms/algebraic/hidden_shift/hidden_shift_no_dual.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ qfunc hidden_shift_no_dual<oracle: qfunc (arg0: qbit[], arg1: qbit), oracle_shif
qfunc main(output target: qbit[], output ind: qbit) {
allocate<16>(target);
allocate<1>(ind);
hidden_shift_no_dual<lambda(arg0, arg1) {
f_qfunc(arg0, arg1);
}, lambda(arg0, arg1) {
g_qfunc(arg0, arg1);
hidden_shift_no_dual<lambda(vars, result) {
f_qfunc(vars, result);
}, lambda(vars, result) {
g_qfunc(vars, result);
}>(target, ind);
}
16 changes: 8 additions & 8 deletions algorithms/algebraic/hidden_shift/hidden_shift_simple.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ qfunc hidden_shift<oracle: qfunc (arg0: qbit[]), oracle_shifted: qfunc (arg0: qb

qfunc main(output s: qbit[]) {
allocate<4>(s);
hidden_shift<lambda(arg0) {
phase_oracle<lambda(arg0, arg1) {
arith_func(arg0, arg1);
}>(arg0);
}, lambda(arg0) {
phase_oracle<lambda(arg0, arg1) {
arith_func_shifted(arg0, arg1);
}>(arg0);
hidden_shift<lambda(y) {
phase_oracle<lambda(vars, result) {
arith_func(vars, result);
}>(y);
}, lambda(y) {
phase_oracle<lambda(vars, result) {
arith_func_shifted(vars, result);
}>(y);
}>(s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ qfunc ccmod_add<N: int, a: int>(phi_b: qbit[], c1: qbit, c2: qbit, aux: qbit) {
ctrl -> {c1, c2};
}

qfunc main(output b: qnum, output ctrl: qbit[], output aux: qbit) {
qfunc main(output b: qnum, output ctrl: qbit[2], output aux: qbit) {
allocate<5>(b);
allocate<2>(ctrl);
allocate<1>(aux);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion algorithms/algebraic/shor/shor_modular_exponentiation.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ qfunc mod_exp_func<N: int, a: int>(x: qbit[], m: qbit[], aux: qbit) {
}
}

qfunc main(output x: qbit[], output power: qbit[], output aux: qbit) {
qfunc main(output x: qbit[], output power: qbit[6], output aux: qbit) {
allocate<3>(x);
allocate<6>(power);
allocate<1>(aux);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"friendly_name": "Amplitude Estimation",
"description": "Integral Evaluation using Amplitude Estimation",
"problem_domain_tags": [],
"problem_domain_tags": ["risk analysis"],
"qmod_type": ["algorithms"],
"level": ["demos"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ qfunc my_iqae_algorithm<k: int, oracle_operand: qfunc (arg0: qbit[]), sp_operand
qfunc main<k: int>(output ind_reg: qbit) {
full_reg: qbit[];
allocate<5>(full_reg);
my_iqae_algorithm<k, lambda(arg0) {
Z(arg0[arg0.len - 1]);
}, lambda(arg0) {
iqae_state_preparation(arg0[0:2], arg0[2:arg0.len - 1], arg0[arg0.len - 1]);
my_iqae_algorithm<k, lambda(x) {
Z(x[x.len - 1]);
}, lambda(x) {
iqae_state_preparation(x[0:2], x[2:x.len - 1], x[x.len - 1]);
}>(full_reg);
state_reg: qbit[4];
full_reg -> {state_reg, ind_reg};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ qfunc main(output phase_reg: qnum) {
allocate_num<5, False, 5>(phase_reg);
hadamard_transform(state_reg);
qpe<lambda() {
my_grover_operator<lambda(arg0) {
arith_oracle(arg0[0:2], arg0[2:arg0.len]);
}, lambda(arg0) {
hadamard_transform(arg0);
my_grover_operator<lambda(x) {
arith_oracle(x[0:2], x[2:x.len]);
}, lambda(x) {
hadamard_transform(x);
}>(state_reg);
}>(phase_reg);
}
4 changes: 1 addition & 3 deletions algorithms/bernstein_vazirani/bernstein_vazirani.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"\n",
"@qfunc\n",
"def bv_predicate(a: CInt, x: QArray, res: QBit):\n",
"\n",
" repeat(\n",
" x.len,\n",
" lambda i: if_(\n",
Expand Down Expand Up @@ -165,7 +164,6 @@
"\n",
"@qfunc\n",
"def bv_function(a: CInt, x: QArray):\n",
"\n",
" aux = QBit(\"aux\")\n",
" hadamard_transform(x)\n",
" within_apply(\n",
Expand Down Expand Up @@ -414,7 +412,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions algorithms/deutsch_jozsa/complex_deutsch_jozsa.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ qfunc my_oracle<predicate: qfunc (arg0: qnum, arg1: qbit)>(target: qnum) {

qfunc deutsch_jozsa<predicate: qfunc (arg0: qnum, arg1: qbit)>(x: qnum) {
hadamard_transform(x);
my_oracle<lambda(arg0, arg1) {
predicate(arg0, arg1);
my_oracle<lambda(x, y) {
predicate(x, y);
}>(x);
hadamard_transform(x);
}

qfunc main(output x: qnum) {
allocate<3>(x);
deutsch_jozsa<lambda(arg0, arg1) {
complex_predicate(arg0, arg1);
deutsch_jozsa<lambda(x, y) {
complex_predicate(x, y);
}>(x);
}
Loading

0 comments on commit f3d45e2

Please sign in to comment.