New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change egsphant format to allow up to 95 materials #633
Conversation
Hi Reid, Something I have actually been using to get around the 9 media issue in egs_brachy and 3ddose_tools is using the following list of numbers and characters
to enumerate up to 61 different media. The reason we went with adding characters instead of using 2 digits is so that our code could still read old egsphants (reading less than 9 media), while being able to use egsphant with more media. Just thought I'd add the CLRP perspective :) Martin |
@MartinMartinov Great idea to have backward compatibility. |
Thanks @MartinMartinov I like this suggestion, it does seem to provide better backwards compatibility. |
I also had a "fixed" version back when I was running calculations for TG-195. And I went with something similar to what @MartinMartinov suggested. I used a sort of hexadecimal numbering system. It is good that this is being finally addressed for good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only issue with this is that if one wants to visually inspect the egsphant file there won't be any space between the values ... for a program that knows the format is not an issue though.
@mainegra there are no spaces in the current version with single digits (up to 9 materials) either, but I don't see it as a problem, when e.g. quickly "visualizing" .egsphant in some text editor. |
@rtownson @mainegra @blakewalters When applying the fix above, the .egsphant turns out OK, but due to the change, in DOSXYZnrc scoring and/or .3ddose output there is something wrong (I did re-compile in both ctcreate and dosxyznrc). See attached screenshot. Actually when I open the .3ddose I see that every other value is 0, so in this screenshot the those low values might be interpolated by CERR. I had an e-mail correspondence with @blakewalters about this ~10 years ago, but remembered only this one change and can't remember was there something else that needed to be changed in order to make this work (correctly). |
While at it, why not allow for all 95 printable ASCII characters, starting at number 1 (char 49), up to the tilde (char 126), and then wrap around with space (char 32) up until number 0 (char 48). For a given medium index |
@ftessier et al - while I like the progress of more sophisticated solution for this, do you have some quick-fix for my issue above? |
I am guessing a corresponding change is required on the DOSXYZnrc side to read the egsphant information in double-digits. Looking into it now. |
Seems like the format for reading the media indices in DOSXYZnrc has to be adjusted to |
@ftessier great suggestion on using the full ASCII set. I'll look into implementing this, unless you already are! |
@ftessier Thanks a lot! Will try this once another simulation finishes (~tomorrow). I will confirm you then! |
Go ahead! Note that using the space ' ' character (ascii decimal 32) might prove confusing, but this will happen for medium 79, so at this point one is already confused anyways 😂 (we could also skip the ' ' char in the list, for 94 media). |
Sorry @ftessier - I need to postpone this till tomorrow - I had accidentally used ECUT=0.521 in my simulation instead of 0.7, so needed to restart with 0.7 - and it will finish tomorrow so hopefully you will wake-up with new information on this. |
@ojalaj I have another alternative for you to test! The commit I just added does the switch to using the full range of ASCII characters as Fred suggested. |
Hi Everyone: Sorry to be late to this party, and it sounds like you're already well on your way to iterating down to a solution, but I was able to retrieve that ancient email (2013) to which @ojalaj was referring: "Hi Jarkko: There should be no practical upper limit to the HU number that ctcreate can handle, provided that your CT ramp also goes up that high. Now, from your output, I can see that, for some reason, the high CT upper bounds you're entering for your ramp are causing the remainder of the inputs on those lines to shift to the right. These errors will cause an error in the phantom (.egsphant) file that you're creating. Now, the new version of ctcreate has a less restricted input format for these lines, so I would suggest that, once you get the new BEAMnrc release up and running, you use it to convert your data. Currently, only one digit can be used to store medium number in the .egsphant file. Thus, medium numbers >=10 will cause problems. So, to get around the fact that you have 10 media, you'll have to modify a couple of codes:
1399 FORMAT($IMAXi1); to: 1399 FORMAT($IMAXi2); then recompile ctcreate by typing "make" in this directory.
:medformat: FORMAT($IMAXi1); to: :medformat: FORMAT($IMAXi2); then recompile dosxyznrc by typing "make" in this directory. This will allow dosxyznrc to read 2 digits specifying the medium no. Good luck, and let us know if there are any further issues." Now, I can't find a response to this particular email, so I'm assuming that the fix worked at the time. |
Thanks @blakewalters for confirming, and thanks @rtownson for the ascii conversion update, which means we don't have to modify dosxyznrc in the end, and |
Well we have to modify dosxyznrc for the conversion from ascii back to medium index:
|
Oh, whoops. I made those changes but they didn't get caught. I guess I forgot to copy the modified dosxyz from egs_home to HEN_HOUSE! I'll fix that. |
d087ea1
to
6c75322
Compare
@ftessier If there is no reason not to increase Anyhow, @rtownson @ftessier I tried with changes provided here. I did re-compile both ctcreate and dosxyz (under EGS_HOME). .egsphant looks as expected, i.e., I have expected characters for media # 9+. Then I tried both batch and interactive runs. For interactive run I get following:
and for batch runs to wX.eo files the following:
and some slurm related seg fault lines. This shouldn't be memory related since in Slurm generated emails I have "Memory Utilized: 2.58 GB Memory Efficiency: 85.89% of 3.00 GB". Any hints how to fix this? |
Thanks @ojalaj, I guess we have to go back and test this ourselves then 😃 . Strange, the code change seems pretty innocuous. The issue with increasing |
@ftessier OK, I fully understand the memory issue with FYI that since in |
I find some instances in the EGSnrc core where |
@ftessier one would have to test if there is any significant impact in performance when defaulting to 95 media instead of a much smaller number of media. A simplistic test could be running a simulation for a large homogeneous phantom once with But for users working with their home computers, maybe running VMs, RAM could be somewhat limited. Perhaps most machines in the world nowadays have enough memory to deal with EGSnrc defaulting to 95 media? 😉 I was working at home using a Windows laptop on WSL2 under the assumption 8GB was good enough for the quick things I was running, but the machine was constantly accessing the hard drive (swapping???) and at times slow. It all got better after I installed 16 GB of RAM and an SSD hard drive. Maybe a compromising solution would be to increase BTW in common |
I get roughly a 10 MB increase in RESident memory when going from ### MXMED = 1
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21001 ftessier 20 0 51484 4128 1872 R 99.7 0.0 0:12.14 dosxyznrc
### MXMED = 95
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
20725 ftessier 20 0 150940 15476 1876 R 100.0 0.1 0:42.93 dosxyznrc So all in all, I say we just increase the default For the record, with ### MXMED = 20 (current default)
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25389 ftessier 20 0 153004 30412 1876 R 98.7 0.1 0:03.01 dosxyznrc
### MXMED = 95
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25005 ftessier 20 0 237780 40044 1872 R 100.0 0.2 0:10.41 dosxyznrc so resident memory increases from 30 MB to 40 MB, i.e. by 30%. By the way, dosxyznrc (EGSnrc) itself can handle |
@rtownson Yes and yes. |
@ojalaj could you email me the egsphant file, perhaps? Or the CT data and ctcreate input file, if it is anonymous. |
@rtownson I'll send you a link to download the .egsphant and .inp soon. |
After the most recent commit no seg fault anymore! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @rtownson!
Doesn't that break the legacy files, which expect indices 1 to 9? Oh, were they 0 to 9 before? |
Yes they were 0-9 before, which was a surprise to me. But both Jarkko and I had old egsphant files with 0's in them! I guess it made sense to use the extra character to get 10 materials. |
Good question, @ftessier. It's always been possible (but I'm not sure how probable) to have med=0 in the .egsphant file but then this gets assigned to vacuum, not the first medium of the ramp (i.e. in the list of media in the .egphant file). I think we're okay as long as, on the ctcreate end, the ramp starts with med=1, which was the case when I tested this. |
Add support for more than 9 materials in egsphant files by changing the material indexing to iterate through all 95 printable ASCII characters. Previously, media indices greater than 9 were replaced with '*' and the resulting invalid egsphant file caused a crash in DOSXYZnrc.
11c6aee
to
373b42e
Compare
@rtownson I squashed the 3 commites together; is the combined commit message fine by you? |
I have always thought that med=0 is somehow 'reserved'/hardcoded for vacuum inside the code. E.g. in PIRS794 Ch 5.3 for medsur it says "The default setting of medsur is 0, indicating the surrounding region is vacuum.", Ch 16.2.5 for ctcreate it says "If the CT number in a voxel is less than material ct lower bound then the medium in that voxel is set to vacuum with density zero." (and in this case med=vacuum=0). And yes, as @rtownson wrote, I do have legacy .egsphant files with 0s, perhaps due to latter example from PIRS794. |
Revert to the egs_brachy encoding for egsphant files, allowing for 63 media encoded with the set of alphanumeric characters (where 0 is reserved for vacuum). Briefly, #633 expanded the number of media in egsphant files to 95, using all printable ascii characters. However, the number of media was also independently expanded in egs_glib for the development of egs_brachy, but using a different encoding consisting of only the 63 alphanumeric ascii characters. This led to inconsistent egsphant files that are no longer interchangeable. This issue was originally reported and discussed in clrp-code/egs_brachy#22.
Revert to the egs_brachy encoding for egsphant files, allowing for 63 media encoded with the set of alphanumeric characters (where 0 is reserved for vacuum). Briefly, #633 expanded the number of media in egsphant files to 95, using all printable ascii characters. However, the number of media was also independently expanded in egs_glib for the development of egs_brachy, but using a different encoding consisting of only the 63 alphanumeric ascii characters. This led to inconsistent egsphant files that are no longer interchangeable. This issue was originally reported and discussed in clrp-code/egs_brachy#22.
Revert to the egs_brachy encoding for egsphant files, allowing for 62 media encoded with the set of alphanumeric characters (where 0 is reserved for vacuum). Briefly, #633 expanded the number of media in egsphant files to 95, using all printable ascii characters. However, the number of media was also independently expanded in egs_glib for the development of egs_brachy, but using a different encoding consisting of only the 62 alphanumeric ascii characters. This led to inconsistent egsphant files that are no longer interchangeable. This issue was originally reported and discussed in clrp-code/egs_brachy#22.
Revert to the egs_brachy encoding for egsphant files, allowing for 62 media encoded with the set of alphanumeric characters (where 0 is reserved for vacuum). Briefly, #633 expanded the number of media in egsphant files to 95, using all printable ascii characters. However, the number of media was also independently expanded in egs_glib for the development of egs_brachy, but using a different encoding consisting of only the 62 alphanumeric ascii characters. This led to inconsistent egsphant files that are no longer interchangeable. This issue was originally reported and discussed in clrp-code/egs_brachy#22.
Revert to the egs_brachy encoding for egsphant files, allowing for 62 media encoded with the set of alphanumeric characters (where 0 is reserved for vacuum). Briefly, #633 expanded the number of media in egsphant files to 95, using all printable ascii characters. However, the number of media was also independently expanded in egs_glib for the development of egs_brachy, but using a different encoding consisting of only the 62 alphanumeric ascii characters. This led to inconsistent egsphant files that are no longer interchangeable. This issue was originally reported and discussed in clrp-code/egs_brachy#22.
Change the egsphant reading/writing algorithms in ctcreate and DOSXYZnrc so that up to 95 materials are allowed. Previously, for media indices greater than 9 they were replaced with
*
and the resulting egsphant file would not be valid, resulting in a crash in DOSXYZnrc.As per Fred's suggestion below, the full range of 95 ASCII printable characters are used for the material indices in the egsphant file. This makes the file slightly less human-readable, but is backwards compatible (expanding to 2 digits per index is not). I made a change from his indexing scheme so that it starts from 0.
This didn't require any changes to egs++ or egs_view, because the XYZ geometry uses the ramp file to assign materials. Other custom codes will need to be updated in order to read new phantoms with >9 materials, but phantoms generated with <=9 materials will still be backward compatible because the indexing starts at 0.
3rd party codes that I know of that might want to update:
3ddose_tools
,egs_brachy
,CERR
(I'm not sure if it reads egsphant, but it does read 3ddose).