|
@@ -1,15 +1,51 @@
|
|
|
|
+"""
|
|
|
|
+Quantum Register Object
|
|
|
|
+"""
|
|
|
|
+
|
|
from qcgpu.backend import Backend
|
|
from qcgpu.backend import Backend
|
|
import pyopencl as cl
|
|
import pyopencl as cl
|
|
import numpy as np
|
|
import numpy as np
|
|
|
|
|
|
class State:
|
|
class State:
|
|
- """ Creates a new quantum register.
|
|
|
|
|
|
+ """A class for representing quantum registers.
|
|
|
|
+
|
|
|
|
+ The State class is the QCGPU representation of a quantum
|
|
|
|
+ register / state vector.
|
|
|
|
+
|
|
|
|
+ This class is what should be used to perform the simulations,
|
|
|
|
+ and has method for things such as applying gates, measurements,
|
|
|
|
+ getting probabilities and such.
|
|
|
|
+
|
|
|
|
+ As QCGPU uses OpenCL, you may be queried about which OpenCL device
|
|
|
|
+ to use. This will only happen when running things such a python repl,
|
|
|
|
+ or running a script using QCGPU from the command line. Otherwise, a
|
|
|
|
+ device will be chosen heuristically.
|
|
|
|
+
|
|
|
|
+ When the register is created, it will be left in the state
|
|
|
|
+
|
|
|
|
+ .. math::
|
|
|
|
+
|
|
|
|
+ \\lvert 000 \\dots 0 \\rangle
|
|
|
|
+
|
|
|
|
+ With the given number of qubits.
|
|
|
|
|
|
Args:
|
|
Args:
|
|
- num_qubits (int): The number of qubits to create in the register
|
|
|
|
|
|
+ num_qubits (int): The number of qubits to create in the register.
|
|
|
|
+ This must be greater then zero.
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
- State: A representation of the quantum register
|
|
|
|
|
|
+ State: A representation of the quantum register.
|
|
|
|
+
|
|
|
|
+ Examples
|
|
|
|
+ >>> qcgpu.State(3)
|
|
|
|
+ Choose platform:
|
|
|
|
+ [0] <pyopencl.Platform 'NVIDIA CUDA' at 0x2f22390>
|
|
|
|
+ Choice [0]:0
|
|
|
|
+ Set the environment variable PYOPENCL_CTX='0' to avoid being asked again.
|
|
|
|
+ [[array(1.+0.j, dtype=complex64)]
|
|
|
|
+ [array(0.+0.j, dtype=complex64)]
|
|
|
|
+ [array(0.+0.j, dtype=complex64)]
|
|
|
|
+ [array(0.+0.j, dtype=complex64)]]
|
|
"""
|
|
"""
|
|
def __init__(self, num_qubits):
|
|
def __init__(self, num_qubits):
|
|
|
|
|
|
@@ -18,10 +54,18 @@ class State:
|
|
if num_qubits <= 0:
|
|
if num_qubits <= 0:
|
|
raise ValueError("num_qubits must be a positive integer")
|
|
raise ValueError("num_qubits must be a positive integer")
|
|
|
|
|
|
|
|
+ #: The number of qubits that are in the register
|
|
self.num_qubits = num_qubits
|
|
self.num_qubits = num_qubits
|
|
self.backend = Backend(num_qubits)
|
|
self.backend = Backend(num_qubits)
|
|
|
|
|
|
def apply_gate(self, gate, target):
|
|
def apply_gate(self, gate, target):
|
|
|
|
+ """Applies a single qubit unitary gate to the register.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ gate (~qcgpu.Gate): The gate to be applied to the register
|
|
|
|
+ target (int): The index of the qubit in the register that the gate
|
|
|
|
+ is to be applied to.
|
|
|
|
+ """
|
|
if not isinstance(target, int) or target < 0:
|
|
if not isinstance(target, int) or target < 0:
|
|
raise ValueError("target must be an int > 0")
|
|
raise ValueError("target must be an int > 0")
|
|
|
|
|