Skip to content

Commit f201f42

Browse files
committed
Changes to be committed:
modified: misc/notebooks/01_Data_Loading_Module_Use.ipynb
1 parent 55d9d16 commit f201f42

1 file changed

Lines changed: 56 additions & 20 deletions

File tree

misc/notebooks/01_Data_Loading_Module_Use.ipynb

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@
225225
"id": "8ca4a398",
226226
"metadata": {},
227227
"source": [
228-
"To load a discrete probability distribution we just need the function *load_probability*, which inside the **DL/data_loading** module. The input should be a numpy array with the probability distribution that we want to load into the quantum state. In this case the probability distribution is the variable *probability*. The output of the function is a **qlm** *AbstractGate* with arity *n*. "
228+
"To load a discrete probability distribution we just need the function *load_probability*, which inside the **DL/data_loading** module. The inputs are:\n",
229+
"\n",
230+
"* numpy array with the probability distribution that we want to load into the quantum state (**MANDATORY**). In this case the probability distribution is the variable *probability*.\n",
231+
"* id_name: string for giving a name to the Abstract Gate created by the function. If not name is provided then the cpu time will be added to the name.\n",
232+
"\n",
233+
"The output of the function is a **qlm** *AbstractGate* with arity *n*. "
229234
]
230235
},
231236
{
@@ -237,36 +242,36 @@
237242
},
238243
"outputs": [],
239244
"source": [
240-
"routine = load_probability(probability)"
241-
]
242-
},
243-
{
244-
"cell_type": "markdown",
245-
"id": "9f2d5768",
246-
"metadata": {},
247-
"source": [
248-
"Now, our quantum state has the form:\n",
249-
"$$\\left[\\sqrt{p_0}|0\\rangle+\\sqrt{p_1}|1\\rangle+\\sqrt{p_2}|2\\rangle+\\sqrt{p_3}|3\\rangle+\\sqrt{p_4}|4\\rangle+\\sqrt{p_5}|5\\rangle+\\sqrt{p_6}|6\\rangle+\\sqrt{p_7}|7\\rangle\\right]$$\n",
250-
"The corresponding circuit can be visualized directly passing the qlm routine *routine* to %qatdisplay."
245+
"#With id_name provided\n",
246+
"routine = load_probability(probability, 'toy')\n",
247+
"#Display circuit representation\n",
248+
"%qatdisplay routine --depth 0 --svg"
251249
]
252250
},
253251
{
254252
"cell_type": "code",
255253
"execution_count": null,
256-
"id": "c6b53c60",
254+
"id": "55bce45d",
257255
"metadata": {
258256
"scrolled": true
259257
},
260258
"outputs": [],
261259
"source": [
260+
"#No id_name provided\n",
261+
"routine = load_probability(probability)\n",
262+
"#Display circuit representation\n",
262263
"%qatdisplay routine --depth 0 --svg"
263264
]
264265
},
265266
{
266267
"cell_type": "markdown",
267-
"id": "5e4b04ac",
268+
"id": "9f2d5768",
268269
"metadata": {},
269270
"source": [
271+
"Now, our quantum state has the form:\n",
272+
"\n",
273+
"$$\\left[\\sqrt{p_0}|0\\rangle+\\sqrt{p_1}|1\\rangle+\\sqrt{p_2}|2\\rangle+\\sqrt{p_3}|3\\rangle+\\sqrt{p_4}|4\\rangle+\\sqrt{p_5}|5\\rangle+\\sqrt{p_6}|6\\rangle+\\sqrt{p_7}|7\\rangle\\right]$$\n",
274+
"\n",
270275
"Last, we use the function *get_results* from **data_extracting** to obtain the probabilities loaded into the quantum circuit. By the quantum properties, what we are measuring is:\n",
271276
"\n",
272277
"\n",
@@ -351,7 +356,7 @@
351356
"metadata": {},
352357
"outputs": [],
353358
"source": [
354-
"%qatdisplay routine --depth 1 --svg"
359+
"%qatdisplay routine --depth 0 --svg"
355360
]
356361
},
357362
{
@@ -360,8 +365,14 @@
360365
"metadata": {},
361366
"source": [
362367
"And the state now loaded in the circuit is:\n",
368+
"\n",
363369
"$$\\dfrac{1}{\\sqrt{N}}|0\\rangle\\left[|0\\rangle+|1\\rangle+|2\\rangle+|3\\rangle+|4\\rangle+|5\\rangle+|6\\rangle+|7\\rangle\\right]$$\n",
364-
"The next step is loading our array. For that we have the function *load_array* inside **DL/data_loading** module, this function takes as first argument a normalised array, one which has norm infinity equal or less than $1$. It admits a second argument called *method*. By default this second argument it is set to *multiplexors*, but it can also have the value *brute_force*. This second option is much less efficient in terms of quantum gates."
370+
"\n",
371+
"The next step is loading our array. For that we have the function *load_array* inside **DL/data_loading** module, this function takes following arguments:\n",
372+
"\n",
373+
"1. normalised array, one which has norm infinity equal or less than $1$. \n",
374+
"2. argument called *method*. By default this second argument it is set to *multiplexors*, but it can also have the value *brute_force*. This second option is much less efficient in terms of quantum gates.\n",
375+
"3. id_name: string for giving a name to the Abstract Gate created by the function. If not name is provided then the cpu time will be added to the name."
365376
]
366377
},
367378
{
@@ -374,14 +385,39 @@
374385
"from QQuantLib.DL.data_loading import load_array"
375386
]
376387
},
388+
{
389+
"cell_type": "code",
390+
"execution_count": null,
391+
"id": "780d7469",
392+
"metadata": {},
393+
"outputs": [],
394+
"source": [
395+
"#Not Providing id_name\n",
396+
"load_gate = load_array(f_normalised)\n",
397+
"%qatdisplay load_gate --depth 0 --svg"
398+
]
399+
},
400+
{
401+
"cell_type": "code",
402+
"execution_count": null,
403+
"id": "b8411534",
404+
"metadata": {},
405+
"outputs": [],
406+
"source": [
407+
"#Providing id_name\n",
408+
"load_gate = load_array(f_normalised, id_name='f')\n",
409+
"%qatdisplay load_gate --depth 0 --svg"
410+
]
411+
},
377412
{
378413
"cell_type": "code",
379414
"execution_count": null,
380415
"id": "253f68ae",
381416
"metadata": {},
382417
"outputs": [],
383418
"source": [
384-
"routine.apply(load_array(f_normalised),register)"
419+
"#Now apply the gate to the routine\n",
420+
"routine.apply(load_gate, register)"
385421
]
386422
},
387423
{
@@ -481,7 +517,7 @@
481517
"source": [
482518
"routine = qlm.QRoutine()\n",
483519
"register = routine.new_wires(n+1)\n",
484-
"routine.apply(load_probability(probability),register[:n])\n",
520+
"routine.apply(load_probability(probability, id_name='p(x)'),register[:n])\n",
485521
"%qatdisplay routine --depth 0 --svg"
486522
]
487523
},
@@ -510,7 +546,7 @@
510546
"outputs": [],
511547
"source": [
512548
"f_root = np.sqrt(f_normalised)\n",
513-
"routine.apply(load_array(f_root),register)\n",
549+
"routine.apply(load_array(f_root, id_name='f(x)'),register)\n",
514550
"%qatdisplay routine --depth 0 --svg"
515551
]
516552
},
@@ -1190,7 +1226,7 @@
11901226
"name": "python",
11911227
"nbconvert_exporter": "python",
11921228
"pygments_lexer": "ipython3",
1193-
"version": "3.9.11"
1229+
"version": "3.9.9"
11941230
}
11951231
},
11961232
"nbformat": 4,

0 commit comments

Comments
 (0)