|
225 | 225 | "id": "8ca4a398", |
226 | 226 | "metadata": {}, |
227 | 227 | "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*. " |
229 | 234 | ] |
230 | 235 | }, |
231 | 236 | { |
|
237 | 242 | }, |
238 | 243 | "outputs": [], |
239 | 244 | "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" |
251 | 249 | ] |
252 | 250 | }, |
253 | 251 | { |
254 | 252 | "cell_type": "code", |
255 | 253 | "execution_count": null, |
256 | | - "id": "c6b53c60", |
| 254 | + "id": "55bce45d", |
257 | 255 | "metadata": { |
258 | 256 | "scrolled": true |
259 | 257 | }, |
260 | 258 | "outputs": [], |
261 | 259 | "source": [ |
| 260 | + "#No id_name provided\n", |
| 261 | + "routine = load_probability(probability)\n", |
| 262 | + "#Display circuit representation\n", |
262 | 263 | "%qatdisplay routine --depth 0 --svg" |
263 | 264 | ] |
264 | 265 | }, |
265 | 266 | { |
266 | 267 | "cell_type": "markdown", |
267 | | - "id": "5e4b04ac", |
| 268 | + "id": "9f2d5768", |
268 | 269 | "metadata": {}, |
269 | 270 | "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", |
270 | 275 | "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", |
271 | 276 | "\n", |
272 | 277 | "\n", |
|
351 | 356 | "metadata": {}, |
352 | 357 | "outputs": [], |
353 | 358 | "source": [ |
354 | | - "%qatdisplay routine --depth 1 --svg" |
| 359 | + "%qatdisplay routine --depth 0 --svg" |
355 | 360 | ] |
356 | 361 | }, |
357 | 362 | { |
|
360 | 365 | "metadata": {}, |
361 | 366 | "source": [ |
362 | 367 | "And the state now loaded in the circuit is:\n", |
| 368 | + "\n", |
363 | 369 | "$$\\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." |
365 | 376 | ] |
366 | 377 | }, |
367 | 378 | { |
|
374 | 385 | "from QQuantLib.DL.data_loading import load_array" |
375 | 386 | ] |
376 | 387 | }, |
| 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 | + }, |
377 | 412 | { |
378 | 413 | "cell_type": "code", |
379 | 414 | "execution_count": null, |
380 | 415 | "id": "253f68ae", |
381 | 416 | "metadata": {}, |
382 | 417 | "outputs": [], |
383 | 418 | "source": [ |
384 | | - "routine.apply(load_array(f_normalised),register)" |
| 419 | + "#Now apply the gate to the routine\n", |
| 420 | + "routine.apply(load_gate, register)" |
385 | 421 | ] |
386 | 422 | }, |
387 | 423 | { |
|
481 | 517 | "source": [ |
482 | 518 | "routine = qlm.QRoutine()\n", |
483 | 519 | "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", |
485 | 521 | "%qatdisplay routine --depth 0 --svg" |
486 | 522 | ] |
487 | 523 | }, |
|
510 | 546 | "outputs": [], |
511 | 547 | "source": [ |
512 | 548 | "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", |
514 | 550 | "%qatdisplay routine --depth 0 --svg" |
515 | 551 | ] |
516 | 552 | }, |
|
1190 | 1226 | "name": "python", |
1191 | 1227 | "nbconvert_exporter": "python", |
1192 | 1228 | "pygments_lexer": "ipython3", |
1193 | | - "version": "3.9.11" |
| 1229 | + "version": "3.9.9" |
1194 | 1230 | } |
1195 | 1231 | }, |
1196 | 1232 | "nbformat": 4, |
|
0 commit comments