Skip to content

Commit

Permalink
Merge pull request #621 from qulacs/en-483
Browse files Browse the repository at this point in the history
Add English version for #483
  • Loading branch information
ikanago committed Mar 19, 2024
2 parents 011ca87 + c7c084f commit 98a2751
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 74 deletions.
60 changes: 55 additions & 5 deletions doc/en/source/guide/2.0_python_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3434,6 +3434,56 @@
"gate = Measurement(target, classical_pos)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### ProbabilisticInstrument\n",
"In addition to the `Probabilistic` function, it is a function that can get the index of the operated gate. If the sum of the distribution is less than 1, or for some other reason no gate has acted, the number of elements in `gate_list` is saved in `classical_address`."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 [0.70710678+0.j 0.70710678+0.j 0. +0.j 0. +0.j]\n",
"0 [0.+0.j 1.+0.j 0.+0.j 0.+0.j]\n",
"1 [0.-0.j 0.+1.j 0.-0.j 0.+0.j]\n",
"1 [0.-0.j 0.+1.j 0.-0.j 0.+0.j]\n",
"2 [0.70710678+0.j 0.70710678+0.j 0. +0.j 0. +0.j]\n",
"0 [0.+0.j 1.+0.j 0.+0.j 0.+0.j]\n",
"1 [0.-0.j 0.+1.j 0.-0.j 0.+0.j]\n",
"1 [0.-0.j 0.+1.j 0.-0.j 0.+0.j]\n",
"2 [0.70710678+0.j 0.70710678+0.j 0. +0.j 0. +0.j]\n",
"2 [0.70710678+0.j 0.70710678+0.j 0. +0.j 0. +0.j]\n"
]
}
],
"source": [
"from qulacs import QuantumState\n",
"from qulacs.gate import X, Y, H, ProbabilisticInstrument\n",
"n = 2\n",
"state = QuantumState(n)\n",
"index = 0\n",
"x_gate = X(index)\n",
"y_gate = Y(index)\n",
"h_gate = H(index)\n",
"distribution = [0.25, 0.25, 0.25]\n",
"gate_list = [x_gate, y_gate, h_gate]\n",
"classical_address = 0\n",
"for _ in range(10):\n",
" state = QuantumState(n)\n",
" probabilistic_instrument_gate = ProbabilisticInstrument(distribution, gate_list, classical_address)\n",
" probabilistic_instrument_gate.update_quantum_state(state)\n",
" result = state.get_classical_value(classical_address)\n",
" print(result, state.get_vector())\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -3940,7 +3990,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -4142,7 +4192,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -4342,7 +4392,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -4402,7 +4452,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -4677,7 +4727,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.11.4"
},
"vscode": {
"interpreter": {
Expand Down

0 comments on commit 98a2751

Please sign in to comment.