Ejemplo n.º 1
0
 def __new__(cls, *args, **kwargs):
     cgate_only = {"I", "M", "Flatten", "CallbackGate", "ZPow", "CZPow"}
     if BACKEND.get('GATES') == 'custom' or cls.__name__ in cgate_only:
         return super(TensorflowGate, cls).__new__(cls)
     else:
         from qibo.tensorflow import gates
         return getattr(gates, cls.__name__)(*args, **kwargs)
Ejemplo n.º 2
0
 def __init__(self):
     self.calculation_cache = None
     # For `controlled_by` gates (see `cache.ControlCache` for more details)
     self.control_cache = None
     # Gate matrices
     self.matrix = None
     # Einsum backend
     self.einsum = BACKEND.get('EINSUM')
Ejemplo n.º 3
0
 def __new__(cls, *args, **kwargs):
     cgate_only = {"I", "M", "Flatten", "CallbackGate", "ZPow", "CZPow"}
     # TODO: Move these to a different file and refactor
     if BACKEND.get('GATES') == 'custom' or cls.__name__ in cgate_only:
         return super(TensorflowGate, cls).__new__(cls)
     else:
         from qibo.tensorflow import gates
         return getattr(gates, cls.__name__)(*args, **kwargs)  # pylint: disable=E0110
Ejemplo n.º 4
0
 def __new__(cls, *args, **kwargs):
     if BACKEND.get('GATES') == 'custom':  # pragma: no cover
         # future TODO
         raise_error(
             NotImplementedError, "Density matrices are not supported by "
             "custom operator gates.")
     else:
         from qibo.tensorflow import gates
         return getattr(gates, cls.__name__)(*args, **kwargs)
Ejemplo n.º 5
0
    def _one_qubit_matrix(self, gate0: "Gate", gate1: "Gate"):
        """Calculates Kroneker product of two one-qubit gates.

        Args:
            gate0: Gate that acts on ``self.qubit0``.
            gate1: Gate that acts on ``self.qubit1``.

        Returns:
            4x4 matrix that corresponds to the Kronecker product of the 2x2
            gate matrices.
        """
        if BACKEND.get('GATES') == "custom":
            return np.kron(gate0.unitary, gate1.unitary)
        else:
            matrix = tf.tensordot(gate0.unitary, gate1.unitary, axes=0)
            matrix = tf.transpose(matrix, [0, 2, 1, 3])
            return tf.reshape(matrix, (4, 4))
Ejemplo n.º 6
0
 def __new__(cls, q, t1, t2, time, excited_population=0, seed=None):
     if BACKEND.get('GATES') == "custom":
         cls_a = _ThermalRelaxationChannelA
         cls_b = _ThermalRelaxationChannelB
     else:
         from qibo.tensorflow import gates
         cls_a = gates._ThermalRelaxationChannelA
         cls_b = gates._ThermalRelaxationChannelB
     if t2 > t1:
         cls_s = cls_b
     else:
         cls_s = cls_a
     return cls_s(q,
                  t1,
                  t2,
                  time,
                  excited_population=excited_population,
                  seed=seed)
Ejemplo n.º 7
0
 def __new__(cls, q0, q1, theta):
     if BACKEND.get('GATES') == 'custom':
         return CU1(q0, q1, theta)
     else:
         from qibo.tensorflow import gates
         return gates.CU1(q0, q1, theta)
Ejemplo n.º 8
0
 def __init__(self):
     super(FusionGroup, self).__init__()
     self.bk = np
     if BACKEND.get('GATES') != "custom":
         self.bk = tf
Ejemplo n.º 9
0
 def __new__(cls, q, theta, trainable=True):
     if BACKEND.get('GATES') == 'custom':
         return U1(q, theta, trainable)
     else:
         from qibo.tensorflow import gates
         return gates.U1(q, theta, trainable)