Replies: 12 comments 21 replies
-
One question is how the performance will compare when the file is very large. Since this only happens once per simulation I imagine it won't be important, but worth checking - I have an egsinp that's 9.2MB, let me know if you want to give it a try. |
Beta Was this translation helpful? Give feedback.
-
I like TOML (https://toml.io/) as well, it is simpler and clearer. I will try writing an |
Beta Was this translation helpful? Give feedback.
-
Below is a similar input file example in TOML. I really like the clean and unambiguous structure, however quoting all those strings is driving me nuts! 😄 . Use the following python snip to parse: # install toml with: pip install toml
import toml
with open("egsinp.toml") as egsinp:
egsinput = toml.loads(egsinp.read())
str = toml.dumps(egsinput)
print(str)
print(egsinput) ### ----------------------------------------------------------------------------
### Simulation
### ----------------------------------------------------------------------------
[simulation]
ncase = 1000
precision = 0.01
geometry = "chamber"
source = "my_source"
[simulation.rng]
type = "xoshiro"
seeds = [123, 1250]
### ----------------------------------------------------------------------------
### Geometries
### ----------------------------------------------------------------------------
# chamber tip
[[geometry]]
name = "chamber_tip"
type = "egs_spheres"
position = [0.931, 0.0, -10.0]
radii = [0.05, 0.311, 0.356, 0.36, 0.37, 1.0]
[geometry.media]
water = "all"
pmma = [0, 2]
air = [1, 3]
# chamber body
[[geometry]]
name = "chamber_body"
type = "EGS_ConeStack"
origin = [0.985, 0.01, -10.0]
direction = [-1, 0, 0]
[[geometry.layer]]
name = "electrode"
thickness = 2.03
top = [0.05, 0.311, 0.356]
bottom = [0.05, 0.311, 0.356]
media = ["pmma", "air", "pmma"]
[[geometry.layer]]
name = "stem"
thickness = 2.0
top = 0.61
bottom = 0.61
media = "pmma"
# combine chamber tip and body
[[geometry]]
name = "chamber"
type = "egs_cdgeometry"
template = "cd_planes_for_chamber"
[geometry.regions]
0 = "chamber_body"
1 = "chamber_tip"
### ----------------------------------------------------------------------------
### Sources
### ----------------------------------------------------------------------------
[[source]]
name = "my_source"
type = "egs_collimated_source"
particle = "photon"
spectrum.type = "monochromatic"
spectrum.energy = 6
shapes.source.type = "point"
shapes.source.position = [0, 0, 100]
shapes.target.type = "rectangle"
shapes.target.rectangle = [-5, 0, 5, 5] Note that the pythom toml library at this point only support the |
Beta Was this translation helpful? Give feedback.
-
Here is a better layout, where the geometries:
# the ion chamber spherical tip
chamber_tip:
class: egs_spheres
midpoint: [&pos 0.935, 0, -10]
radii: [0.05, 0.305, 0.355]
media:
water: all
air: [1, 2, 3]
pmma: [4, 5]
# the cylindrical body of the ion chamber
chamber_body:
class: egs_conestack
origin: [*pos, 0, -10]
direction: [-1, 0, 0]
layers:
- electrode:
thickness: 2.03
top radii: [0.05, 0.305, 0.355]
bottom radii: [0.05, 0.305, 0.355]
media: [&medium pmma, air, *medium]
- stem:
thickness: 2.0
top radii: 0.61
bottom radii: 0.61
media: *medium
# join the chamber tip and body to build chamber
chamber:
class: egs_cdgeometry
base geometry: cd_planes_for_chamber
fill region 0: chamber_body
fill region 1: chamber_tip
new indexing style: true which parses to the following JSON: {
"geometries": {
"chamber_tip": {
"class": "egs_spheres",
"midpoint": [
0.935,
0,
-10
],
"radii": [
0.05,
0.305,
0.355
],
"media": {
"water": "all",
"air": [
1,
2,
3
],
"pmma": [
4,
5
]
}
},
"chamber_body": {
"class": "egs_conestack",
"origin": [
0.935,
0,
-10
],
"direction": [
-1,
0,
0
],
"layers": [
{
"electrode": {
"thickness": 2.03,
"top radii": [
0.05,
0.305,
0.355
],
"bottom radii": [
0.05,
0.305,
0.355
],
"media": [
"pmma",
"air",
"pmma"
]
}
},
{
"stem": {
"thickness": 2.0,
"top radii": 0.61,
"bottom radii": 0.61,
"media": "pmma"
}
}
]
},
"chamber": {
"class": "egs_cdgeometry",
"base geometry": "cd_planes_for_chamber",
"fill region 0": "chamber_body",
"fill region 1": "chamber_tip",
"new indexing style": true
}
}
} I used the following python snippet to convert yaml to json: import sys
import yaml
import json
with open(sys.argv[1]) as f:
yaml_content = yaml.safe_load(f)
print(json.dumps(yaml_content, indent=4)) |
Beta Was this translation helpful? Give feedback.
-
Having a json representation would allow validation through a json schema. A json schema also allows for automatically generating a validating web interface to egsinp content. Strict json as an input syntax is not practical since there are too many quotes to type, and more critically it does not allow comments; rjson (relaxed json does), but at that point why not use yaml? 😉 |
Beta Was this translation helpful? Give feedback.
-
Scrap the idea of turning the name properties into the dictionary keys, this precludes writing a proper schema! So we should have the following, where for example geometries:
# the ion chamber spherical tip
- name: chamber_tip
class: spheres
midpoint: [&pos 0.935, 0, -10]
radii: [0.05, 0.305, 0.355]
media:
water: all
air: [1, 2, 3]
pmma: [4, 5]
# the cylindrical body of the ion chamber
- name: chamber_body
class: conestack
origin: [*pos, 0, -10]
direction: [-1, 0, 0]
layers:
- name: electrode
thickness: 2.03
top radii: [0.05, 0.305, 0.355]
bottom radii: [0.05, 0.305, 0.355]
media: [&medium pmma, air, *medium]
- name: stem
thickness: 2.0
top radii: 0.61
bottom radii: 0.61
media: *medium
# join the chamber tip and body to build chamber
- name: chamber
class: cdgeometry
base geometry: cd_planes_for_chamber
fill region 0: chamber_body
fill region 1: chamber_tip
new indexing style: true |
Beta Was this translation helpful? Give feedback.
-
Note that LLMs can help with extracting the schema from the current geometry {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "EGS_Box",
"type": "object",
"properties": {
"dimensions": {
"oneOf": [
{
"type": "array",
"items": { "type": "number" },
"minItems": 1,
"maxItems": 1,
"description": "Uniform size for all dimensions if only one value is provided."
},
{
"type": "array",
"items": { "type": "number" },
"minItems": 3,
"maxItems": 3,
"description": "Individual sizes for the x, y, and z dimensions."
}
]
},
"affine transform": {
"type": "object",
"description": "Optional affine transform applied to the box.",
"properties": {
"rotation": {
"type": "array",
"items": { "type": "number" },
"minItems": 9,
"maxItems": 9,
"description": "3x3 rotation matrix values in row-major order."
},
"translation": {
"type": "array",
"items": { "type": "number" },
"minItems": 3,
"maxItems": 3,
"description": "Translation vector for the transform."
}
},
"required": ["rotation", "translation"]
},
"boundary tolerance": {
"type": "number",
"description": "Tolerance value for the boundary of the box."
},
"media": {
"type": "array",
"items": { "type": "string" },
"description": "Array of media names associated with the box geometry."
},
"labels": {
"type": "array",
"items": { "type": "string" },
"description": "Array of labels for different parts or regions of the box."
}
},
"required": ["name", "dimensions"]
} |
Beta Was this translation helpful? Give feedback.
-
@ftessier I'm personally preferring yaml or toml to json, seems more human readable. |
Beta Was this translation helpful? Give feedback.
-
+1 for YAML. |
Beta Was this translation helpful? Give feedback.
-
Since we generally expect people to type input files, I'm hesitant to use any format that has much markup at all, or special characters. That's why I like the current format. Very little fluff, easy to read, no special characters except for ":". Editing any of these formats manually sounds like a huge headache. Unless we're proposing a whole new way to design input files, by GUI I suppose. The egs_editor addition would help a bit. |
Beta Was this translation helpful? Give feedback.
-
I've created a new repo for some ideas. Should there be a GitHub Project somewhere?
|
Beta Was this translation helpful? Give feedback.
-
I don't know that it is possible to generate a schema directly from the c++
classes. Is there a tool for that (I mean, apart from LLMs)?
I was suggesting to write what we want the input to look like in YAML, then
express the schema as JSON (to validate any input written in YAML), and
tweak the classes to match if needed. The YAML can be parsed in one go to
build a DOM with libyamlcpp or other standard c++ Li
brary.
Le ven. 22 nov. 2024, 15 h 28, Cody Crewson ***@***.***> a
écrit :
… My proposal is to use YAML, but with a JSON schema to validate YAML.
I see what you're suggesting now, if we pick a library and a class design,
then the JSON and YAML schemas come with them. If that's the case then the
work should be reversed. Could I propose that we design the JSON from a
reference class implementation, not the reverse?
—
Reply to this email directly, view it on GitHub
<#659 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALATEIDWESVYDPHFZS2UE32B6HWJAVCNFSM6AAAAABRKLMMXKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMZVGMYTGMQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
What do you think about using the well-known and standardized markup language YAML for EGSnrc input files, especially the egs++
.egsinp
files, instead of EGSnrc's own format (using:start
and:stop
tags and nested key-value pairs). The yaml specification is also a key-value pair format, so it is very similar to.egsinp
format.There are libraries readily available to parse yaml in all common languages, and one can write a JSON schema to automatically validate EGSnrc input files. In fact, the idea to look at yaml again was precipitated by the recent input validation discussion.
I have also considered TOML and JSON, but I don't think those fit the bill. Note that this can be implemented on the side (i.e., leaving the traditional
.egsinp
format available; if in time yaml input gained traction, we could also write a converter of course.I have been toying with the idea a little, and found the following pros for yaml input:
.egsinp
already (notably, whitespace is allowed in keys)&pos 0.935
and*pos
in the example below)<<: *tip
in example below)!!str 2.0
)Here is what a typical input might look like:
I am working on a JSON schema to specify the permitted and required EGSnrc input, for validation, and will post it here as soon as I have something decent.
Beta Was this translation helpful? Give feedback.
All reactions