Skip to content

Commit

Permalink
Added files for HPC IPOPT convergence test
Browse files Browse the repository at this point in the history
  • Loading branch information
leespen1 committed Sep 26, 2024
1 parent 9f7c336 commit e2ece92
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
91 changes: 91 additions & 0 deletions examples/cnot3_optimize_gate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using JLD2, Dates, ArgParse, Printf

s = ArgParseSettings()

@add_arg_table s begin
"--use_juqbox", "-j"
help = "Flag for using Juqbox"
action = :store_true
"--gmres_abstol", "-a"
help = "Absolute tolerance to use in GMRES"
arg_type = Float64
default = 1e-12
"--gmres_reltol", "-r"
help = "Relative tolerance to use in GMRES"
arg_type = Float64
default = 1e-12
"--max_iter", "-m"
help = "Maximum number of IPOPT iterations."
arg_type = Int
default = 50
"order"
help = "Order of the method."
arg_type = Int
required = true
"stepsize"
help = "Stepsize to use."
arg_type = Float64
required = true
end

parsed_args = parse_args(s)

order = parsed_args["order"]
stepsize = parsed_args["stepsize"]
use_juqbox = parsed_args["use_juqbox"]
max_iter = parsed_args["max_iter"]

if use_juqbox
@assert order == 2
end

# Run setup
include("cnot2_setup.jl")

# Compute nsteps based on command line input
nsteps = ceil(Int, prob.tf / stepsize)

prob.nsteps = nsteps
params.nsteps = nsteps

prob.gmres_abstol = parsed_args["gmres_abstol"]
prob.gmres_reltol = parsed_args["gmres_reltol"]


if use_juqbox
# Run test
juqbox_ipopt_prob = Juqbox.setup_ipopt_problem(
params, wa, nCoeff, minCoeff, maxCoeff,
maxIter=max_iter,
lbfgsMax=lbfgsMax,
startFromScratch=startFromScratch,
max_cpu_time=60.0*60*8
)
pcof_opt = Juqbox.run_optimizer(juqbox_ipopt_prob, pcof0);


jldsave("results_cnot3_juqbox_order$(order)_stepsize" * @sprintf("%.2E", stepsize) * "_"* string(now()) * ".jld2";
order,
nsteps,
use_juqbox,
pcof_opt,
max_iter,
params,
juqbox_ipopt_prob
)
else
opt_ret = optimize_gate(
prob, controls, pcof0, target, order=order,
pcof_U=amax, pcof_L=-amax,
maxIter=max_iter, max_cpu_time=60.0*60*8
)

jldsave("results_cnot3_order$(order)_stepsize" * @sprintf("%.2E", stepsize) * "_"* string(now()) * ".jld2";
order,
nsteps,
use_juqbox,
max_iter,
prob,
opt_ret
)
end
41 changes: 41 additions & 0 deletions examples/cnot3_optimize_gate.sb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
#SBATCH --job-name=cnot3_convergence_correctness # Job name
#SBATCH --mail-type=NONE # Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=leespen1@msu.edu # Where to send mail.
#SBATCH --nodes=6 # Maximum number of nodes to be allocated
#SBATCH --ntasks-per-node=2 # Maximum number of tasks on each node
#SBATCH --cpus-per-task=8 # Number of processors for each task (want several because the BLAS is multithreaded, even though my Julia code is not)
#SBATCH --mem-per-cpu=1Gb # Memory (i.e. RAM) per processor
#SBATCH --export=ALL # Export environment variable (not sure if this is necessary, but I don't think it hurts)
#SBATCH --time=96:00:00 # Wall time limit (days-hrs:min:sec)
#SBATCH --output=cnot3_convergence_correctness_%j.log # Path to the standard output and error files relative to the working directory



echo "Date = $(date)"
echo "Hostname = $(hostname -s)"
echo "Working Directory = $(pwd)"
echo ""
echo "Number of Nodes Allocated = $SLURM_JOB_NUM_NODES"
echo "Number of Tasks Per Node = $SLURM_NTASKS_PER_NODE"
echo "Number of CPUs Per Task = $SLURM_CPUS_PER_TASK"
echo ""

# I am hoping that this allows me to distribute each julia run between nodes and tasks.
# Above I established the pool to draw from, and below I execute things that take a limited
# amount of resources from that pool

srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 2 1e-2 -j -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 2 1e-4 -j -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 2 1e-2 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 2 1e-4 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 4 1.8e-2 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 4 1.8e-3 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 6 5.6e-1 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 6 1e-1 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 8 1e0 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 8 3.2e-1 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 10 1.3e0 -m 10000 &
srun --nodes=1 --ntasks=1 julia cnot3_optimize_gate.jl 10 5.6e-1 -m 10000 &

wait # Wait for all tasks to finish before completing the job

0 comments on commit e2ece92

Please sign in to comment.