2020年2月27日木曜日

Q#で乱数表示

まず、新規プロジェクトを作る。Visual Studio Codeを使ってるので、下記参照。
Create a C# project, using VS Code

抜粋

  • Go to View -> Command Palette
  • Select Q#: Create New Project
  • Select Standalone console application
  • Navigate to the location on the file system where you would like to create the application
  • Click on the Open new project... button, once the project has been created
一番初歩っぽい、乱数発生機を使う練習


Program.qs (MSのサイトだとOperation.qsになってるけど、VS code 1.4.2 2020/1月最新版だとProgram.qsで動く)

namespace Qrng {
    open Microsoft.Quantum.Intrinsic;
    operation SampleQuantumRandomNumberGenerator() : Result {
        using (q = Qubit())  { // Allocate a qubit.
            H(q);             // Put the qubit to superposition. It now has a 50% chance of being 0 or 1.
            let r = M(q);     // Measure the qubit value.
            Reset(q);
            return r;
        }
    }
}

に書き換えて、
Driver.csを
using System;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using System.Linq;
namespace Qrng
{
    class Driver
    {
        static void Main(string[] args)
        {
            using (var sim = new QuantumSimulator())
            {
                // First we initialize all the variables:
                var bitString = "0"; // To save the bit string
                int max = 50; // The maximum of the range
                int size = Convert.ToInt32(Math.Floor(Math.Log(max, 2.0) + 1));
                // To calculate the amount of needed bits
                int output = max + 1; // Int to store the output
                while (output > max)  // Loop to generate the number
                {
                    bitString = "0"; // Restart the bit string if fails
                    bitString = String.Join("", Enumerable.Range(0, size).Select(idx =>
                                            SampleQuantumRandomNumberGenerator.Run(sim).Result == Result.One ? "1" : "0"
                                                                                )
                                           );
                    // Generate and concatenate the bits using using the Q# operation
                    output = Convert.ToInt32(bitString, 2);
                    // Convert the bit string to an integer
                }
                // Print the result
                Console.WriteLine($"The random number generated is {output}.");
            }
         }
      }
    }
に書き換えて terminal から"dotnet run"すると、乱数が出力された

2020年2月14日金曜日

Winnyの作者(金子さん)を持ち上げる風潮

なんでかしら無いが、最近Winnyの作者の金子さんがやたら持ち上げられるので、私は反対であることを表明しておく。

ツールを悪用した人物ではなく、ツールをつくったプログラマーに「悪意があった」とするのは過剰かつ不当な対応だ。そもそもWinny自体は合法なファイルも共有できる。いまでいえば、YouTubeに著作権違反の動画がアップされるたびに、YouTubeの経営者が投獄されるようなものである。
https://wired.jp/2018/11/10/winny-isamu-kaneko-1/

と書かれているけれども、
こんなこと発言してる人が著作権を違反する意図がなかったと言うの変じゃないですかね?
裁判所が無罪と言ったことには敬意を払いますが、善意のスーパーヒーローであったかのように扱うのには強い違和感があります。


43 名前:47 投稿日:02/04/06 01:17 ID:M5Lc7MaX main/1017590243.html#476
ソフト公開で逮捕というとFLMASKの例があるから絶対無いともいえんけど、
その前にトンズラできると思うなぁ。
初めは目立たないWEB上でひっそりやって目立ってきたら
自分で作ったワールド内に逃げればいいと思われ。

広まるほどの完成度に達すれば逃げられるし、
達しなければ捕まることも無いという二重の安全策(w

あとMXでの公開の方が絶対危険だよね。
あれ珍しいファイルだと提供者のIPが一発でばれるし。

2020年2月5日水曜日

XcalableMP/XcalableACC or OMNI Compiler

I have just built the OMNI Compiler 1.3.2 on DGX Station with Ubuntu 18.04.

Configure options:
env CPP=/usr/bin/cpp ./configure --enable-openacc --enable-xacc \
--with-cuda=/opt/pgi/linux86-64/2019/cuda/10.1 \
--with-gpu-cflags="-arch=sm_70 -O3" \
--prefix=/home/kushida/OMNI-Compiler/1.3.2


module file.
#%Module1.0
##
## OMNI Compiler 1.3.2
proc ModulesHelp { } {
        puts stderr "OMNI Compiler 1.3.2\n"
}

module-whatis   "OMNI Compiler 1.3.2"

# for Tcl script only
set     omni_path       /home/kushida/OMNI-Compiler/1.3.2

# append pathes
prepend-path    CPATH           $omni_path/include
prepend-path    PATH            $omni_path/bin
prepend-path    LD_LIBRARY_PATH $omni_path/lib
prepend-path    MANPATH         $omni_path/share/man

conflict omnicompiler
prereq pgi/19.10
prereq openmpi/3.1.3

2020年2月3日月曜日