Skip to content
This repository was archived by the owner on Oct 7, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion referenceqvm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from referenceqvm.gates import gate_matrix
from referenceqvm.qvm_wavefunction import QVM_Wavefunction
from referenceqvm.qvm_unitary import QVM_Unitary
from referenceqvm.qvm_density import QVM_Density


def QVMConnection(type_trans='wavefunction',
gate_set=gate_matrix):
gate_set=gate_matrix, noise_model=None):
"""
Initialize a qvm of a particular type. The type corresponds to the
type of transition the QVM can perform.
Expand All @@ -31,6 +32,9 @@ def QVMConnection(type_trans='wavefunction',
elif type_trans == 'unitary':
qvm = QVM_Unitary(gate_set=gate_set)

elif type_trans == 'density':
qvm = QVM_Density(gate_set=gate_set, noise_model=noise_model)

else:
raise TypeError("{} is not a valid QVM type.".format(type_trans))

Expand Down
63 changes: 63 additions & 0 deletions referenceqvm/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,66 @@ def BARENCO(alpha, phi, theta):
'CZ': CZ
}


# noisy gates
def relaxation(p):
"""
Return the amplitude damping Kraus operators
"""
k0 = np.array([[1.0, 0.0], [0.0, np.sqrt(1 - p)]])
k1 = np.array([[0.0, np.sqrt(p)], [0.0, 0.0]])
return [k0, k1]


def dephasing(p):
"""
Return the phase damping Kraus operators
"""
k0 = np.eye(2)*np.sqrt(1 - p/2)
k1 = np.sqrt(p/2) * Z
return [k0, k1]


def depolarizing(p):
"""
Return the phase damping Kraus operators
"""
k0 = np.sqrt(1.0 - p)*I
k1 = np.sqrt(p/3.0)*X
k2 = np.sqrt(p/3.0)*Y
k3 = np.sqrt(p/3.0)*Z
return [k0, k1, k2, k3]


def phase_flip(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p)*I
k1 = np.sqrt(p)*Z
return [k0, k1]


def bit_flip(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p)*I
k1 = np.sqrt(p)*X
return [k0, k1]


def bitphase_flip(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p)*I
k1 = np.sqrt(p)*Y
return [k0, k1]

noise_gates = {'relaxation': relaxation,
'dephasing': dephasing,
'depolarizing': depolarizing,
'phase_flip': phase_flip,
'bit_flip': bit_flip,
'bitphase_flip': bitphase_flip}
1 change: 1 addition & 0 deletions referenceqvm/qam.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def load_program(self, pyquil_program):
invalid = True
break

# NOTE: all_inst is set by the subclass
if invalid is True and self.all_inst is False:
raise TypeError("In QVM_Unitary, only Gates and DefGates are "
"supported")
Expand Down
Loading