Last active
August 14, 2019 17:21
-
-
Save cgranade/e4a837dcb37a4e60f8e971cf1372a2ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Start from the IQ# base image. The definition for this image can be found at | |
# https://github.com/microsoft/iqsharp/blob/master/images/iqsharp-base/Dockerfile. | |
FROM mcr.microsoft.com/quantum/iqsharp-base:0.8.1907.1701 | |
ENV IQSHARP_HOSTING_ENV=quantumcomputing-7012 | |
# 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} | |
# Finish by dropping back to the notebook user. | |
USER ${USER} |
This file contains hidden or 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": "[\"Chunked\"]", | |
"text/html": [ | |
"<ul><li>Chunked</li></ul>" | |
], | |
"text/plain": [ | |
"Chunked" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"open Microsoft.Quantum.Arrays;\n", | |
"open Microsoft.Quantum.Diagnostics;\n", | |
"\n", | |
"function Chunked<'T>(array : 'T[], chunkSize : Int) : 'T[][] {\n", | |
" Fact(Length(array) % chunkSize == 0, \"Qubit array can not be splitted into equally sized chunks\");\n", | |
" Fact(Length(array) / chunkSize > 0, \"Qubit array length is smaller than chunk size.\");\n", | |
" let numChunks = Length(array) / chunkSize;\n", | |
" let res = Partitioned(ConstantArray(numChunks, chunkSize), array);\n", | |
" Fact(Length(res[numChunks]) == 0, \"Qubit array not split equally.\");\n", | |
" // Note that since Parititoned always returns\n", | |
" // one more array than the length of the array\n", | |
" // of chunk sizes, chop off the last element of its result.\n", | |
" return Most(res);\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/json": "[\"Example\"]", | |
"text/html": [ | |
"<ul><li>Example</li></ul>" | |
], | |
"text/plain": [ | |
"Example" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"open Microsoft.Quantum.Arrays;\n", | |
"open Microsoft.Quantum.Convert;\n", | |
"\n", | |
"function Example() : Unit {\n", | |
" let rank3 = Chunked(Chunked(RangeAsIntArray(1.. 5 * 2 * 3), 2), 3);\n", | |
" Message($\"Rank-3 array: {rank3}\");\n", | |
" Message($\"Length(rank3) = {Length(rank3)}\");\n", | |
" Message($\"Length(rank3[0]) = {Length(rank3[0])}\");\n", | |
" Message($\"Length(rank3[0][0]) = {Length(rank3[0][0])}\");\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Rank-3 array: [[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]],[[13,14],[15,16],[17,18]],[[19,20],[21,22],[23,24]],[[25,26],[27,28],[29,30]]]\n", | |
"Length(rank3) = 5\n", | |
"Length(rank3[0]) = 3\n", | |
"Length(rank3[0][0]) = 2\n" | |
] | |
}, | |
{ | |
"data": { | |
"application/json": "{\"@type\":\"tuple\"}", | |
"text/plain": [ | |
"()" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%simulate Example" | |
] | |
}, | |
{ | |
"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.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment