コード例 #1
0
 def test_get_1D_array_cartesian_vectors(self):
     si = la.CartesianSpinOperator((1, 0, 0, 0))
     sx = la.CartesianSpinOperator((0, 1, 0, 0))
     sy = la.CartesianSpinOperator((0, 0, 1, 0))
     sz = la.CartesianSpinOperator((0, 0, 0, 1))
     spins = np.array([si, sx, sy, sz])
     calc = la.get_cartesian_vectors(spins)
     expected = (np.array([1, 0, 0, 0]), np.array([0, 1, 0, 0]),
                 np.array([0, 0, 1, 0]), np.array([0, 0, 0, 1]))
     for c, e in zip(calc, expected):
         self.assertTrue(np.array_equal(c, e))
コード例 #2
0
 def test_get_2D_array_cartesian_vectors(self):
     s1 = la.CartesianSpinOperator((1., 2., 3., 4.))
     s2 = la.CartesianSpinOperator((1.1, 1.2, 1.3, 1.4))
     s3 = la.CartesianSpinOperator((1.5, 2.5, 3.5, 4.5))
     s4 = la.CartesianSpinOperator((10., 20., 30., 40.))
     spins = np.array([[s1, s2], [s3, s4]])
     calc = la.get_cartesian_vectors(spins)
     expected = (np.array([[1., 1.1],
                           [1.5, 10.]]), np.array([[2., 1.2], [2.5, 20.]]),
                 np.array([[3., 1.3],
                           [3.5, 30.]]), np.array([[4., 1.4], [4.5, 40.]]))
     for c, e in zip(calc, expected):
         self.assertTrue(np.array_equal(c, e))
コード例 #3
0
 def test_get_single_cartesian_vector(self):
     sx = la.CartesianSpinOperator((0, 1, 0, 0))
     self.assertEqual((0, 1, 0, 0), la.get_cartesian_vector(sx))
     self.assertEqual((0, 1, 0, 0), la.get_cartesian_vectors(sx))
コード例 #4
0
def plot_flow(flow_grids,
              quiver_kwargs=[{
                  'linewidth': 2.,
                  'colors': red
              }],
              proj_quiver_kwargs=[{
                  'linewidth': 2.,
                  'colors': red,
                  'alpha': 0.5
              }],
              fig_kwargs={'figsize': [12., 15.]},
              ax_kwargs={},
              font_kwargs={
                  'name': 'serif',
                  'size': 40
              },
              show_plot=True,
              fname=None,
              fig_num=None):

    # Repeat axis and line formats if only one value is given
    if len(quiver_kwargs) == 1:
        quiver_kwargs = quiver_kwargs * len(flow_grids)
    if len(proj_quiver_kwargs) == 1:
        proj_quiver_kwargs = proj_quiver_kwargs * len(flow_grids)

    # Checks that all inputs are now the same length
    assert len(flow_grids) == len(quiver_kwargs) == len(proj_quiver_kwargs)

    # Initialize Figure and Axes
    fig = plt.figure(fig_num, **fig_kwargs)
    ax = fig.gca(projection='3d')

    # Get Axis Parameters
    x_mins = []
    x_maxs = []
    y_mins = []
    y_maxs = []
    z_mins = []
    z_maxs = []
    for fg in flow_grids:
        x_mins.append(2 * np.min(fg.grid[0]).real)
        x_maxs.append(2 * np.max(fg.grid[0]).real)
        y_mins.append(2 * np.min(fg.grid[1]).real)
        y_maxs.append(2 * np.max(fg.grid[1]).real)
        z_mins.append(2 * np.min(fg.grid[2]).real)
        z_maxs.append(2 * np.max(fg.grid[2]).real)
    x_lim = np.min(x_mins), np.max(x_maxs)
    y_lim = np.min(y_mins), np.max(y_maxs)
    z_lim = np.min(z_mins), np.max(z_maxs)

    # Format Axes
    format_3d_axes(ax,
                   x_lim=x_lim,
                   y_lim=y_lim,
                   z_lim=z_lim,
                   font_kwargs=font_kwargs,
                   **ax_kwargs)

    # Generate Quiver Plot
    for flow_grid, line_format, proj_format in zip(flow_grids, quiver_kwargs,
                                                   proj_quiver_kwargs):
        # Grab Coordinates
        xc, yc, zc = tuple(
            flow_grid.grid.grid
        )  # Factor of 2 for Consistency with Bloch Sphere Convention
        x = 2 * xc.real
        y = 2 * yc.real
        z = 2 * zc.real
        mid_x = int(np.floor(np.shape(x)[0] / 2))
        mid_y = int(np.floor(np.shape(y)[1] / 2))
        mid_z = int(np.floor(np.shape(z)[2] / 2))

        # Vectorize Operators
        flow = la.get_cartesian_vectors(flow_grid.data)

        quiv = ax.quiver(x,
                         y,
                         z,
                         flow[1],
                         flow[2],
                         flow[3],
                         length=0.25,
                         **line_format)
        quiv = ax.quiver(x[:, mid_x, :],
                         x_lim[1] * np.ones_like(y[:, mid_x, :]),
                         z[:, mid_x, :],
                         flow[1][:, mid_x, :],
                         np.zeros_like(flow[2][:, mid_x, :]),
                         flow[3][:, mid_x, :],
                         length=0.25,
                         zorder=-1.,
                         **proj_format)
        quiv = ax.quiver(y_lim[0] * np.ones_like(x[mid_y, :, :]),
                         y[mid_y, :, :],
                         z[mid_y, :, :],
                         np.zeros_like(flow[1][mid_y, :, :]),
                         flow[2][mid_y, :, :],
                         flow[3][mid_y, :, :],
                         length=0.25,
                         zorder=-1.,
                         **proj_format)
        quiv = ax.quiver(x[:, :, mid_z],
                         y[:, :, mid_z],
                         z_lim[0] * np.ones_like(z[:, :, mid_z]),
                         flow[1][:, :, mid_z],
                         flow[2][:, :, mid_z],
                         np.zeros_like(flow[3][:, :, mid_z]),
                         length=0.25,
                         **proj_format)

    # Plot and Save Figure
    if show_plot:
        plt.show()
    if fname is not None:
        fig.savefig(fname)

    return fig, quiv
コード例 #5
0
 def cartesian_vectors(self, container_type=None):
     if container_type is None:
         container_type = self._container_type
     vecs = container_type(la.get_cartesian_vectors(self.data))
     return vecs
コード例 #6
0
ファイル: grids.py プロジェクト: idodin/QuDiPy
def vectorize_operator_grid(operator_grid):
    vec_data = la.get_cartesian_vectors(operator_grid.data)
    return operator_grid.like(vec_data)