Last active
June 11, 2020 00:53
-
-
Save crazy4pi314/516936ac7777660d2694eb9d7f957263 to your computer and use it in GitHub Desktop.
ControlledOnBitString-behavior-sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "\"true\"", | |
"text/plain": [ | |
"true" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%config dump.truncateSmallAmplitudes = true" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "\"\\\"bitstring\\\"\"", | |
"text/plain": [ | |
"\"bitstring\"" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%config dump.basisStateLabelingConvention = \"bitstring\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "[\"ControllingStringCorrectLength\",\"ControllingStringShort\"]", | |
"text/html": [ | |
"<ul><li>ControllingStringCorrectLength</li><li>ControllingStringShort</li></ul>" | |
], | |
"text/plain": [ | |
"ControllingStringCorrectLength, ControllingStringShort" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"open Microsoft.Quantum.Diagnostics;\n", | |
"\n", | |
"operation ControllingStringCorrectLength() : Unit {\n", | |
" let address = [true, false, true];\n", | |
" using((addressRegister, target) = (Qubit[3], Qubit())){\n", | |
" // Prepare address register to address value\n", | |
" ApplyPauliFromBitString(PauliX, true, address, addressRegister);\n", | |
" // Control on the same address, should put target qubit in superposition.\n", | |
" (ControlledOnBitString(address, H))\n", | |
" (addressRegister, target);\n", | |
" DumpMachine();\n", | |
" ResetAll(addressRegister+[target]);\n", | |
" }\n", | |
"}\n", | |
"\n", | |
"operation ControllingStringShort() : Unit {\n", | |
" let address = [true, false];\n", | |
" using((addressRegister, target) = (Qubit[3], Qubit())){\n", | |
" // Prepare address register to address value\n", | |
" ApplyPauliFromBitString(PauliX, true, address, addressRegister);\n", | |
" // Control on the same address, should put target qubit in superposition.\n", | |
" (ControlledOnBitString(address, H))\n", | |
" (addressRegister, target);\n", | |
" DumpMachine();\n", | |
" ResetAll(addressRegister+[target]);\n", | |
" }\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "{\"QubitIds\":[0,1,2,3],\"NQubits\":4,\"Amplitudes\":[{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.7071067811865476,\"Imaginary\":0.0,\"Magnitude\":0.7071067811865476,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.7071067811865476,\"Imaginary\":0.0,\"Magnitude\":0.7071067811865476,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0}]}", | |
"text/html": [ | |
"\r\n", | |
" <table style=\"table-layout: fixed; width: 100%\">\r\n", | |
" <thead>\r\n", | |
" \r\n", | |
" <tr>\r\n", | |
" <th>Qubit IDs</th>\r\n", | |
" <td span=\"3\">0, 1, 2, 3</td>\r\n", | |
" </tr>\r\n", | |
" \r\n", | |
" <tr>\r\n", | |
" <th style=\"width: 20ch)\">Basis state (bitstring)</th>\r\n", | |
" <th style=\"width: 20ch\">Amplitude</th>\r\n", | |
" <th style=\"width: calc(100% - 26ch - 20ch)\">Meas. Pr.</th>\r\n", | |
" <th style=\"width: 6ch\">Phase</th>\r\n", | |
" </tr>\r\n", | |
" </thead>\r\n", | |
"\r\n", | |
" <tbody>\r\n", | |
" \r\n", | |
" <tr>\r\n", | |
" <td>$\\left|1010\\right\\rangle$</td>\r\n", | |
" <td>$0.7071 + 0.0000 i$</td>\r\n", | |
" <td>\r\n", | |
" <progress\r\n", | |
" max=\"100\"\r\n", | |
" value=\"50.000000000000014\"\r\n", | |
" style=\"width: 100%;\"\r\n", | |
" >\r\n", | |
" </td>\r\n", | |
" <td style=\"transform: rotate(0deg);\r\n", | |
" text-align: center;\">\r\n", | |
" ↑\r\n", | |
" </td>\r\n", | |
" </tr>\r\n", | |
" \n", | |
"\r\n", | |
" <tr>\r\n", | |
" <td>$\\left|1011\\right\\rangle$</td>\r\n", | |
" <td>$0.7071 + 0.0000 i$</td>\r\n", | |
" <td>\r\n", | |
" <progress\r\n", | |
" max=\"100\"\r\n", | |
" value=\"50.000000000000014\"\r\n", | |
" style=\"width: 100%;\"\r\n", | |
" >\r\n", | |
" </td>\r\n", | |
" <td style=\"transform: rotate(0deg);\r\n", | |
" text-align: center;\">\r\n", | |
" ↑\r\n", | |
" </td>\r\n", | |
" </tr>\r\n", | |
" \r\n", | |
" </tbody>\r\n", | |
" </table>\r\n", | |
" " | |
], | |
"text/plain": [ | |
"|1010⟩\t0.7071067811865476 + 0𝑖\n", | |
"|1011⟩\t0.7071067811865476 + 0𝑖" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"application/json": "{\"@type\":\"tuple\"}", | |
"text/plain": [ | |
"()" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%simulate ControllingStringCorrectLength" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "{\"QubitIds\":[0,1,2,3],\"NQubits\":4,\"Amplitudes\":[{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":1.0,\"Imaginary\":0.0,\"Magnitude\":1.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0}]}", | |
"text/html": [ | |
"\r\n", | |
" <table style=\"table-layout: fixed; width: 100%\">\r\n", | |
" <thead>\r\n", | |
" \r\n", | |
" <tr>\r\n", | |
" <th>Qubit IDs</th>\r\n", | |
" <td span=\"3\">0, 1, 2, 3</td>\r\n", | |
" </tr>\r\n", | |
" \r\n", | |
" <tr>\r\n", | |
" <th style=\"width: 20ch)\">Basis state (bitstring)</th>\r\n", | |
" <th style=\"width: 20ch\">Amplitude</th>\r\n", | |
" <th style=\"width: calc(100% - 26ch - 20ch)\">Meas. Pr.</th>\r\n", | |
" <th style=\"width: 6ch\">Phase</th>\r\n", | |
" </tr>\r\n", | |
" </thead>\r\n", | |
"\r\n", | |
" <tbody>\r\n", | |
" \r\n", | |
" <tr>\r\n", | |
" <td>$\\left|1000\\right\\rangle$</td>\r\n", | |
" <td>$1.0000 + 0.0000 i$</td>\r\n", | |
" <td>\r\n", | |
" <progress\r\n", | |
" max=\"100\"\r\n", | |
" value=\"100\"\r\n", | |
" style=\"width: 100%;\"\r\n", | |
" >\r\n", | |
" </td>\r\n", | |
" <td style=\"transform: rotate(0deg);\r\n", | |
" text-align: center;\">\r\n", | |
" ↑\r\n", | |
" </td>\r\n", | |
" </tr>\r\n", | |
" \r\n", | |
" </tbody>\r\n", | |
" </table>\r\n", | |
" " | |
], | |
"text/plain": [ | |
"|1000⟩\t1 + 0𝑖" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"application/json": "{\"@type\":\"tuple\"}", | |
"text/plain": [ | |
"()" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%simulate ControllingStringShort" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "{\"rows\":[{\"@type\":\"@tuple\",\"Item1\":\"iqsharp\",\"Item2\":\"0.11.2006.403\"},{\"@type\":\"@tuple\",\"Item1\":\"Jupyter Core\",\"Item2\":\"1.3.60623.0\"},{\"@type\":\"@tuple\",\"Item1\":\".NET Runtime\",\"Item2\":\".NETCoreApp,Version=v3.1\"}]}", | |
"text/html": [ | |
"<table><thead><tr><th>Component</th><th>Version</th></tr></thead><tbody><tr><td>iqsharp</td><td>0.11.2006.403</td></tr><tr><td>Jupyter Core</td><td>1.3.60623.0</td></tr><tr><td>.NET Runtime</td><td>.NETCoreApp,Version=v3.1</td></tr></tbody></table>" | |
], | |
"text/plain": [ | |
"Component Version\r\n", | |
"------------ ------------------------\r\n", | |
"iqsharp 0.11.2006.403\r\n", | |
"Jupyter Core 1.3.60623.0\r\n", | |
".NET Runtime .NETCoreApp,Version=v3.1\r\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%version" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Q#", | |
"language": "qsharp", | |
"name": "iqsharp" | |
}, | |
"language_info": { | |
"file_extension": ".qs", | |
"mimetype": "text/x-qsharp", | |
"name": "qsharp", | |
"version": "0.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM mcr.microsoft.com/quantum/iqsharp-base:0.11.2006.403 | |
ENV IQSHARP_HOSTING_ENV=sckaiser-ctlonbitstring-bug | |
# Make sure the contents of our repo are in ${HOME}. | |
# These steps are required for use on mybinder.org. | |
USER root | |
COPY . ${HOME} | |
RUN chown -R ${USER} ${HOME} | |
RUN pip install rise | |
# Finish by dropping back to the notebook user. | |
USER ${USER} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment