4 ms·
So far, with any amount of coaxing, it can't: fix the above download isssue (https://github.com/uncbiag/ICON/blob/752532ff339a6511dfa93f435273f1d9651f12ae/src/
by QuadmasterXLII 4y ago
So far, with any amount of coaxing, it can't:
fix the above download isssue (https://github.com/uncbiag/ICON/blob/752532ff339a6511dfa93f435273f1d9651f12ae/src/icon_registration/pretrained_models/lung_ct.py#L24 https://github.com/uncbiag/ICON/blob/752532ff339a6511dfa93f4...)
Modify an existing class to take the number of iterations as a parameter instead of relying on hardcoded constants (https://github.com/uncbiag/ICON/blob/752532ff339a6511dfa93f435273f1d9651f12ae/src/icon_registration/network_wrappers.py#L122 https://github.com/uncbiag/ICON/blob/752532ff339a6511dfa93f4...)
Fix a function to gracefully handle an old version of git
This last one is illustrative, as its proposed solution looks elegant, correct, and well explained, but totally fails.
QuadmasterXLII:
This function crashes if an old version of git is installed that doesn't have the :(exclude) feature. Can you fix it?
```
def initialize(run_name=None, output_root="results/"):
global output_dir_impl
global initialized
if initialized:
raise Exception("footsteps can only be initialized once")
initialized = True
if not run_name:
if "FOOTSTEPS_NAME" in os.environ:
run_name = os.environ["FOOTSTEPS_NAME"]
else:
print("Input name of experiment:")
run_name = input()
output_dir_impl = os.path.join(output_root, run_name) + "/"
suffix = 0
while os.path.exists(output_dir_impl):
suffix += 1
output_dir_impl = os.path.join(output_root, run_name) + "-" + str(suffix) + "/"
os.makedirs(output_dir_impl)
print("Saving results to " + output_dir_impl)
with open(output_dir_impl + "info.txt", "w") as f:
f.write("Command:\n")
f.write(" ".join(sys.argv) + "\n")
f.write("System:\n")
f.write(subprocess.check_output(["hostname"]).decode())
f.write("Python:\n")
f.write(shutil.which("python") + "\n")
f.write("Git Hash:\n")
f.write(
subprocess.check_output(["git", "describe", "--always"]).strip().decode()
+ "\n"
)
f.write("Uncommitted changes:\n")
f.write(
subprocess.check_output(
["git", "diff", "HEAD", "--", ".", ":(exclude)*.ipynb"]
).decode()
)
f.write("Current working dir:\n")
f.write(os.getcwd() + "\n")
try:
shutil.copy(sys.argv[0], output_dir_impl + os.path.basename(sys.argv[0]))
except:
pass
```
ChatGPT:
This function checks whether the :(exclude) feature is available in the installed version of git by calling git diff with :(exclude).ipynb. If the feature is not available, git will return an error and the function will crash.
To fix this, we can add a check to see if git supports the :(exclude) feature before calling git diff with it. We can do this by calling git help diff and checking the output for a mention of :(exclude). If the feature is not supported, we can call git diff without the :(exclude) feature.
Here is how the fixed function would look like:
Copy code
```
def initialize(run_name=None, output_root="results/"):
global output_dir_impl
global initialized
if initialized:
raise Exception("footsteps can only be initialized once")
initialized = True
if not run_name:
if "FOOTSTEPS_NAME" in os.environ:
run_name = os.environ["FOOTSTEPS_NAME"]
else:
print("Input name of experiment:")
run_name = input()
output_dir_impl = os.path.join(output_root, run_name) + "/"
suffix = 0
while os.path.exists(output_dir_impl):
suffix += 1
output_dir_impl = os.path.join(output_root, run_name) + "-" + str(suffix) + "/"
os.makedirs(output_dir_impl)
print("Saving results to " + output_dir_impl)
with open(output_dir_impl + "info.txt", "w") as f:
f.write("Command:\n")
f.write(" ".join(sys.argv) + "\n")
f.write("System:\n")
f.write(subprocess.check_output(["hostname"]).decode())
f.write("Python:\n")
f.write(shutil.which("python") + "\n")
f.write("Git Hash:\n")
f.write(
subprocess.check_output(["git", "describe", "--always"]).strip().decode()
+ "\n"
)
f.write("Uncommitted changes:\n")
# Check if git supports the :(exclude) feature
help_output = subprocess.check_output(["git", "help", "diff"]).decode()
if ":(exclude)" in help_output:
# :(exclude) is supported, call git diff with it
f.write(
subprocess.check_output(
["git", "diff", "HEAD", "--", ".", ":(exclude)*.ipynb"]
).decode()
)
else:
# :(exclude) is not supported, call git diff without it
f.write(
subprocess.check_output(
["git", "diff", "HEAD", "--", "."]
).decode()
)
f.write("Current working dir:\n")
f.write(os.getcwd() +
```
- QuadmasterXLII 4y agoBecause this code has 7 or 8 unit tests but none of them verify that notebooks are actually excluded from the diff, the gpt code which is wrong and so always calls the fallback _passes the unit test suite_. Brace yourselves for a new era of buggy code