Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions concore.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ def safe_literal_eval(filename, defaultValue):
inpath = "./in" #must be rel path for local
outpath = "./out"
simtime = 0
concore_params_file = os.path.join(inpath, "1", "concore.params")
concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime")

#9/21/22
# ===================================================================
# Parameter Parsing
# ===================================================================
try:
sparams_path = os.path.join(inpath + "1", "concore.params")
sparams_path = concore_params_file
if os.path.exists(sparams_path):
with open(sparams_path, "r") as f:
sparams = f.read()
Expand Down Expand Up @@ -171,8 +173,7 @@ def tryparam(n, i):
def default_maxtime(default):
"""Read maximum simulation time from file or use default."""
global maxtime
maxtime_path = os.path.join(inpath + "1", "concore.maxtime")
maxtime = safe_literal_eval(maxtime_path, default)
maxtime = safe_literal_eval(concore_maxtime_file, default)

default_maxtime(100)

Expand Down Expand Up @@ -220,7 +221,7 @@ def read(port_identifier, name, initstr_val):
return default_return_val

time.sleep(delay)
file_path = os.path.join(inpath+str(file_port_num), name)
file_path = os.path.join(inpath, str(file_port_num), name)
ins = ""

try:
Expand Down Expand Up @@ -283,14 +284,12 @@ def write(port_identifier, name, val, delta=0):
print(f"ZMQ write error on port {port_identifier} (name: {name}): {e}")
except Exception as e:
print(f"Unexpected error during ZMQ write on port {port_identifier} (name: {name}): {e}")
return

# Case 2: File-based port
try:
if isinstance(port_identifier, str) and port_identifier in zmq_ports:
file_path = os.path.join("../"+port_identifier, name)
else:
file_port_num = int(port_identifier)
file_path = os.path.join(outpath+str(file_port_num), name)
file_port_num = int(port_identifier)
file_path = os.path.join(outpath, str(file_port_num), name)
except ValueError:
print(f"Error: Invalid port identifier '{port_identifier}' for file operation. Must be integer or ZMQ name.")
return
Expand Down
10 changes: 6 additions & 4 deletions concoredocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ def safe_literal_eval(filename, defaultValue):
inpath = os.path.abspath("/in")
outpath = os.path.abspath("/out")
simtime = 0
concore_params_file = os.path.join(inpath, "1", "concore.params")
concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime")

#9/21/22
try:
sparams = open(inpath+"1/concore.params").read()
sparams = open(concore_params_file).read()
if sparams[0] == '"': #windows keeps "" need to remove
sparams = sparams[1:]
sparams = sparams[0:sparams.find('"')]
Expand All @@ -46,7 +48,7 @@ def tryparam(n, i):
#9/12/21
def default_maxtime(default):
global maxtime
maxtime = safe_literal_eval(os.path.join(inpath, "1", "concore.maxtime"), default)
maxtime = safe_literal_eval(concore_maxtime_file, default)

default_maxtime(100)

Expand All @@ -62,7 +64,7 @@ def read(port, name, initstr):
global s, simtime, retrycount
max_retries=5
time.sleep(delay)
file_path = os.path.join(inpath+str(port), name)
file_path = os.path.join(inpath, str(port), name)

try:
with open(file_path, "r") as infile:
Expand Down Expand Up @@ -101,7 +103,7 @@ def read(port, name, initstr):

def write(port, name, val, delta=0):
global simtime
file_path = os.path.join(outpath+str(port), name)
file_path = os.path.join(outpath, str(port), name)

if isinstance(val, str):
time.sleep(2 * delay)
Expand Down