Skip to content

Commit

Permalink
Use simpler constructors for heavy hex lattice (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 authored Aug 8, 2023
1 parent 0f96a0a commit 77ec3cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 78 deletions.
92 changes: 21 additions & 71 deletions examples/dynamics/heavy_hex_ising_real_tebd.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ITensors
using ITensorNetworks
using NamedGraphs
using NamedGraphs: rem_edges!, add_edge!
using NamedGraphs: rem_edges!, add_edge!, decorate_graph_edges, hexagonal_lattice_graph
using Graphs

using ITensorNetworks:
Expand All @@ -15,78 +15,27 @@ using ITensorNetworks:
symmetric_to_vidal_gauge,
norm_network

#Create the heavy_hex grid of the same structure and labelling as https://www.nature.com/articles/s41586-023-06096-3. With up to no_qubits <= 127 qubits.
function create_heavy_hex_grid(no_qubits::Int64)
g = named_grid((no_qubits, 1))
g = rename_vertices(v -> v[1] - 1, g)
rung_qubits = [
14,
15,
16,
17,
33,
34,
35,
36,
52,
53,
54,
55,
71,
72,
73,
74,
90,
91,
92,
93,
109,
110,
111,
112,
]
qubit_pairs = [
(0, 18),
(4, 22),
(8, 26),
(12, 30),
(20, 39),
(24, 43),
(28, 47),
(32, 51),
(37, 56),
(41, 60),
(45, 64),
(49, 68),
(58, 77),
(62, 81),
(66, 85),
(70, 89),
(75, 94),
(79, 98),
(83, 102),
(87, 106),
(96, 114),
(100, 118),
(104, 122),
(108, 126),
]

for (i, qp) in enumerate(qubit_pairs)
rq = rung_qubits[i]
rem_vertex!(g, rq)
add_vertex!(g, rq)
if qubit_pairs[i][1] <= (no_qubits - 1) && rq <= (no_qubits - 1)
add_edge!(g, qubit_pairs[i][1] => rq)
end
if qubit_pairs[i][2] <= (no_qubits - 1) && rq <= (no_qubits - 1)
add_edge!(g, rq => qubit_pairs[i][2])
end
end
function heavy_hex_lattice_graph(n::Int64, m::Int64)
g = hexagonal_lattice_graph(n, m)
g = decorate_graph_edges(g)
return g
end

function ibm_processor_graph(n::Int64, m::Int64)
g = heavy_hex_lattice_graph(n, m)
dims = maximum(vertices(hexagonal_lattice_graph(n, m)))
v1, v2 = (1, dims[2]), (dims[1], 1)
add_vertices!(g, [v1, v2])
add_edge!(g, v1 => v1 .- (0, 1))
add_edge!(g, v2 => v2 .+ (0, 1))

return g
end

eagle_processor_graph() = ibm_processor_graph(3, 6)
hummingbird_processor_graph() = ibm_processor_graph(2, 4)
osprey_processor_graph() = ibm_processor_graph(6, 12)

"""Take the expectation value of o on an ITN using belief propagation"""
function expect_state_SBP(
o::ITensor, ψ::AbstractITensorNetwork, ψψ::AbstractITensorNetwork, mts::DataGraph
Expand All @@ -110,8 +59,7 @@ end
function main(θh::Float64, no_trotter_steps::Int64; apply_kwargs...)

#Build the graph
no_qubits = 127
g = create_heavy_hex_grid(no_qubits)
g = eagle_processor_graph()

#Do this if measuring a Z based expectation value (i.e. ignore ZZ_gates in final layer as they are irrelevant)
shortened_final_layer = true
Expand Down Expand Up @@ -166,6 +114,8 @@ function main(θh::Float64, no_trotter_steps::Int64; apply_kwargs...)
return mag_dict
end

ibm_processor_graph(3, 6)

θh = pi / 4
no_trotter_steps = 5
χ = 32
Expand Down
8 changes: 4 additions & 4 deletions src/beliefpropagation/beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function belief_propagation_iteration(
ITensors.contract(ITensor(new_mts[src(e) => dst(e)]))
LHS /= sum(diag(LHS))
RHS /= sum(diag(RHS))
c += 0.5 * norm(LHS - RHS)
c += 0.5 * norm(denseblocks(LHS) - denseblocks(RHS))
end
end
return new_mts, c / (length(es))
Expand Down Expand Up @@ -152,9 +152,9 @@ function get_environment(tn::ITensorNetwork, mts::DataGraph, verts::Vector; dir=
end

env_tns = ITensorNetwork[mts[e] for e in boundary_edges(mts, subgraphs; dir=:in)]
central_tn = ITensorNetwork([
tn[v] for v in setdiff(flatten([vertices(mts[s]) for s in subgraphs]), verts)
])
central_tn = ITensorNetwork(
ITensor[tn[v] for v in setdiff(flatten([vertices(mts[s]) for s in subgraphs]), verts)]
)
return ITensorNetwork(vcat(env_tns, ITensorNetwork[central_tn]))
end

Expand Down
6 changes: 3 additions & 3 deletions test/test_gauging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ using SplitApplyCombine
@test diagITensor(vector(diag(m_e)), inds(m_e)) m_e atol = 1e-8
end

@test symmetric_itn_canonicalness(ψ_symm, ψ_symm_mts) < 1e-6
@test symmetric_itn_canonicalness(ψ_symm, ψ_symm_mts) < 1e-5

ψ_vidal, bond_tensors = vidal_gauge(ψ; target_canonicalness=1e-6)
@test vidal_itn_canonicalness(ψ_vidal, bond_tensors) < 1e-6
@test vidal_itn_canonicalness(ψ_vidal, bond_tensors) < 1e-5

ψ_vidal, bond_tensors = symmetric_to_vidal_gauge(ψ_symm, ψ_symm_mts)
@test vidal_itn_canonicalness(ψ_vidal, bond_tensors) < 1e-6
@test vidal_itn_canonicalness(ψ_vidal, bond_tensors) < 1e-5
end

0 comments on commit 77ec3cb

Please sign in to comment.