|
177 | 177 | "metadata": {}, |
178 | 178 | "outputs": [], |
179 | 179 | "source": [ |
180 | | - "widg.indentCircuitLines = False\n", |
181 | 180 | "widg.curveConnectors = False\n", |
182 | 181 | "\n", |
183 | | - "# Can also specify at construction:\n", |
184 | | - "# CircuitWidget(stim=..., indentCircuitLines=False, curveConnectors=False)" |
| 182 | + "# Can also specify at construction, e.g.:\n", |
| 183 | + "# CircuitWidget(stim=..., curveConnectors=False)" |
185 | 184 | ] |
186 | 185 | }, |
187 | 186 | { |
|
276 | 275 | "For example, consider the circuit specification below which omits the '`#!pragma `' preceding its `MARKZ` instruction. Attempting to create a `stim.Circuit` will cause an error:" |
277 | 276 | ] |
278 | 277 | }, |
279 | | - { |
280 | | - "cell_type": "code", |
281 | | - "execution_count": null, |
282 | | - "id": "4aa33573", |
283 | | - "metadata": {}, |
284 | | - "outputs": [], |
285 | | - "source": [ |
286 | | - "%pip install stim" |
287 | | - ] |
288 | | - }, |
289 | 278 | { |
290 | 279 | "cell_type": "code", |
291 | 280 | "execution_count": null, |
|
367 | 356 | "The `traitlets` package used behind the scenes of both `CircuitWidget` and the widgets of `ipywidgets` allows for the composition of multiple widgets through functions like `link` and `dlink`. See the `ipywidgets` [documentation](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html#linking-widgets) for more advanced uses." |
368 | 357 | ] |
369 | 358 | }, |
370 | | - { |
371 | | - "cell_type": "code", |
372 | | - "execution_count": null, |
373 | | - "id": "e27207a6", |
374 | | - "metadata": {}, |
375 | | - "outputs": [], |
376 | | - "source": [ |
377 | | - "%pip install ipywidgets" |
378 | | - ] |
379 | | - }, |
380 | 359 | { |
381 | 360 | "cell_type": "markdown", |
382 | 361 | "id": "d3f8883a-12d8-4594-aec3-e7b98873ebe2", |
|
423 | 402 | "id": "ed2c23e0", |
424 | 403 | "metadata": {}, |
425 | 404 | "source": [ |
426 | | - "## Appendix: Converting to Stim" |
| 405 | + "### Converting Directly from a Circuit (`stim`, `cirq`, `qiskit`)" |
427 | 406 | ] |
428 | 407 | }, |
429 | 408 | { |
430 | 409 | "cell_type": "markdown", |
431 | 410 | "id": "ed4ffb4e", |
432 | 411 | "metadata": {}, |
433 | 412 | "source": [ |
434 | | - "If `stim` isn't your quantum circuit package of choice, it may still be possible to utilize CrumPy. Circuits from packages like `cirq` or `qiskit` may be convertible to a `stim` circuit (which can be easily converted to a string for use with `CircuitWidget`). For circuit languages that don't have an existing transpiler that converts to Stim, it may also be possible to convert to [OpenQASM](https://en.wikipedia.org/wiki/OpenQASM), which—while maybe not the most efficient—can be [converted to Cirq](https://quantumai.google/cirq/build/interop#importing_from_openqasm) and finally [converted to Stim](https://github.com/quantumlib/Stim/tree/main/glue/cirq#readme).\n", |
| 413 | + "CrumPy provides helper methods for creating a `CircuitWidget` directly from 3 popular quantum circuit packages: `stim`, `cirq`, and `qiskit`.\n", |
435 | 414 | "\n", |
436 | | - "Note that it may not always be possible to convert a circuit between formats (notably, `stim` has a [limited gate set](https://github.com/quantumlib/Stim/tree/main?tab=readme-ov-file#what-is-stim:~:text=There%20is%20no%20support%20for%20non%2DClifford%20operations%2C%20such%20as%20T%20gates%20and%20Toffoli%20gates.%20Only%20stabilizer%20operations%20are%20supported.))." |
| 415 | + "Even if `stim` isn't your quantum circuit package of choice, it may still be possible to utilize CrumPy. Circuits from packages like `cirq` or `qiskit` may be convertible to a `stim` circuit. For circuit languages that don't have an existing transpiler that converts directly to Stim, it may also be possible to convert to [OpenQASM](https://en.wikipedia.org/wiki/OpenQASM), which can be [converted to Cirq](https://quantumai.google/cirq/build/interop#importing_from_openqasm) and finally [converted to Stim](https://github.com/quantumlib/Stim/tree/main/glue/cirq#readme).\n", |
| 416 | + "\n", |
| 417 | + "Note that it may not always be possible to convert a circuit between formats (notably, `stim` has a [limited gate set](https://github.com/quantumlib/Stim/tree/main?tab=readme-ov-file#what-is-stim:~:text=There%20is%20no%20support%20for%20non%2DClifford%20operations%2C%20such%20as%20T%20gates%20and%20Toffoli%20gates.%20Only%20stabilizer%20operations%20are%20supported.)).\n", |
| 418 | + "\n" |
437 | 419 | ] |
438 | 420 | }, |
439 | 421 | { |
440 | 422 | "cell_type": "markdown", |
441 | 423 | "id": "b4dd3937", |
442 | 424 | "metadata": {}, |
443 | 425 | "source": [ |
444 | | - "### Example: `cirq` to `stim` with `stimcirq`" |
| 426 | + "#### Examples" |
| 427 | + ] |
| 428 | + }, |
| 429 | + { |
| 430 | + "cell_type": "markdown", |
| 431 | + "id": "30d3991d", |
| 432 | + "metadata": {}, |
| 433 | + "source": [ |
| 434 | + "`CircuitWidget.from_stim`" |
445 | 435 | ] |
446 | 436 | }, |
447 | 437 | { |
|
451 | 441 | "metadata": {}, |
452 | 442 | "outputs": [], |
453 | 443 | "source": [ |
454 | | - "%pip install cirq\n", |
455 | | - "%pip install stimcirq" |
| 444 | + "import stim\n", |
| 445 | + "\n", |
| 446 | + "stim_circuit = stim.Circuit(\"\"\"\n", |
| 447 | + "Y 0\n", |
| 448 | + "CY 0 1 \n", |
| 449 | + "\"\"\")\n", |
| 450 | + "\n", |
| 451 | + "CircuitWidget.from_stim(stim_circuit)" |
456 | 452 | ] |
457 | 453 | }, |
458 | 454 | { |
459 | 455 | "cell_type": "markdown", |
460 | | - "id": "7ad3a4cc", |
| 456 | + "id": "d2ee059f", |
461 | 457 | "metadata": {}, |
462 | 458 | "source": [ |
463 | | - "Let's create a simple `cirq` circuit we want converted to `stim` (note that importing cirq might take a minute):" |
| 459 | + "`CircuitWidget.from_cirq`" |
464 | 460 | ] |
465 | 461 | }, |
466 | 462 | { |
467 | 463 | "cell_type": "code", |
468 | 464 | "execution_count": null, |
469 | | - "id": "b089b365", |
| 465 | + "id": "0649f636", |
470 | 466 | "metadata": {}, |
471 | 467 | "outputs": [], |
472 | 468 | "source": [ |
473 | 469 | "import cirq\n", |
474 | 470 | "\n", |
475 | 471 | "q0 = cirq.LineQubit(0)\n", |
476 | 472 | "q1 = cirq.LineQubit(1)\n", |
477 | | - "cirq_circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))\n", |
| 473 | + "cirq_circuit = cirq.Circuit(cirq.X(q0), cirq.CNOT(q0, q1))\n", |
478 | 474 | "\n", |
479 | | - "cirq_circuit" |
| 475 | + "CircuitWidget.from_cirq(cirq_circuit)" |
480 | 476 | ] |
481 | 477 | }, |
482 | 478 | { |
483 | 479 | "cell_type": "markdown", |
484 | | - "id": "ad52fa36", |
| 480 | + "id": "ff13af42", |
485 | 481 | "metadata": {}, |
486 | 482 | "source": [ |
487 | | - "We can use the `stimcirq` package (a sub-package within the Stim project) to convert to a `stim.Circuit`:" |
| 483 | + "`CircuitWidget.from_qiskit`" |
488 | 484 | ] |
489 | 485 | }, |
490 | 486 | { |
491 | 487 | "cell_type": "code", |
492 | 488 | "execution_count": null, |
493 | | - "id": "6f24253b", |
| 489 | + "id": "8bf6aa0b", |
494 | 490 | "metadata": {}, |
495 | 491 | "outputs": [], |
496 | 492 | "source": [ |
497 | | - "import stimcirq\n", |
| 493 | + "import qiskit\n", |
| 494 | + "\n", |
| 495 | + "qiskit_circuit = qiskit.QuantumCircuit(2)\n", |
| 496 | + "qiskit_circuit.z(0)\n", |
| 497 | + "qiskit_circuit.cz(0, 1)\n", |
498 | 498 | "\n", |
499 | | - "converted_stim = stimcirq.cirq_circuit_to_stim_circuit(cirq_circuit)\n", |
500 | | - "converted_stim" |
| 499 | + "CircuitWidget.from_qiskit(qiskit_circuit)" |
501 | 500 | ] |
502 | 501 | }, |
503 | 502 | { |
504 | 503 | "cell_type": "markdown", |
505 | | - "id": "9e736aee", |
| 504 | + "id": "b3b2651f", |
506 | 505 | "metadata": {}, |
507 | 506 | "source": [ |
508 | | - "Note that for `CircuitWidget` compatibility, we need this circuit as a string:" |
509 | | - ] |
510 | | - }, |
511 | | - { |
512 | | - "cell_type": "code", |
513 | | - "execution_count": null, |
514 | | - "id": "432fe474", |
515 | | - "metadata": {}, |
516 | | - "outputs": [], |
517 | | - "source": [ |
518 | | - "converted_stim_str = str(converted_stim)\n", |
519 | | - "\n", |
520 | | - "CircuitWidget(stim=converted_stim_str)" |
| 507 | + "While it's not possible to directly add Pauli markers or other Crumble-specific instructions when creating `CircuitWidget`s with these methods, it is possible to read/write the resulting `CircuitWidget`'s `.stim` attribute to get the final converted Stim circuit (in string form), which can then be modified." |
521 | 508 | ] |
522 | 509 | } |
523 | 510 | ], |
524 | 511 | "metadata": { |
525 | 512 | "kernelspec": { |
526 | | - "display_name": "Python 3 (ipykernel)", |
| 513 | + "display_name": "crumpy", |
527 | 514 | "language": "python", |
528 | 515 | "name": "python3" |
529 | 516 | }, |
|
0 commit comments