From 96c4fc2356050cdcf36ce68a586731bdd11a21b1 Mon Sep 17 00:00:00 2001 From: maolinml <86260930+maolinml@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:50:08 -0700 Subject: [PATCH 1/5] add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file From 1b730697bb5bd010fd92128f055eba1344493fd8 Mon Sep 17 00:00:00 2001 From: maolinml <86260930+maolinml@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:50:32 -0700 Subject: [PATCH 2/5] -m modify a typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79622db..ea33c53 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The output .json file will be saved in `examples/ahs_program.json`. 1.B Generate .json using Python Braket SDK from the AHS program object: ``` ahs_ir = ahs_program.to_ir() -json_object = json.loads(ahs_ir.json()) +json_data = json.loads(ahs_ir.json()) json_string = json.dumps(json_data, indent=4) filename = "ahs_program.json" with open(filename, "w") as json_file: From d3ff8d88ad0b25efe531ef8b612206e18a65149b Mon Sep 17 00:00:00 2001 From: maolinml <86260930+maolinml@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:36:25 -0700 Subject: [PATCH 3/5] modify parse_protocol so that programs without local detuning can be run --- src/mps_utils.jl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mps_utils.jl b/src/mps_utils.jl index 8828a56..183e4d0 100644 --- a/src/mps_utils.jl +++ b/src/mps_utils.jl @@ -56,9 +56,17 @@ function parse_protocol(ahs_program, τ::Float64, n_τ_steps::Int) time_points_Ω = ahs_program["hamiltonian"]["drivingFields"][1]["amplitude"]["time_series"]["times"] values_Ω = ahs_program["hamiltonian"]["drivingFields"][1]["amplitude"]["time_series"]["values"] - pattern = ahs_program["hamiltonian"]["shiftingFields"][1]["magnitude"]["pattern"] - time_points_shift = ahs_program["hamiltonian"]["shiftingFields"][1]["magnitude"]["time_series"]["times"] - values_shift = ahs_program["hamiltonian"]["shiftingFields"][1]["magnitude"]["time_series"]["values"] + if "local_detuning" ∉ keys(ahs_program["hamiltonian"]) || length(ahs_program["hamiltonian"]["local_detuning"]) == 0 + # Define an empty local detuning with zero pattern and zero values + filling = ahs_json["setup"]["ahs_register"]["filling"] + pattern = ["0" for _ in filling] + time_points_local_detuning = ["0.0", time_points_Ω[end]] + values_local_detuning = ["0.0", "0.0"] + else + pattern = ahs_program["hamiltonian"]["local_detuning"][1]["magnitude"]["pattern"] + time_points_local_detuning = ahs_program["hamiltonian"]["local_detuning"][1]["magnitude"]["time_series"]["times"] + values_local_detuning = ahs_program["hamiltonian"]["local_detuning"][1]["magnitude"]["time_series"]["values"] + end # Convert strings to floats [parsing Braket AHS program] time_points_Δ = parse.(Float64, time_points_Δ) @@ -67,15 +75,15 @@ function parse_protocol(ahs_program, τ::Float64, n_τ_steps::Int) values_Ω = parse.(Float64, values_Ω) pattern = parse.(Float64, pattern) - time_points_shift = parse.(Float64, time_points_shift) - values_shift = parse.(Float64, values_shift) + time_points_local_detuning = parse.(Float64, time_points_local_detuning) + values_local_detuning = parse.(Float64, values_local_detuning) # Define piecewise protocols t_vals = [i/n_τ_steps*total_time for i in 1:n_τ_steps] # Global detuning time series Δ_glob_ts = [piecewise_protocol(t, time_points_Δ, values_Δ) for t in t_vals] # Local detuning time series - Δ_loc_ts = [piecewise_protocol(t, time_points_shift, values_shift) for t in t_vals] + Δ_loc_ts = [piecewise_protocol(t, time_points_local_detuning, values_local_detuning) for t in t_vals] # Rabi driving field Ω_ts = [piecewise_protocol(t, time_points_Ω, values_Ω) for t in t_vals] From 8964834e93babf4114464a2e7cb7fdce23a6ffdc Mon Sep 17 00:00:00 2001 From: maolinml <86260930+maolinml@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:00:11 -0700 Subject: [PATCH 4/5] deprecate tau and use n-tau-steps and the time max in the program to determine the trotter time step --- src/mps_runner.jl | 8 ++++---- src/mps_utils.jl | 30 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/mps_runner.jl b/src/mps_runner.jl index dcc8c96..c9feced 100644 --- a/src/mps_runner.jl +++ b/src/mps_runner.jl @@ -44,10 +44,10 @@ function parse_commandline() "--compute-truncation-error" help = "whether to compute the error induced by truncation at each step (computationally expensive)" action = :store_true # default without this flag is false - "--tau" - help = "time evolution step size in seconds" - arg_type = Float64 - default = 0.01e-6 + # "--tau" + # help = "time evolution step size in seconds" + # arg_type = Float64 + # default = 0.01e-6 "--n-tau-steps" help = "number of time evolution steps to simulate" arg_type = Int diff --git a/src/mps_utils.jl b/src/mps_utils.jl index 183e4d0..d15925f 100644 --- a/src/mps_utils.jl +++ b/src/mps_utils.jl @@ -46,26 +46,25 @@ function piecewise_protocol(x, points, values) return y end -function parse_protocol(ahs_program, τ::Float64, n_τ_steps::Int) +function parse_protocol(ahs_program, n_τ_steps::Int) # Define piecewise functions (protocols) time_steps = collect(0:(n_τ_steps-1)) ./ n_τ_steps - total_time = n_τ_steps * τ time_points_Δ = ahs_program["hamiltonian"]["drivingFields"][1]["detuning"]["time_series"]["times"] values_Δ = ahs_program["hamiltonian"]["drivingFields"][1]["detuning"]["time_series"]["values"] time_points_Ω = ahs_program["hamiltonian"]["drivingFields"][1]["amplitude"]["time_series"]["times"] values_Ω = ahs_program["hamiltonian"]["drivingFields"][1]["amplitude"]["time_series"]["values"] - if "local_detuning" ∉ keys(ahs_program["hamiltonian"]) || length(ahs_program["hamiltonian"]["local_detuning"]) == 0 + if "localDetuning" ∉ keys(ahs_program["hamiltonian"]) || length(ahs_program["hamiltonian"]["localDetuning"]) == 0 # Define an empty local detuning with zero pattern and zero values filling = ahs_json["setup"]["ahs_register"]["filling"] pattern = ["0" for _ in filling] time_points_local_detuning = ["0.0", time_points_Ω[end]] values_local_detuning = ["0.0", "0.0"] else - pattern = ahs_program["hamiltonian"]["local_detuning"][1]["magnitude"]["pattern"] - time_points_local_detuning = ahs_program["hamiltonian"]["local_detuning"][1]["magnitude"]["time_series"]["times"] - values_local_detuning = ahs_program["hamiltonian"]["local_detuning"][1]["magnitude"]["time_series"]["values"] + pattern = ahs_program["hamiltonian"]["localDetuning"][1]["magnitude"]["pattern"] + time_points_local_detuning = ahs_program["hamiltonian"]["localDetuning"][1]["magnitude"]["time_series"]["times"] + values_local_detuning = ahs_program["hamiltonian"]["localDetuning"][1]["magnitude"]["time_series"]["values"] end # Convert strings to floats [parsing Braket AHS program] @@ -73,12 +72,14 @@ function parse_protocol(ahs_program, τ::Float64, n_τ_steps::Int) values_Δ = parse.(Float64, values_Δ) time_points_Ω = parse.(Float64, time_points_Ω) values_Ω = parse.(Float64, values_Ω) + pattern = parse.(Float64, pattern) time_points_local_detuning = parse.(Float64, time_points_local_detuning) values_local_detuning = parse.(Float64, values_local_detuning) # Define piecewise protocols + total_time = time_points_Δ[end] t_vals = [i/n_τ_steps*total_time for i in 1:n_τ_steps] # Global detuning time series Δ_glob_ts = [piecewise_protocol(t, time_points_Δ, values_Δ) for t in t_vals] @@ -96,7 +97,9 @@ function parse_protocol(ahs_program, τ::Float64, n_τ_steps::Int) rabi_driving=Ω_ts, global_detuning=Δ_glob_ts, local_detuning=Δ_loc_ts, - pattern=pattern) + pattern=pattern, + τ=total_time/n_τ_steps + ) end function compute_energies(samples, Vij::Matrix{Float64}, Δ_glob_ts, Δ_loc_ts, pattern) @@ -115,14 +118,15 @@ function compute_energies(samples, Vij::Matrix{Float64}, Δ_glob_ts, Δ_loc_ts, end """ - get_trotterized_circuit_2d(sites, τ, n_steps, N, Vij::Matrix{Float64}) + get_trotterized_circuit_2d(sites, n_steps, N, Vij::Matrix{Float64}) Second order Trotterization circuit for a time-dependent Hamiltonian, -for a time step `τ` and `n_steps` total time steps, on `N` total atoms. +for a time step `n_steps` total time steps, on `N` total atoms. `sites` defines the site indices in the MPS used to build the circuit. Returns a `Vector{Vector{iTensor}}` list of gates at each time step. """ -function get_trotterized_circuit_2d(sites, τ::Float64, n_steps::Int, N::Int, Vij::Matrix{Float64}, protocol) +function get_trotterized_circuit_2d(sites, n_steps::Int, N::Int, Vij::Matrix{Float64}, protocol) + τ = protocol[:τ] circuit = Vector{Vector{ITensor}}(undef, n_steps) for i_τ in 1:n_steps two_site_gates = ITensor[] @@ -180,7 +184,6 @@ Returns prepared experiment protocol `protocol` as a `NamedTuple` with keys function parse_ahs_program(ahs_json, args::Dict{String, Any}) program_path = args["program-path"] experiment_path = args["experiment-path"] - τ = args["tau"] n_τ_steps = args["n-tau-steps"] interaction_R = args["interaction-radius"] C6 = args["C6"] @@ -210,7 +213,7 @@ function parse_ahs_program(ahs_json, args::Dict{String, Any}) @debug "Atoms in atom array: $atom_coordinates" Vij = get_Vij(atom_coordinates, N, interaction_R, C6) - protocol = parse_protocol(ahs_json, τ, n_τ_steps) + protocol = parse_protocol(ahs_json, n_τ_steps) return Vij, protocol, N end @@ -263,7 +266,6 @@ end function run(ahs_json, args) experiment_path = args["experiment-path"] - τ = args["tau"] n_τ_steps = args["n-tau-steps"] C6 = args["C6"] interaction_R = args["interaction-radius"] @@ -276,7 +278,7 @@ function run(ahs_json, args) # Initialize ψ to be a product state: Down state (Ground state) ψ = MPS(s, n -> "Dn") @info "Generating Trotterized circuit" - circuit = get_trotterized_circuit_2d(s, τ, n_τ_steps, N, Vij, protocol) + circuit = get_trotterized_circuit_2d(s, n_τ_steps, N, Vij, protocol) max_bond_dim = args["max-bond-dim"] cutoff = args["cutoff"] From 71bb6e7dfa6f8845a51c14935dcba95f0876f0f3 Mon Sep 17 00:00:00 2001 From: maolinml <86260930+maolinml@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:14:55 -0700 Subject: [PATCH 5/5] modify the test file --- test/runtests.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6988ac3..f4f18ea 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,7 +5,7 @@ using JSON3 @testset "BraketAHS.jl" begin # Write your tests here. - json_str = """{"setup":{"ahs_register":{"sites":[["0.0","0.0"],["5.499999999999999856993733449161965e-6","0.0"],["0.0","5.499999999999999856993733449161965e-6"],["5.499999999999999856993733449161965e-6","5.499999999999999856993733449161965e-6"]],"filling":[1,1,1,1]}},"braketSchemaHeader":{"name":"braket.ir.ahs.program","version":"1"},"hamiltonian":{"shiftingFields":[{"magnitude":{"pattern":["0.0","0.0","0.0","0.0"],"time_series":{"values":["0.0","0.0"],"times":["0.0","3.999999999999999818992447303545035e-6"]}}}],"drivingFields":[{"phase":{"pattern":"uniform","time_series":{"values":["0.0","0.0"],"times":["0.0","3.999999999999999818992447303545035e-6"]}},"detuning":{"pattern":"uniform","time_series":{"values":["-3.15e7","-3.15e7","3.15e7","3.15e7"],"times":["0.0","9.999999999999999547481118258862587e-8","3.899999999999999929396754527743951e-6","3.999999999999999818992447303545035e-6"]}},"amplitude":{"pattern":"uniform","time_series":{"values":["0.0","6.3e6","6.3e6","0.0"],"times":["0.0","9.999999999999999547481118258862587e-8","3.899999999999999929396754527743951e-6","3.999999999999999818992447303545035e-6"]}}}]}} + json_str = """{"setup":{"ahs_register":{"sites":[["0.0","0.0"],["5.499999999999999856993733449161965e-6","0.0"],["0.0","5.499999999999999856993733449161965e-6"],["5.499999999999999856993733449161965e-6","5.499999999999999856993733449161965e-6"]],"filling":[1,1,1,1]}},"braketSchemaHeader":{"name":"braket.ir.ahs.program","version":"1"},"hamiltonian":{"localDetuning":[{"magnitude":{"pattern":["0.0","0.0","0.0","0.0"],"time_series":{"values":["0.0","0.0"],"times":["0.0","3.999999999999999818992447303545035e-6"]}}}],"drivingFields":[{"phase":{"pattern":"uniform","time_series":{"values":["0.0","0.0"],"times":["0.0","3.999999999999999818992447303545035e-6"]}},"detuning":{"pattern":"uniform","time_series":{"values":["-3.15e7","-3.15e7","3.15e7","3.15e7"],"times":["0.0","9.999999999999999547481118258862587e-8","3.899999999999999929396754527743951e-6","3.999999999999999818992447303545035e-6"]}},"amplitude":{"pattern":"uniform","time_series":{"values":["0.0","6.3e6","6.3e6","0.0"],"times":["0.0","9.999999999999999547481118258862587e-8","3.899999999999999929396754527743951e-6","3.999999999999999818992447303545035e-6"]}}}]}} """ ahs_json = JSON3.read(json_str) @@ -17,7 +17,6 @@ using JSON3 "shots" => 1000, "max-bond-dim" => 16, "compute-truncation-error" => false, - "tau" => 0.01e-6, "n-tau-steps" => 400, "C6" => 5.42e-24, "compute-correlators" => false,