Skip to content
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

mccode-antlr: Add mccode_config / m[c,x]run entry for MCCOGEN #1749

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

willend
Copy link
Contributor

@willend willend commented Oct 21, 2024

These few edits allow the use of a non-standard code-generator, e.g. mcstas-antlr, via the new config item MCCOGEN. By default this entry assumes the same value as MCCODE, i.e. the build-time @FLAVOR@.

By following the steps

  1. pip install mccode-antlr --upgrade
  2. plus potentially ln -s /path/to/mcstas-antlr/ /path/to/mcstas-install/bin/mcstas-antlr
    the antlr-based mcstas-antlr from @g5t can be used

The second step may be required on some systems, since m[c,x]run (for the sake of not "mixing" parallel mccode installations) assume that the code generator is located in the mccode bin folder

@willend willend requested a review from g5t October 21, 2024 08:25
@willend
Copy link
Contributor Author

willend commented Oct 21, 2024

@g5t a couple of potential integration-improvements to do in mccode-antlr are

  • A flag to request mcstas-antlr defaulting to pick up comps from the local installation (perhaps this exists already? :-) )
  • A conda-forge feedstock would be nice

@willend
Copy link
Contributor Author

willend commented Oct 21, 2024

@g5t the commit in the "parked" part of the comp lib is in fact related, since mcstas-antlr picked up a stale version of the union NCrystal_process.comp from there rather than the union folder:

Downloading file 'mcstas-comps/parked/Union_plus_NCrystal/NCrystal_process.comp' from 'https://github.com/McStasMcXtrace/McCode/raw/v3.5.6/mcstas-comps/parked/Union_plus_NCrystal/NCrystal_process.comp' to '/Users/peterwillendrup/Library/Caches/mcstas/v3.5.6'.

I would think/guess this all together makes "all" current McStas instruments function with the antlr cogen

@willend
Copy link
Contributor Author

willend commented Oct 21, 2024

@g5t as discussed in the hallway, passing a -I to mcstas-antlr works, albeit I couldn't make it work with a single -I $MCSTAS. (It seems the tree was not traversed, the process was somehow hung.)

But adding a number of separate entries did work:
"MCCOGEN": "mcstas-antlr -I /Users/peterwillendrup/McStas/mcstas/3.x-dev/sources -I /Users/peterwillendrup/McStas/mcstas/3.x-dev/optics -I /Users/peterwillendrup/McStas/mcstas/3.x-dev/samples -I /Users/peterwillendrup/McStas/mcstas/3.x-dev/monitors -I /Users/peterwillendrup/McStas/mcstas/3.x-dev/union -I /Users/peterwillendrup/McStas/mcstas/3.x-dev/misc",

Also, this makes Union + Crystal function, as expected

(mcstas-3.x-dev/miniconda3) Union_NCrystal_example $ mcrun -c Union_NCrystal_example.instr 
INFO: No output directory specified (--dir)
INFO: Using directory: "Union_NCrystal_example_20241021_130809"
INFO: Regenerating c-file: Union_NCrystal_example.c
2024-10-21 13:08:10.958 | DEBUG    | mccode_antlr.translators.c:sort_include_hierarchy:41 - sort includes :Monitor_nD(0):monitor_nd-lib :Monitor_nD(1):read_table-lib :Monitor_nD(2):interoff-lib
2024-10-21 13:08:10.958 | DEBUG    | mccode_antlr.translators.c:sort_include_hierarchy:66 - sorted to monitor_nd-lib  read_table-lib  interoff-lib
No initialization present?

-----------------------------------------------------------

Generating single GPU kernel or single CPU section layout:

-----------------------------------------------------------

Generating GPU/CPU -DFUNNEL layout:
-> GPU kernel from component init
-> GPU kernel from component NCrystal_mono
-> GPU kernel from component NCrystal_mono_material
-> GPU kernel from component NCrystal_sample
-> GPU kernel from component NCrystal_sample_material
-> GPU kernel from component origin
-> GPU kernel from component source
-> GPU kernel from component mono_arm
-> GPU kernel from component monochromator
Component master1 is NOACC, CPUONLY=False
->FUNNEL mode enabled, SPLIT within buffer.
-> GPU kernel from component master1
-> GPU kernel from component mono_out
-> GPU kernel from component powder_sample
Component master2 is NOACC, CPUONLY=False
->FUNNEL mode enabled, SPLIT within buffer.
-> GPU kernel from component master2
-> GPU kernel from component powder_pattern_detc
-> GPU kernel from component stop

-----------------------------------------------------------
INFO: Recompiling: ./Union_NCrystal_example.out
ld: warning: duplicate -rpath '/Users/peterwillendrup/McStas/mcstas/3.x-dev/miniconda3/lib' ignored
INFO: ===
Instrument parameters for Union_NCrystal_example (/Users/peterwillendrup/Union_NCrystal_example/Union_NCrystal_example.instr)
NCrystal: McStas Union process component(s) are using version 3.9.4 of the NCrystal library.
[Union_NCrystal_example] Initialize
---------------------------------------------------------------------
global_process_list_master->num_elements: 2
name of process [0]: NCrystal_mono 
component index [0]: 2 
name of process [1]: NCrystal_sample 
component index [1]: 4 
---------------------------------------------------------------------
global_material_list_master->num_elements: 2
name of material    [0]: NCrystal_mono_material 
component index     [0]: 3 
my_absoprtion       [0]: 1.215020 
number of processes [0]: 1 
name of material    [1]: NCrystal_sample_material 
component index     [1]: 5 
my_absoprtion       [1]: 0.042478 
number of processes [1]: 1 
---------------------------------------------------------------------
global_geometry_list_master->num_elements: 2

name of geometry    [0]: monochromator 
component index     [0]: 9 
Volume.name         [0]: monochromator 
Volume.p_physics.is_vacuum           [0]: 0 
Volume.p_physics.my_absorption       [0]: 1.215020 
Volume.p_physics.number of processes [0]: 1 
Volume.geometry.shape                [0]: box 
Volume.geometry.center.x             [0]: 0.000000 
Volume.geometry.center.y             [0]: 0.000000 
Volume.geometry.center.z             [0]: 0.800000 
Volume.geometry.rotation_matrix[0]           [0]: [0.707107 0.000000 -0.707107] 
Volume.geometry.rotation_matrix[1]           [0]: [-0.000000 1.000000 0.000000] 
Volume.geometry.rotation_matrix[2]           [0]: [0.707107 -0.000000 0.707107] 
Volume.geometry.focus_data_array.elements[0].Aim             [0]: [0.000000 0.000000 1.000000] 
---------------------------------------------------------------------
number_of_volumes = 2
number_of_masks = 0
number_of_masked_volumes = 0

 ---- Overview of the lists generated for each volume ---- 
List overview for surrounding vacuum
LIST: Children for Volume                  0 = [1]
LIST: Direct_children for Volume           0 = [1]
LIST: Intersect_check_list for Volume      0 = [1]
LIST: Mask_intersect_list for Volume       0 = []
LIST: Destinations_list for Volume         0 = []
LIST: Reduced_destinations_list for Volume 0 = []
LIST: Next_volume_list for Volume          0 = [1]
LIST: mask_list for Volume                 0 = []
LIST: masked_by_list for Volume            0 = []
LIST: masked_by_mask_index_list for Volume 0 = []
      mask_mode for Volume                 0 = 0

List overview for monochromator with box shape made of NCrystal_mono_material
LIST: Children for Volume                  1 = []
LIST: Direct_children for Volume           1 = []
LIST: Intersect_check_list for Volume      1 = []
LIST: Mask_intersect_list for Volume       1 = []
LIST: Destinations_list for Volume         1 = [0]
LIST: Reduced_destinations_list for Volume 1 = []
LIST: Next_volume_list for Volume          1 = [0]
      Is_vacuum for Volume                 1 = 0
      is_mask_volume for Volume            1 = 0
      is_masked_volume for Volume          1 = 0
      is_exit_volume for Volume            1 = 0
LIST: mask_list for Volume                 1 = []
LIST: masked_by_list for Volume            1 = []
LIST: masked_by_mask_index_list for Volume 1 = []
      mask_mode for Volume                 1 = 0

Union_master component master1 initialized sucessfully
---------------------------------------------------------------------
global_process_list_master->num_elements: 2
name of process [0]: NCrystal_mono 
component index [0]: 2 
name of process [1]: NCrystal_sample 
component index [1]: 4 
---------------------------------------------------------------------
global_material_list_master->num_elements: 2
name of material    [0]: NCrystal_mono_material 
component index     [0]: 3 
my_absoprtion       [0]: 1.215020 
number of processes [0]: 1 
name of material    [1]: NCrystal_sample_material 
component index     [1]: 5 
my_absoprtion       [1]: 0.042478 
number of processes [1]: 1 
---------------------------------------------------------------------
global_geometry_list_master->num_elements: 2

name of geometry    [1]: powder_sample 
component index     [1]: 12 
Volume.name         [1]: powder_sample 
Volume.p_physics.is_vacuum           [1]: 0 
Volume.p_physics.my_absorption       [1]: 0.042478 
Volume.p_physics.number of processes [1]: 1 
Volume.geometry.shape                [1]: cylinder 
Volume.geometry.center.x             [1]: -0.400000 
Volume.geometry.center.y             [1]: 0.000000 
Volume.geometry.center.z             [1]: 0.800000 
Volume.geometry.rotation_matrix[0]           [1]: [0.000000 0.000000 1.000000] 
Volume.geometry.rotation_matrix[1]           [1]: [-0.000000 1.000000 0.000000] 
Volume.geometry.rotation_matrix[2]           [1]: [-1.000000 -0.000000 0.000000] 
Volume.geometry.geometry_parameters.cyl_radius [1]: 0.010000 
Volume.geometry.geometry_parameters.height [1]: 0.010000 
Volume.geometry.focus_data_array.elements[0].Aim             [1]: [0.000000 0.000000 1.000000] 
---------------------------------------------------------------------
number_of_volumes = 2
number_of_masks = 0
number_of_masked_volumes = 0

 ---- Overview of the lists generated for each volume ---- 
List overview for surrounding vacuum
LIST: Children for Volume                  0 = [1]
LIST: Direct_children for Volume           0 = [1]
LIST: Intersect_check_list for Volume      0 = [1]
LIST: Mask_intersect_list for Volume       0 = []
LIST: Destinations_list for Volume         0 = []
LIST: Reduced_destinations_list for Volume 0 = []
LIST: Next_volume_list for Volume          0 = [1]
LIST: mask_list for Volume                 0 = []
LIST: masked_by_list for Volume            0 = []
LIST: masked_by_mask_index_list for Volume 0 = []
      mask_mode for Volume                 0 = 0

List overview for powder_sample with cylinder shape made of NCrystal_sample_material
LIST: Children for Volume                  1 = []
LIST: Direct_children for Volume           1 = []
LIST: Intersect_check_list for Volume      1 = []
LIST: Mask_intersect_list for Volume       1 = []
LIST: Destinations_list for Volume         1 = [0]
LIST: Reduced_destinations_list for Volume 1 = []
LIST: Next_volume_list for Volume          1 = [0]
      Is_vacuum for Volume                 1 = 0
      is_mask_volume for Volume            1 = 0
      is_masked_volume for Volume          1 = 0
      is_exit_volume for Volume            1 = 0
LIST: mask_list for Volume                 1 = []
LIST: masked_by_list for Volume            1 = []
LIST: masked_by_mask_index_list for Volume 1 = []
      mask_mode for Volume                 1 = 0

Union_master component master2 initialized sucessfully
*** TRACE end *** 

Save [Union_NCrystal_example]
Detector: powder_pattern_detc_I=1.61829e-10 powder_pattern_detc_ERR=2.39885e-12 powder_pattern_detc_N=7338 "powder_pattern_detc_1729508899.A"

Finally [Union_NCrystal_example: Union_NCrystal_example_20241021_130809]. Time: 1 [s] 
INFO: Placing instr file copy Union_NCrystal_example.instr in dataset Union_NCrystal_example_20241021_130809
INFO: Placing generated c-code copy Union_NCrystal_example.c in dataset Union_NCrystal_example_20241021_130809

@willend
Copy link
Contributor Author

willend commented Oct 21, 2024

@g5t I have been testing a bit and think I will simply deem this as "functional" and merge

@willend willend merged commit f15d470 into McStasMcXtrace:main Oct 21, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant