{"action":"created","issue":{"url":"https://api.github.com/repos/msr-quarc/Liquid/issues/10","repository_url":"https://api.github.com/repos/msr-quarc/Liquid","labels_url":"https://api.github.com/repos/msr-quarc/Liquid/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/msr-quarc/Liquid/issues/10/comments","events_url":"https://api.github.com/repos/msr-quarc/Liquid/issues/10/events","html_url":"https://github.com/msr-quarc/Liquid/issues/10","id":131173245,"number":10,"title":"Randomness generation for separate measurements seems to be heavily correlated","user":{"login":"pizzasok","id":17054436,"avatar_url":"https://avatars.githubusercontent.com/u/17054436?v=3","gravatar_id":"","url":"https://api.github.com/users/pizzasok","html_url":"https://github.com/pizzasok","followers_url":"https://api.github.com/users/pizzasok/followers","following_url":"https://api.github.com/users/pizzasok/following{/other_user}","gists_url":"https://api.github.com/users/pizzasok/gists{/gist_id}","starred_url":"https://api.github.com/users/pizzasok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pizzasok/subscriptions","organizations_url":"https://api.github.com/users/pizzasok/orgs","repos_url":"https://api.github.com/users/pizzasok/repos","events_url":"https://api.github.com/users/pizzasok/events{/privacy}","received_events_url":"https://api.github.com/users/pizzasok/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-03T22:21:26Z","updated_at":"2016-02-03T22:48:22Z","closed_at":null,"body":"Hi,\r\n\r\nI just started experimenting with the simulator and subsequent measurements turned out be heavily correlated. I just initialised a qubit in some state and measured it, and repeated the same process many times. The result was very very strange. It may be the case that randomness generation is just not refreshed frequently enough so that it somehow use the same values for quickly repeated measurements. \r\n\r\nHere is my code:\r\n\r\n    #if INTERACTIVE\r\n    #r @\".\\Liquid1.dll\"\r\n    #else \r\n    namespace Microsoft.Research.Liquid // Tell the compiler our namespace\r\n    #endif\r\n\r\n    open Microsoft.Research.Liquid // Get necessary Liquid libraries \r\n    open Util // General utilities \r\n    open Operations // Basic gates and operations\r\n\r\n\r\n    module Script =                     // The script module allows for incremental loading\r\n\r\n        let rec measIter (qubit:Qubit) (times:int) =\r\n            let q = Ket(1).Qubits.[0]\r\n            q.StateSet qubit.State\r\n            M[q]\r\n            if q.Bit.v = 0 then\r\n                times\r\n            else\r\n                measIter qubit (times+1)\r\n\r\n        [<LQD>] \r\n        let TestRandom() =\r\n            show \"Iterating a measurement on qubit copies:\"\r\n            let qubit = Ket(1).Qubits.[0]\r\n            qubit.StateSet(sqrt(0.8),0.0,sqrt(0.2),0.0)\r\n            let p = qubit.Prob1\r\n            for i in [1..10] do\r\n                let rep = measIter qubit 0\r\n                show \"First measured |0> after %i repetitions, its probability is %e.\" rep ((1.0-p)*p**(float rep))\r\n\r\nAnd the result of running it was:\r\n\r\n    C:\\Liquid\\bin>Liquid.exe /s TestRandom.fsx TestRandom()\r\n    0:0000.0/\r\n    0:0000.0/===========================================================================================\r\n    0:0000.0/=    The Language-Integrated Quantum Operations (LIQUi|>) Simulator                       =\r\n    0:0000.0/=        Copyright (c) 2015, Microsoft Corporation                                        =\r\n    0:0000.0/=        If you use LIQUi|> in your research, please follow the guidelines at             =\r\n    0:0000.0/=        https://github.com/msr-quarc/Liquid for citing LIQUi|> in your publications.     =\r\n    0:0000.0/===========================================================================================\r\n    0:0000.0/\r\n    0:0000.0/\r\n    0:0000.0/===========================================================================================\r\n    0:0000.0/=    This is an unregistered copy of LIQUi|>.                                             =\r\n    0:0000.0/=    Please follow the instructions at http://github.com/msr-quarc/Liquid to register.    =\r\n    0:0000.0/===========================================================================================\r\n    0:0000.0/\r\n    0:0000.0/=============== Logging to: Liquid.log opened ================\r\n    Microsoft (R) F# Compiler version 14.0.23020.0\r\n    Copyright (c) Microsoft Corporation. All Rights Reserved.\r\n    0:0000.0/Iterating a measurement on qubit copies:\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 1829 repetitions, its probability is 0.000000e+000.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/First measured |0> after 0 repetitions, its probability is 8.000000e-001.\r\n    0:0000.0/=============== Logging to: Liquid.log closed ================\r\n\r\nOn the third line you can see the trace of an event which should not happen in the lifetime of the universe. A measurement event happened 1829 times in a sequence where each individual event had only 10% chance! I get similar results for about each 3rd test runs.\r\n\r\nI do not know if it is relevant but I am running Liquid on a 64 bit Windows 7 OS which runs on a VirtualBox instance hosted by a 64 bit ubuntu machine.\r\n\r\nDo you have any clue what is happening under the hood?"},"comment":{"url":"https://api.github.com/repos/msr-quarc/Liquid/issues/comments/179512778","html_url":"https://github.com/msr-quarc/Liquid/issues/10#issuecomment-179512778","issue_url":"https://api.github.com/repos/msr-quarc/Liquid/issues/10","id":179512778,"user":{"login":"alan-geller","id":10674457,"avatar_url":"https://avatars.githubusercontent.com/u/10674457?v=3","gravatar_id":"","url":"https://api.github.com/users/alan-geller","html_url":"https://github.com/alan-geller","followers_url":"https://api.github.com/users/alan-geller/followers","following_url":"https://api.github.com/users/alan-geller/following{/other_user}","gists_url":"https://api.github.com/users/alan-geller/gists{/gist_id}","starred_url":"https://api.github.com/users/alan-geller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alan-geller/subscriptions","organizations_url":"https://api.github.com/users/alan-geller/orgs","repos_url":"https://api.github.com/users/alan-geller/repos","events_url":"https://api.github.com/users/alan-geller/events{/privacy}","received_events_url":"https://api.github.com/users/alan-geller/received_events","type":"User","site_admin":false},"created_at":"2016-02-03T22:48:22Z","updated_at":"2016-02-03T22:48:22Z","body":"@pizzasok: A new pseudorandom number generator is created every time you create a new Ket. The generator is seeded with the current system tick count, which is updated rather infrequently in general, especially on VMs. Thus, the behavior you're seeing is expected.\r\nA better practice is to create one Ket object, and then use the Ket.Reset method when you want to reinitialize. That way you'll use a single random sequence, and should get good statistics."}}