Add deutsch algorithm
This commit is contained in:
parent
183396208f
commit
80b3e96fca
172
1.Introduction.ipynb
Normal file
172
1.Introduction.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -1,8 +1,17 @@
|
|||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "2953ed5d-b54c-41a7-8b01-11e9f4ffebea",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Используя вентили X, H и CNOT, можно проводить эксперименты с первым в мире алгоритмом квантовых вычислений: алгоритм Дойча [dɔitʃ] является одним из наиболее распространенных квантовых алгоритмов, который определяет тип функции. В отличие от классических алгоритмов, алгоритм Дойча демонстрирует ускорение алгоритмов\n",
|
||||||
|
"квантовых вычислений."
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 14,
|
||||||
"id": "fc7fe56b-71b4-498c-955d-e5e56af8f08e",
|
"id": "fc7fe56b-71b4-498c-955d-e5e56af8f08e",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -10,21 +19,24 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"{'10': 512, '11': 512}\n"
|
"{'11': 1024}\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"from spinqit import get_basic_simulator, get_compiler, Circuit, BasicSimulatorConfig\n",
|
"from spinqit import get_basic_simulator, get_compiler, Circuit, BasicSimulatorConfig\n",
|
||||||
"from spinqit import H, CX, Rx\n",
|
"from spinqit import H, X, Rx, CNOT\n",
|
||||||
"from math import pi\n",
|
"from math import pi\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Write the program\n",
|
"# Write the program\n",
|
||||||
"circ = Circuit()\n",
|
"circ = Circuit()\n",
|
||||||
"q = circ.allocateQubits(2)\n",
|
"q = circ.allocateQubits(2)\n",
|
||||||
"circ << (Rx, q[0], pi)\n",
|
"circ << (X, q[1])\n",
|
||||||
|
"circ << (H, q[0])\n",
|
||||||
|
"circ << (H, q[1])\n",
|
||||||
|
"circ << (CNOT, (q[0], q[1]))\n",
|
||||||
|
"circ << (H, q[0])\n",
|
||||||
"circ << (H, q[1])\n",
|
"circ << (H, q[1])\n",
|
||||||
"circ << (CX, (q[0], q[1]))\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"# Choose the compiler and backend\n",
|
"# Choose the compiler and backend\n",
|
||||||
"comp = get_compiler(\"native\")\n",
|
"comp = get_compiler(\"native\")\n",
|
||||||
@ -41,6 +53,22 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"print(result.counts)"
|
"print(result.counts)"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "c8fd21c4-ce4b-4d47-8bf6-ca241e994d1e",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "0c9946b4-0366-4129-ac6e-1e138309ee5f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
25
main.py
25
main.py
@ -1,25 +0,0 @@
|
|||||||
from spinqit import get_basic_simulator, get_compiler, Circuit, BasicSimulatorConfig
|
|
||||||
from spinqit import H, CX, Rx
|
|
||||||
from math import pi
|
|
||||||
|
|
||||||
# Write the program
|
|
||||||
circ = Circuit()
|
|
||||||
q = circ.allocateQubits(2)
|
|
||||||
circ << (Rx, q[0], pi)
|
|
||||||
circ << (H, q[1])
|
|
||||||
circ << (CX, (q[0], q[1]))
|
|
||||||
|
|
||||||
# Choose the compiler and backend
|
|
||||||
comp = get_compiler("native")
|
|
||||||
engine = get_basic_simulator()
|
|
||||||
|
|
||||||
# Compile
|
|
||||||
optimization_level = 0
|
|
||||||
exe = comp.compile(circ, optimization_level)
|
|
||||||
|
|
||||||
# Run
|
|
||||||
config = BasicSimulatorConfig()
|
|
||||||
config.configure_shots(1024)
|
|
||||||
result = engine.execute(exe, config)
|
|
||||||
|
|
||||||
print(result.counts)
|
|
Loading…
Reference in New Issue
Block a user