Skip to content

Instantly share code, notes, and snippets.

@agnel
Last active May 17, 2022 06:58
Show Gist options
  • Save agnel/dabc621fec0cec17cf2717c4b057151c to your computer and use it in GitHub Desktop.
Save agnel/dabc621fec0cec17cf2717c4b057151c to your computer and use it in GitHub Desktop.
Solution to Qiskit Textbook Chapter 2 Exercise 3.4 Question 1
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "8da111d8-7b48-4eb8-aa45-a6cd1ba4d793",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$$\n",
"\\text{Statevector = }\n",
"\\begin{bmatrix}\n",
"0 & \\tfrac{1}{\\sqrt{2}} & \\tfrac{1}{\\sqrt{2}} & 0 \\\\\n",
" \\end{bmatrix}\n",
"$$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from qiskit import QuantumCircuit, Aer, assemble\n",
"from qiskit.visualization import array_to_latex\n",
"qc = QuantumCircuit(2)\n",
"qc.h(0)\n",
"qc.x(1)\n",
"qc.cx(0,1)\n",
"qc.draw()\n",
"qc.save_statevector()\n",
"sim = Aer.get_backend('aer_simulator')\n",
"result = sim.run(assemble(qc)).result()\n",
"array_to_latex(result.get_statevector(), prefix=\"\\\\text{Statevector = }\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1085260-e4f5-4950-9ab0-180ccc4a99ac",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Qiskit v0.35.0 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"0abefdd487974febaf5f2e5b73deff0f": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HTMLModel",
"state": {
"layout": "IPY_MODEL_b551ac1f8ec9410d9fed9279e828aca6",
"style": "IPY_MODEL_e6755939b37b4d76a601b099ea2da827",
"value": "<h5>Message</h5>"
}
},
"30d039b93433450a9d3aef55d9ea62df": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HTMLModel",
"state": {
"layout": "IPY_MODEL_bdce776c42c845578c33d44f05b13326",
"style": "IPY_MODEL_b0165a85fe08414fb58eb739e57f919d",
"value": "<h5>Status</h5>"
}
},
"36fe03a70549440f872f5b5527eb3e3a": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "GridBoxModel",
"state": {
"children": [
"IPY_MODEL_d17e4c3c7479493ea7c9be54eb3f136a"
],
"layout": "IPY_MODEL_bda17efdeb0a47bcbcb8048750ae0f11"
}
},
"39232b1cfc664d119817215d4f86e34d": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"width": "145px"
}
},
"6e83346e59c64463aa23283b7dd65b85": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HTMLModel",
"state": {
"layout": "IPY_MODEL_39232b1cfc664d119817215d4f86e34d",
"style": "IPY_MODEL_f85a925dcde84293baaa61eb9e059f54",
"value": "<h5>Backend</h5>"
}
},
"7dd5126057f3451f84a84d97fc958eb2": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"margin": "0px 0px 10px 0px"
}
},
"7ddd06f4ebb24498963e05a4fd83d86d": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "ButtonStyleModel",
"state": {}
},
"88af635c15284b5f8ef0cf7232a95169": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HTMLModel",
"state": {
"layout": "IPY_MODEL_f38f4aee7b184493ba26c046a079015e",
"style": "IPY_MODEL_fc0156a7d49b4d46b57a84938f56f16f",
"value": "<h5>Queue</h5>"
}
},
"a034a8c8dba242c2b1eacae540883ee4": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"a34bf992ac28432f9cd3c22f7a0a91d0": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HBoxModel",
"state": {
"children": [
"IPY_MODEL_ac3fa1c4688944c3b99ba3ff7b796cec",
"IPY_MODEL_6e83346e59c64463aa23283b7dd65b85",
"IPY_MODEL_30d039b93433450a9d3aef55d9ea62df",
"IPY_MODEL_88af635c15284b5f8ef0cf7232a95169",
"IPY_MODEL_0abefdd487974febaf5f2e5b73deff0f"
],
"layout": "IPY_MODEL_a97f231df03c4f63b7b30e66393d2368"
}
},
"a97f231df03c4f63b7b30e66393d2368": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"margin": "0px 0px 0px 37px",
"width": "600px"
}
},
"ac3fa1c4688944c3b99ba3ff7b796cec": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HTMLModel",
"state": {
"layout": "IPY_MODEL_bf32a7539bd6442b8b47c142ccf76145",
"style": "IPY_MODEL_a034a8c8dba242c2b1eacae540883ee4",
"value": "<h5>Job ID</h5>"
}
},
"b0165a85fe08414fb58eb739e57f919d": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"b551ac1f8ec9410d9fed9279e828aca6": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {}
},
"bda17efdeb0a47bcbcb8048750ae0f11": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"grid_template_areas": "\n \". . . . right \"\n ",
"grid_template_columns": "20% 20% 20% 20% 20%",
"width": "100%"
}
},
"bdce776c42c845578c33d44f05b13326": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"width": "95px"
}
},
"bf32a7539bd6442b8b47c142ccf76145": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"width": "190px"
}
},
"c2c366c43c044c9cbc9cdf0f3f348bc3": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"ce60f33a6ec34cb59800c92438d6f870": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "HTMLModel",
"state": {
"layout": "IPY_MODEL_7dd5126057f3451f84a84d97fc958eb2",
"style": "IPY_MODEL_c2c366c43c044c9cbc9cdf0f3f348bc3",
"value": "<p style='font-family: IBM Plex Sans, Arial, Helvetica, sans-serif; font-size: 20px; font-weight: medium;'>Circuit Properties</p>"
}
},
"d17e4c3c7479493ea7c9be54eb3f136a": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "ButtonModel",
"state": {
"button_style": "primary",
"description": "Clear",
"layout": "IPY_MODEL_dbb6fbf8930c44f8801ccfb3e8ed42c1",
"style": "IPY_MODEL_7ddd06f4ebb24498963e05a4fd83d86d"
}
},
"dbb6fbf8930c44f8801ccfb3e8ed42c1": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"grid_area": "right",
"padding": "0px 0px 0px 0px",
"width": "70px"
}
},
"e6755939b37b4d76a601b099ea2da827": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"f38f4aee7b184493ba26c046a079015e": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"width": "70px"
}
},
"f85a925dcde84293baaa61eb9e059f54": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"fc0156a7d49b4d46b57a84938f56f16f": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "1.5.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
}
},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment