Example #1
0
def _bloch_multivector_data(state):
    """Return list of Bloch vectors for each qubit

    Args:
        state (DensityMatrix or Statevector): an N-qubit state.

    Returns:
        list: list of Bloch vectors (x, y, z) for each qubit.

    Raises:
        VisualizationError: if input is not an N-qubit state.
    """
    rho = DensityMatrix(state)
    num = rho.num_qubits
    if num is None:
        raise VisualizationError("Input is not a multi-qubit quantum state.")
    pauli_singles = PauliTable.from_labels(['X', 'Y', 'Z'])
    bloch_data = []
    for i in range(num):
        if num > 1:
            paulis = PauliTable(np.zeros((3, 2 * (num - 1)),
                                         dtype=bool)).insert(i,
                                                             pauli_singles,
                                                             qubit=True)
        else:
            paulis = pauli_singles
        bloch_state = [
            np.real(np.trace(np.dot(mat, rho.data)))
            for mat in paulis.matrix_iter()
        ]
        bloch_data.append(bloch_state)
    return bloch_data
 def test_weight_order_2q(self):
     """Test 2-qubit pauli_basis function with weight=True."""
     labels = [
         'II', 'IX', 'IY', 'IZ', 'XI', 'YI', 'ZI', 'XX', 'XY', 'XZ', 'YX',
         'YY', 'YZ', 'ZX', 'ZY', 'ZZ'
     ]
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(2, weight=True), target)
 def test_standard_order_2q(self):
     """Test 2-qubit pauli_basis function."""
     labels = [
         'II', 'IX', 'IY', 'IZ', 'XI', 'XX', 'XY', 'XZ', 'YI', 'YX', 'YY',
         'YZ', 'ZI', 'ZX', 'ZY', 'ZZ'
     ]
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(2), target)
Example #4
0
 def test_weight_order_3q(self):
     """Test 3-qubit pauli_basis function with weight=True."""
     labels = ['III', 'IIX', 'IIY', 'IIZ', 'IXI', 'IYI', 'IZI', 'XII', 'YII', 'ZII',
               'IXX', 'IXY', 'IXZ', 'IYX', 'IYY', 'IYZ', 'IZX', 'IZY', 'IZZ',
               'XIX', 'XIY', 'XIZ', 'XXI', 'XYI', 'XZI',
               'YIX', 'YIY', 'YIZ', 'YXI', 'YYI', 'YZI',
               'ZIX', 'ZIY', 'ZIZ', 'ZXI', 'ZYI', 'ZZI',
               'XXX', 'XXY', 'XXZ', 'XYX', 'XYY', 'XYZ', 'XZX', 'XZY', 'XZZ',
               'YXX', 'YXY', 'YXZ', 'YYX', 'YYY', 'YYZ', 'YZX', 'YZY', 'YZZ',
               'ZXX', 'ZXY', 'ZXZ', 'ZYX', 'ZYY', 'ZYZ', 'ZZX', 'ZZY', 'ZZZ']
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(3, weight=True), target)
 def test_weight_order_2q(self):
     """Test 2-qubit pauli_basis function with weight=True."""
     labels = [
         "II",
         "IX",
         "IY",
         "IZ",
         "XI",
         "YI",
         "ZI",
         "XX",
         "XY",
         "XZ",
         "YX",
         "YY",
         "YZ",
         "ZX",
         "ZY",
         "ZZ",
     ]
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(2, weight=True), target)
 def test_standard_order_2q(self):
     """Test 2-qubit pauli_basis function."""
     labels = [
         "II",
         "IX",
         "IY",
         "IZ",
         "XI",
         "XX",
         "XY",
         "XZ",
         "YI",
         "YX",
         "YY",
         "YZ",
         "ZI",
         "ZX",
         "ZY",
         "ZZ",
     ]
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(2), target)
 def test_weight_order_1q(self):
     """Test 1-qubit pauli_basis function with weight=True."""
     labels = ['I', 'X', 'Y', 'Z']
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(1, weight=True), target)
 def test_standard_order_1q(self):
     """Test 1-qubit pauli_basis function."""
     labels = ['I', 'X', 'Y', 'Z']
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(1), target)
 def test_standard_order_3q(self):
     """Test 3-qubit pauli_basis function."""
     labels = [
         "III",
         "IIX",
         "IIY",
         "IIZ",
         "IXI",
         "IXX",
         "IXY",
         "IXZ",
         "IYI",
         "IYX",
         "IYY",
         "IYZ",
         "IZI",
         "IZX",
         "IZY",
         "IZZ",
         "XII",
         "XIX",
         "XIY",
         "XIZ",
         "XXI",
         "XXX",
         "XXY",
         "XXZ",
         "XYI",
         "XYX",
         "XYY",
         "XYZ",
         "XZI",
         "XZX",
         "XZY",
         "XZZ",
         "YII",
         "YIX",
         "YIY",
         "YIZ",
         "YXI",
         "YXX",
         "YXY",
         "YXZ",
         "YYI",
         "YYX",
         "YYY",
         "YYZ",
         "YZI",
         "YZX",
         "YZY",
         "YZZ",
         "ZII",
         "ZIX",
         "ZIY",
         "ZIZ",
         "ZXI",
         "ZXX",
         "ZXY",
         "ZXZ",
         "ZYI",
         "ZYX",
         "ZYY",
         "ZYZ",
         "ZZI",
         "ZZX",
         "ZZY",
         "ZZZ",
     ]
     target = PauliTable.from_labels(labels)
     self.assertEqual(pauli_basis(3), target)