Skip to content

Instantly share code, notes, and snippets.

@cgranade
Created January 12, 2022 02:56
Show Gist options
  • Save cgranade/7c2a5a0827dddc4281666ad45763b1ec to your computer and use it in GitHub Desktop.
Save cgranade/7c2a5a0827dddc4281666ad45763b1ec to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "d4eab2a5",
"metadata": {},
"outputs": [],
"source": [
"import qutip\n",
"from qutip.qinstrument import (\n",
" QInstrument,\n",
" basis_measurement,\n",
" pauli_measurement\n",
")"
]
},
{
"cell_type": "markdown",
"id": "8f488f31",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Basics of instruments"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9c0d3906",
"metadata": {},
"outputs": [],
"source": [
"H = qutip.operations.hadamard_transform()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4bc13109",
"metadata": {},
"outputs": [],
"source": [
"ket_plus = H * qutip.basis(2, 0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f686f39e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190ff7e80 {\n",
" dims [[[2], [2]], [[2], [2]]]\n",
" outcomes Seq(0,) Seq(1,)\n",
"}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument = basis_measurement(2)\n",
"z_instrument"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "bb07de40",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(Seq(0,),\n",
" Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
" Qobj data =\n",
" [[1. 0.]\n",
" [0. 0.]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument.sample(ket_plus)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "1d8ae9ef",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
"{Seq(0,): Outcome(probability=0.5000000000000002, output_state=Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
" Qobj data =\n",
" [[0.5 0.5]\n",
" [0.5 0.5]]),\n",
" Seq(1,): Outcome(probability=0.5000000000000002, output_state=Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
" Qobj data =\n",
" [[ 0.5 -0.5]\n",
" [-0.5 0.5]])}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(H * z_instrument)(ket_plus)"
]
},
{
"cell_type": "markdown",
"id": "636196ae",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Combining instruments"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "13b73f44",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190ff9d00 {\n",
" dims [[[2], [2]], [[2], [2]]]\n",
" outcomes Seq(0, 0) Seq(1, 1)\n",
"}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument * z_instrument"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c51d19d8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190ff9460 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(Par(0, 0),) Seq(Par(0, 1),) Seq(Par(1, 0),) Seq(Par(1, 1),)\n",
"}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"qutip.tensor([z_instrument] * 2)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8bee7008",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190ff3880 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(Par(Seq(0, 0), 0),) Seq(Par(Seq(0, 0), 1),) Seq(Par(Seq(1, 0), 0),) Seq(Par(Seq(1, 0), 1),) Seq(Par(Seq(0, 1), 0),) Seq(Par(Seq(0, 1), 1),) Seq(Par(Seq(1, 1), 0),) Seq(Par(Seq(1, 1), 1),)\n",
"}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"qutip.tensor(z_instrument.with_finite_visibility(0.95) ** 2, z_instrument)"
]
},
{
"cell_type": "markdown",
"id": "2877bc44",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Eliminating impossible outcomes"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "667488ad",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190ff3d90 {\n",
" dims [[[2], [2]], [[2], [2]]]\n",
" outcomes Seq(0, 0) Seq(1, 1)\n",
"}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument * z_instrument"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "821761cc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fc7550 {\n",
" dims [[[2], [2]], [[2], [2]]]\n",
" outcomes Seq(0, 0) Seq(1, 0) Seq(0, 1) Seq(1, 1)\n",
"}"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument.with_finite_visibility(0.95) ** 2"
]
},
{
"cell_type": "markdown",
"id": "dd2fea77",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Arbitrary dims"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b8879dd3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fc79d0 {\n",
" dims [[[3], [3]], [[3], [3]]]\n",
" outcomes Seq(0,) Seq(1,) Seq(2,)\n",
"}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"basis_measurement(3)"
]
},
{
"cell_type": "markdown",
"id": "88544446",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Incomplete instruments"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "5ba4d69a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fc7b50 {\n",
" dims [[[4], [4]], [[4], [4]]]\n",
" outcomes Seq() Seq('⊥',)\n",
"}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"qutip.QInstrument(qutip.projection(4, 0, 0)).complete()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "66cd8660",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fc7eb0 {\n",
" dims [[[4], [4]], [[4], [4]]]\n",
" outcomes Seq(0,) Seq(1,)\n",
"}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"qutip.QInstrument(qutip.projection(4, 0, 0)).complete().reindex()"
]
},
{
"cell_type": "markdown",
"id": "a467b7f5",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Arbitrary outcome labels"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "43b73db9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fbc9d0 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(+XX, +ZZ) Seq(-XX, +ZZ) Seq(+XX, -ZZ) Seq(-XX, -ZZ)\n",
"}"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pauli_measurement(\"ZZ\") * pauli_measurement(\"XX\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "1a6fea6c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fbccd0 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(+XX, +ZZ, +XX, +ZZ) Seq(-XX, +ZZ, -XX, +ZZ) Seq(+XX, -ZZ, +XX, -ZZ) Seq(-XX, -ZZ, -XX, -ZZ)\n",
"}"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(pauli_measurement(\"ZZ\") * pauli_measurement(\"XX\")) ** 2"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b07ab3d7",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fb1ac0 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(+XX, +ZZ, +XX, +ZZ) Seq(-XX, +ZZ, +XX, +ZZ) Seq(+XX, -ZZ, +XX, +ZZ) Seq(-XX, -ZZ, +XX, +ZZ) Seq(+XX, +ZZ, -XX, +ZZ) Seq(-XX, +ZZ, -XX, +ZZ) Seq(+XX, -ZZ, -XX, +ZZ) Seq(-XX, -ZZ, -XX, +ZZ) Seq(+XX, +ZZ, +XX, -ZZ) Seq(-XX, +ZZ, +XX, -ZZ) Seq(+XX, -ZZ, +XX, -ZZ) Seq(-XX, -ZZ, +XX, -ZZ) Seq(+XX, +ZZ, -XX, -ZZ) Seq(-XX, +ZZ, -XX, -ZZ) Seq(+XX, -ZZ, -XX, -ZZ) Seq(-XX, -ZZ, -XX, -ZZ)\n",
"}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(\n",
" pauli_measurement(\"ZZ\") * pauli_measurement(\"XX\")\n",
").with_finite_visibility(0.95) ** 2"
]
},
{
"cell_type": "markdown",
"id": "98e1163a",
"metadata": {},
"source": [
"When using custom output labels, you can specify sequences of outcomes with `,` and parallel outcomes with `;`. Integers in strings are automatically converted, but other strings are preserved."
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "0a6f32a4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fb1f70 {\n",
" dims [[[4], [4]], [[4], [4]]]\n",
" outcomes Seq(Par(Seq(0, 1, 2), Seq(4, '⊥')),)\n",
"}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"QInstrument({\n",
" '0, 1, 2; 4, ⊥': qutip.projection(4, 0, 0)\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "391107b5",
"metadata": {},
"source": [
"For more complicated labels, `Seq` and `Par` can also be used directly. For example, the string `'0, 1, 2; 4, ⊥'` can also be written more explicitly as `Seq(Par(Seq(0, 1, 2), Seq(4, '⊥')),)`."
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "a8c0c0ad",
"metadata": {},
"outputs": [],
"source": [
"from qutip.qinstrument import Seq, Par"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "c8545e5a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=2319106e490 {\n",
" dims [[[4], [4]], [[4], [4]]]\n",
" outcomes Seq(Par(Seq(0, 1, 2), Seq(4, '⊥')),) Seq(Par(Seq(0, 1, 2), Seq(Par('A', 'B'), 'C')),)\n",
"}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"QInstrument({\n",
" Seq(Par(Seq(0, 1, 2), Seq(4, '⊥')),): qutip.projection(4, 0, 0),\n",
" Seq(Par(Seq(0, 1, 2), Seq(Par('A', 'B'), 'C')),): qutip.projection(4, 1, 1)\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "85704c93",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Nonselective processes"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "c2d9fcd6",
"metadata": {},
"outputs": [],
"source": [
"ins = (\n",
" pauli_measurement(\"ZZ\") * pauli_measurement(\"XX\")\n",
").with_finite_visibility(0.95) ** 2"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "945bb514",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[[2, 2], [2, 2]], [[2, 2], [2, 2]]], shape=(16, 16), type='super', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}0.501 & 0 & 0 & -2.082\\times10^{ -17 } & 0 & \\cdots & 0 & -2.082\\times10^{ -17 } & 0 & 0 & 0.499\\\\0 & 0.003 & 0 & 0 & 0 & \\cdots & 0 & 0 & 0 & 0 & 0\\\\0 & 0 & 0.003 & 0 & 0 & \\cdots & 0 & 0 & 0 & 0 & 0\\\\-2.082\\times10^{ -17 } & 0 & 0 & 0.501 & 0 & \\cdots & 0 & 0.499 & 0 & 0 & -2.082\\times10^{ -17 }\\\\0 & 0 & 0 & 0 & 0.003 & \\cdots & 0 & 0 & 0 & 0 & 0\\\\\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots\\\\0 & 0 & 0 & 0 & 0 & \\cdots & 0.003 & 0 & 0 & 0 & 0\\\\-2.082\\times10^{ -17 } & 0 & 0 & 0.499 & 0 & \\cdots & 0 & 0.501 & 0 & 0 & -2.082\\times10^{ -17 }\\\\0 & 0 & 0 & 0 & 0 & \\cdots & 0 & 0 & 0.003 & 0 & 0\\\\0 & 0 & 0 & 0 & 0 & \\cdots & 0 & 0 & 0 & 0.003 & 0\\\\0.499 & 0 & 0 & -2.082\\times10^{ -17 } & 0 & \\cdots & 0 & -2.082\\times10^{ -17 } & 0 & 0 & 0.501\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[[2, 2], [2, 2]], [[2, 2], [2, 2]]], shape=(16, 16), type='super', isherm=True\n",
"Qobj data =\n",
"[[ 5.01250000e-01 0.00000000e+00 0.00000000e+00 -2.08166817e-17\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" -2.08166817e-17 0.00000000e+00 0.00000000e+00 4.98750000e-01]\n",
" [ 0.00000000e+00 2.50000000e-03 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 2.50000000e-03 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [-2.08166817e-17 0.00000000e+00 0.00000000e+00 5.01250000e-01\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 4.98750000e-01 0.00000000e+00 0.00000000e+00 -2.08166817e-17]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 2.50000000e-03 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 5.01250000e-01 2.77555756e-17 0.00000000e+00\n",
" 0.00000000e+00 2.77555756e-17 4.98750000e-01 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 2.77555756e-17 5.01250000e-01 0.00000000e+00\n",
" 0.00000000e+00 4.98750000e-01 2.77555756e-17 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 2.50000000e-03\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 2.50000000e-03 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 2.77555756e-17 4.98750000e-01 0.00000000e+00\n",
" 0.00000000e+00 5.01250000e-01 2.77555756e-17 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 4.98750000e-01 2.77555756e-17 0.00000000e+00\n",
" 0.00000000e+00 2.77555756e-17 5.01250000e-01 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 2.50000000e-03\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
" [-2.08166817e-17 0.00000000e+00 0.00000000e+00 4.98750000e-01\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 5.01250000e-01 0.00000000e+00 0.00000000e+00 -2.08166817e-17]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 2.50000000e-03 0.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 2.50000000e-03 0.00000000e+00]\n",
" [ 4.98750000e-01 0.00000000e+00 0.00000000e+00 -2.08166817e-17\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00\n",
" -2.08166817e-17 0.00000000e+00 0.00000000e+00 5.01250000e-01]]"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ins.nonselective_process"
]
},
{
"cell_type": "markdown",
"id": "e3bd961c",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Checking CP/TP/HP"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "0db1c92c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ins.iscptp"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "8bb4f873",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ins.ishp"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "895fe604",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ins.istp"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "77cbd8dd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ins.iscp"
]
},
{
"cell_type": "markdown",
"id": "ecb2ad45",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Operator overloading"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "affb2378",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=2319108d730 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(Par(0, 0),) Seq(Par(0, 1),) Seq(Par(1, 0),) Seq(Par(1, 1),)\n",
"}"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument & z_instrument.with_finite_visibility(0.95)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "78b477fa",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=23190fc7df0 {\n",
" dims [[[2, 2, 2], [2, 2, 2]], [[2, 2, 2], [2, 2, 2]]]\n",
" outcomes Seq(Par(0, 0, 0),) Seq(Par(0, 0, 1),) Seq(Par(0, 1, 0),) Seq(Par(0, 1, 1),) Seq(Par(1, 0, 0),) Seq(Par(1, 0, 1),) Seq(Par(1, 1, 0),) Seq(Par(1, 1, 1),)\n",
"}"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument ^ 3"
]
},
{
"cell_type": "markdown",
"id": "caa872a1",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Conditional processes"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "d0b19014",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=2319108d4c0 {\n",
" dims [[[2], [2]], [[2], [2]]]\n",
" outcomes Seq(0,) Seq(1,)\n",
"}"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reset = z_instrument.if_({\n",
" 1: qutip.to_super(qutip.sigmax())\n",
"})\n",
"reset"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "4c57edf0",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[[2], [2]], [[2], [2]]], shape=(4, 4), type='super', isherm=False\\begin{equation*}\\left(\\begin{array}{*{11}c}1 & 0 & 0 & 1\\\\0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[[2], [2]], [[2], [2]]], shape=(4, 4), type='super', isherm=False\n",
"Qobj data =\n",
"[[1. 0. 0. 1.]\n",
" [0. 0. 0. 0.]\n",
" [0. 0. 0. 0.]\n",
" [0. 0. 0. 0.]]"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reset.nonselective_process"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "6a4c3637",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=2319108d490 {\n",
" dims [[[2], [2]], [[2], [2]]]\n",
" outcomes Seq(0,) Seq(1,)\n",
"}"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z_instrument.if_({\n",
" 1: qutip.QInstrument(qutip.to_super(qutip.sigmax()))\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "b3e26192",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"V = (\n",
" (qutip.qeye(2) & qutip.qip.operations.cnot()) *\n",
" (qutip.qeye(2) & qutip.qip.operations.hadamard_transform() & qutip.qeye(2)) *\n",
" (qutip.qeye(2) & qutip.basis(2, 0) & qutip.basis(2, 0))\n",
")\n",
" \n",
"prepare_bell = qutip.sprepost(V, V.dag())"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "f6f038d2",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[[2, 2, 2], [2, 2, 2]], [[2], [2]]], shape=(64, 4), type='super', isherm=False\\begin{equation*}\\left(\\begin{array}{*{11}c}0.500 & 0 & 0 & 0\\\\0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0\\\\0.500 & 0 & 0 & 0\\\\0 & 0.500 & 0 & 0\\\\\\vdots & \\vdots & \\vdots & \\vdots\\\\0 & 0 & 0.500 & 0\\\\0 & 0 & 0 & 0.500\\\\0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0.500\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[[2, 2, 2], [2, 2, 2]], [[2], [2]]], shape=(64, 4), type='super', isherm=False\n",
"Qobj data =\n",
"[[0.5 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0.5 0. 0. 0. ]\n",
" [0. 0.5 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0.5 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0.5 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0.5 0. 0. 0. ]\n",
" [0. 0.5 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0.5 0. 0. ]\n",
" [0. 0. 0.5 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0.5 0. ]\n",
" [0. 0. 0. 0.5]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0.5]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0.5 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0.5 0. ]\n",
" [0. 0. 0. 0.5]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0.5]]"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prepare_bell"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "29578328",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}1 & 0\\\\0 & 0\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
"Qobj data =\n",
"[[1. 0.]\n",
" [0. 0.]]"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prepare_bell(qutip.basis(2, 0)).ptrace([0])"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "b269cf9f",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[2, 2], [2, 2]], shape=(4, 4), type='oper', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}0.500 & 0 & 0 & 0.500\\\\0 & 0 & 0 & 0\\\\0 & 0 & 0 & 0\\\\0.500 & 0 & 0 & 0.500\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[2, 2], [2, 2]], shape=(4, 4), type='oper', isherm=True\n",
"Qobj data =\n",
"[[0.5 0. 0. 0.5]\n",
" [0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. ]\n",
" [0.5 0. 0. 0.5]]"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prepare_bell(qutip.basis(2, 0)).ptrace([1, 2])"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "6fbd297f",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"bell_measurement = pauli_measurement(\"ZZ\") * pauli_measurement(\"XX\")"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "527c6716",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=2319108d6a0 {\n",
" dims [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]\n",
" outcomes Seq(+XX, +ZZ) Seq(-XX, +ZZ) Seq(+XX, -ZZ) Seq(-XX, -ZZ)\n",
"}"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bell_measurement"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "6254f6c0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QInstrument id=231910999d0 {\n",
" dims [[[2, 2, 2], [2, 2, 2]], [[2], [2]]]\n",
" outcomes Seq(+XX, +ZZ) Seq(-XX, +ZZ) Seq(+XX, -ZZ) Seq(-XX, -ZZ)\n",
"}"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"teleport_wo_correction = (\n",
" (bell_measurement & qutip.to_super(qutip.qeye(2))) *\n",
" prepare_bell\n",
")\n",
"teleport_wo_correction"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "77ce500d",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"teleport = teleport_wo_correction.if_({\n",
" qutip.Seq(\"XX\", \"ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.qeye(2)),\n",
" qutip.Seq(\"-XX\", \"ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.sigmaz()),\n",
" qutip.Seq(\"XX\", \"-ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.sigmax()),\n",
" qutip.Seq(\"-XX\", \"-ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.sigmay()),\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "7d5e9d0c",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}1 & 0\\\\0 & 0\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
"Qobj data =\n",
"[[1. 0.]\n",
" [0. 0.]]"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"teleport.nonselective_process(qutip.basis(2, 0)).ptrace([2])"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "bc075928",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}0 & 0\\\\0 & 1\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
"Qobj data =\n",
"[[0. 0.]\n",
" [0. 1.]]"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"teleport.nonselective_process(qutip.basis(2, 1)).ptrace([2])"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "049fdfe1",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}0.500 & 0.500\\\\0.500 & 0.500\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
"Qobj data =\n",
"[[0.5 0.5]\n",
" [0.5 0.5]]"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"teleport.nonselective_process(qutip.qip.operations.hadamard_transform() * qutip.basis(2, 0)).ptrace([2])"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "e27a077a",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"teleport_wo_correction = (\n",
" (bell_measurement.with_finite_visibility(0.95) & qutip.to_super(qutip.qeye(2))) *\n",
" prepare_bell\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "13885daa",
"metadata": {},
"outputs": [],
"source": [
"teleport = teleport_wo_correction.if_({\n",
" qutip.Seq(\"XX\", \"ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.qeye(2)),\n",
" qutip.Seq(\"-XX\", \"ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.sigmaz()),\n",
" qutip.Seq(\"XX\", \"-ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.sigmax()),\n",
" qutip.Seq(\"-XX\", \"-ZZ\"): qutip.to_super((qutip.qeye(2) ^ 2) & qutip.sigmay()),\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "8aa10550",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\\begin{equation*}\\left(\\begin{array}{*{11}c}0.500 & 0.475\\\\0.475 & 0.500\\end{array}\\right)\\end{equation*}"
],
"text/plain": [
"Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', isherm=True\n",
"Qobj data =\n",
"[[0.5 0.475]\n",
" [0.475 0.5 ]]"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"teleport.nonselective_process(qutip.qip.operations.hadamard_transform() * qutip.basis(2, 0)).ptrace([2])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60cbb857",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment