Просмотр исходного кода

Added interface to single qubit measurement

Adam Kelly 5 лет назад
Родитель
Сommit
8d84c6178c
3 измененных файлов с 11 добавлено и 9 удалено
  1. 5 5
      notebooks/In-Progress Experiments.ipynb
  2. 3 4
      qcgpu/backend.py
  3. 3 0
      qcgpu/state.py

+ 5 - 5
notebooks/In-Progress Experiments.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -17,22 +17,22 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 4,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "0.4999062"
+       "1.0"
       ]
      },
-     "execution_count": 2,
+     "execution_count": 4,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "state.backend.measure_qubit(0)"
+    "state.measure_qubit(0)"
    ]
   },
   {

+ 3 - 4
qcgpu/backend.py

@@ -121,18 +121,17 @@ class Backend:
 
         return kernel(self.buffer, target).get()
 
-    def measure_qubit(self, target):
+    def measure_qubit(self, target, samples):
         probability_of_0 = self.qubit_probability(target)
 
         total = 0
-        samples = 10000000.0
 
-        for i in range(int(samples)):
+        for i in range(samples):
             outcome = 1 if random.random() > probability_of_0 else 0
             total = total + outcome
             
         
-        return total / samples
+        return total
 
 
     def amplitudes(self):

+ 3 - 0
qcgpu/state.py

@@ -38,6 +38,9 @@ class State:
 
         self.backend.apply_controlled_gate(gate, control, target)
 
+    def measure_qubit(self, target, samples=1):
+        return self.backend.measure_qubit(target, samples)
+
     def amplitudes(self):
         return self.backend.amplitudes()