quairkit.database.hamiltonian

The library of common Hamiltonians.

quairkit.database.hamiltonian.ising_hamiltonian(edges, vertices)

Compute the Ising Hamiltonian

\[\begin{align} H_{Ising}= \sum_{(u,v) \in E(u>v)}\gamma_{uv}Z_u Z_v + \sum_{k \in V}\beta_k X_k \end{align}\]
Parameters:
edges : Tensor

A tensor E shape=[V, V], where E[u][v] is gamma_{uv}.

vertices : Tensor

A tensor E shape=[V], where V[k] is beta_{k}.

Returns:

H_{Ising}

Return type:

Hamiltonian

edges = torch.tensor([[0, 1, 0.5],
                      [1, 0, 0.2],
                     [0.5, 0.2, 0]])

vertices = torch.tensor([0.3, 0.4, 0.1])

hamiltonian = ising_hamiltonian(edges, vertices)

print(f'The Ising_Hamiltonian is \n {hamiltonian}.')
The Ising_Hamiltonian is
1.0 Z0, Z1
0.5 Z0, Z2
0.20000000298023224 Z1, Z2
0.30000001192092896 X0
0.4000000059604645 X1
0.10000000149011612 X2.
quairkit.database.hamiltonian.xy_hamiltonian(edges)

Compute the Ising Hamiltonian

\[\begin{align} H_{XY}= \sum_{(u,v) \in E(u>v)}(\alpha_{uv}X_u X_v + \beta_{uv}Y_u Y_v) \end{align}\]
Parameters:
edges : Tensor

A tensor E shape=[2, V, V], where E[0][u][v] is alpha_{uv} and E[1][u][v] is beta_{uv}.

Returns:

H_{XY}

Return type:

Hamiltonian

edges = torch.tensor([[
    [0, 0.7, 0],
    [0.7, 0, 0.2],
    [0, 0.2, 0]
],
[
    [0, 0.5, 0],
    [0.5, 0, 0.3],
    [0, 0.3, 0]
]])

H_XY = xy_hamiltonian(edges)

print(f'The XY Hamiltonian is:\n{H_XY}')
The XY Hamiltonian is:
0.699999988079071 X0, X1
0.5 Y0, Y1
0.20000000298023224 X1, X2
0.30000001192092896 Y1, Y2
quairkit.database.hamiltonian.heisenberg_hamiltonian(edges)

Compute the Heisenberg Hamiltonian

\[\begin{align} H_{Heisenberg}= \sum_{(u,v) \in E(u>v)}(\alpha_{uv}X_u X_v + \beta_{uv}Y_u Y_v, + \gamma_{uv}Z_u Z_v) \end{align}\]
Parameters:
edges : Tensor

A tensor E shape=[3, V, V], where E[0][u][v] is alpha_{uv}, E[1][u][v] is beta_{uv} and E[2][u][v] is gamma_{uv}.

Returns:

H_{Heisenberg}

Return type:

Hamiltonian

edges = torch.tensor([
    [
        [0, 0.5, 0],
        [0.5, 0, 0.2],
        [0, 0.2, 0]
    ],
    [
        [0, 0.3, 0],
        [0.3, 0, 0.4],
        [0, 0.4, 0]
    ],
    [
        [0, 0.7, 0],
        [0.7, 0, 0.1],
        [0, 0.1, 0]
    ]
])

H_Heisenberg = heisenberg_hamiltonian(edges)

print(f'The Heisenberg Hamiltonian is:\n{H_Heisenberg}')
The Heisenberg Hamiltonian is:
0.5 X0, X1
0.30000001192092896 Y0, Y1
0.699999988079071 Z0, Z1
0.20000000298023224 X1, X2
0.4000000059604645 Y1, Y2
0.10000000149011612 Z1, Z2