Releases: xsuite/xcoll
Releases · xsuite/xcoll
Xcoll release 0.7.2
Develop Updates
- Remove dunders from setting names in
Constantsto avoid incompatibilities with core Python name-mangling - Adapted prebuilt kernel definitions to include
EXTRA_XCOLL_CLASSES - Better GEANT4 compilation and environment checking
- Wrap
run(['which', ...], ...)intry.. exceptto avoid failing on systems wherewhichis not installed - Pre-compilation of
Geant4Collimatorworks, however, leads to segmentation fault when running. Might have to do withpybind11dependency.Temporarily removed from perbuilt kernels.
Full Changelog: v0.7.1...v0.7.2
Xcoll release 0.7.1
Develop Updates
- Fix: Auto-generate
configandlibfolders if missing - Fix:
Geant4Collimatordoes instantiate with_DEFAULT_MATERIALinstead ofMaterial()(which is forbidden) - this prevented the generation of prebuilt kernels
Full Changelog: v0.7.0...v0.7.1
Xcoll release 0.7.0
What's Changed
General
CollimatorDatabasenow hasto_dict,to_json, andto_yamlfunctionality.- New class
ParticlesTreeto inspect the family tree of particles and their children. This is an experimental feature and the API might change in future releases. See tests/test_particle_id_hierarchy.py for some example usage. Some inspection functions likeprint_tree(ASCII) andplot_tree(withmatplotlib) are available but limited in usability when many particles are shown.
Materials
- Expansive list of predefined materials and alias names (see
xcoll.materials.db.show()), including most atomic elements, and some relevant compounds and mixtures/alloys. Predefined materials originally fromK2still exist with a prefixed name (as inK2MolybdenumGraphite) for backward compatibility if needed. - Any material can now be defined, either as:
- an atomic element (e.g. different allotropes) by specifying
ZandA - a compound by specifiying
componentsandn_atoms - a mixture or alloy by specifying
componentsandmass_fractions,volume_fractions, ormolar_fractions(oratomic_fractionswhich is equivalent tomolar_fractions) - see examples/materials.py.
- an atomic element (e.g. different allotropes) by specifying
- The material property
densityis a required argument. Other material properties are automatically estimated, whileradiation_lengthandexcitation_energycan also be explicitly provided for more precision if known. Everest-specific parameters (nuclear_radius,nuclear_elastic_slope,cross_section, andhcut) are not yet automatically estimated (though this is in the pipeline). Without these, material interactions are only described by multiple-Coulomb scattering and ionisation loss (so no nuclear scattering). Most materials are hence only partiallyEverest-compatible. This can be verified with thefull_everest_supportedattribute.- Code auto-generation for Geant4/BDSIM (and blueprint for similar auto-generation for FLUKA) is in place.
Interface to Geant4
(#75, #77, #85, #114, #116, #123, #126, #128, #129, #130, #151 by @freddieknets, @bjlindst, @gbrogginess)
- Prerequisite: Need a complete installation of Geant4 and BDSIM (easiest is to install
bdsim-g4with conda/mamba). Then compile the interface withxcoll.geant4.environment.compile()(this needs to be done only once). - New element
Geant4Collimatorwhich works exactly like anEverestCollimatorbut with Geant4 physics. - Before scattering can be active, a connection to Geant4/BDSIM needs to be made. This is done by starting the engine:
xcoll.geant4.engine.start(). For this, the necessary arguments are eitherelementsorlineto specify which elements are to be linked (with the additional optional argumentnamesif it is only a subset), andparticle_refto describe the beam if not already provided by theline(and in case the line has a different reference particle, this is overwritten by the engine's one and restored when the engine stops). Optional arguments include:seedto set the seed in BDSIMcwdto define a run folder (a random named one is generated by default for the logs etc)cleanto clean up connection and log filesverboseto print out info during the connection setup and input file generationrelative_energy_cutto define a lower energy threshold in kinetic energy for child particles to be consideredphysics_listto specify the BDSIM/Geant4 physics list to be considered (otherwise a relevant list is chosen in function of the reference particle)stop_secondariesto avoid the generation of child particlesextra_optsandextra_inputwhich are extra options resp. commands to be put in thegmadfile to be sent to BDSIM.
- Note that engine attributes can be pre-set on the engine before starting. In that case, they keep their value even after stopping the engine (within the same Python session). Otherwise, they are reset to their defaults after stopping the engine.
- BDSIM uses an input file with some settings and definitions. This is auto-generated based on the options above, though, for full flexibility, a user-provided file can also be passed to the engine with the
input_fileargument. Note that, to ensure a certain input file is compatible for the set of elements passed to the engine, the input file has an Xcoll header (as comments) with relevant info of the elements. As it is not trivial to manually generate this header, a functionxcoll.geant4.engine.generate_input_file()is available to generate the input file (including the header) based on a line or set of elements, which can then be manually adapted to the user's wishes before using this file to start the engine. It takes the same arguments asxcoll.geant4.engine.start()with the additional optional argumentfilename. - There is a small caveat with starting and stopping the engine in succession (within the same python session, as e.g. happens when testing multiple tests with
pytest). Certain environment variables inside Geant4 are not cleared, making a second connection fail in a rather obscure way. This is beyond our control (it has been flagged to the Geant4 devs), but a workaround exists usingrpycto spawn a python session inside the current session, and connect from the nested one over a network protocol. This is the default behaviour (need topip install rpyc), but can be switched off as it produces a visible performance reduction (around 30% slower tracking). To achieve this, setxcoll.geant4.engine.reentry_protection_enabled = Falsebut this is at the user's own risk, as one has to remember to always exit and restart Python when tracking is interrupted, to avoid unexpected behaviour. - The material definition of an element is governed inside Xcoll, and the correct code to define it in BDSIM is auto-generated. If a material already exists in the built-in Geant4/BDSIM databases but not in Xcoll's, there are two options:
- Define the material in Xcoll the standard way, and set the attribute
geant4_nameto the correct name (case-sensitive). This will essentially ignore the Xcoll parameters and use the material definition in Geant4/BDSIM. It is the user's responsibility to make sure both definitions represent the same to avoid misunderstandings. - Use a
ReferenceMaterialwhich has no properties exceptgeant4_name. This is preferred, as it is clear that no Xcoll definition is used.
- Define the material in Xcoll the standard way, and set the attribute
- See the examples for more info.
Develop Updates
- To be able to use formatted output (as in the materials database), a function
styleis defined (inxcoll.pretty_print) which uses ANSI styles to format terminal output (color,bgfor background colour,italic,bold,underline, anddimare supported). - New class
Constantsto define anxobjects-style set of constants by deriving from it. Constant names are enforced to be unique across all modules the class is imported to. See xcoll/headers/particle_states.py for an example usage.- Inside the new class, the following attributes define its logic:
__category__for the name of the constant type (e.g.particle_state).__plural__(optional) if the auto-generated plural name of the category is not correct.__reverse__which can be"unique","multi", orNone(default:"unique"). If"unique", constants' values are enforced to be unique across all modules the class is imported to. IfNone, a reverse look-up does not exist.__c_prefix__to prefix the generated constant name in the C code.__include_guard__to wrap the C code in an include shield.
- Each constant is defined in the class as
NAME = constant(value, info=..., c_name=...)or without the wrapper as e.g.NAME = 9.8. The type is automatically deduced, and all constants should be of the same type if the map is reversible. Theinfoattribute is wrapped into a docstring, such that constants can be inspected in anipythonsession. Ifc_nameis not provided, it is auto-generated using the main C prefix. - A group of constants can be defined as
GROUPNAME = group(c1, c2, c3, ..., info=...). This is useful for things likenp.isin(part.state, xc.constants.USE_IN_LOSSMAP)whereUSE_IN_LOSSMAPrepresents all lost particle state codes for a loss map (apertures and all collimation elements). - The class on itself does nothing, but should be exported to a module using the function
export_to_module(). See e.g. xcoll/constants/__init__.py which imports the particle states and interaction types intoxcoll.constants. In particular it imports:- A mapping (dict) between all constant names and their values. This variable is named using its category plural name (e.g.
xcoll.constants.particle_states). - A reversed mapping between all constant values and their names, if the class is defined to be reversible. This variable is named as
<category>_names(e.g.xcoll.constants.particle_state_names). - If
include_src=True: a string with the C code. This variable is named as<plural>_src(e.g.xc.constants.particle_states_src) - If
include_meta=True: a mapping between...
- A mapping (dict) between all constant names and their values. This variable is named using its category plural name (e.g.
- Inside the new class, the following attributes define its logic:
Xcoll release 0.6.8
Development Changes
- Losses on aperture downstream of collimators should only be shifted to the collimator if it is active
Full Changelog: v0.6.7...v0.6.8
Xcoll release 0.6.7
Development Changes
- Bugfix: Allow
CollimatorDatabases with a single collimator - Bugfix: Allow installing collimators when
family=None(e.g. from json-style colldb)
Full Changelog: v0.6.6...v0.6.7
Xcoll release 0.6.6
Xcoll release 0.6.5
Xcoll release 0.6.4
What's Changed
- Made RFSweep backwards compatible (though with a deprecation warning)
- Added savefig to plot examples
Development updates
- Correct implementation of
pyproject.tomlfollowing PEP621 RFSweepchecks for the existence ofref_managerinstead of_xdeps_managerin theEnvironment
Full Changelog: v0.6.3...v0.6.4
Xcoll release 0.6.3
What's Changed
- Updated RFSweep to use time-dependent variables, as the old implementation had become very slow.
- Added SPS line to examples
Development Updates
- Dedicated prebuild kernels folder, as preparation to move the element definitions out of Xsuite
Full Changelog: v0.6.2...v0.6.3
Xcoll release 0.6.2
Development Updates
- Making lossmap plot test dependent on existing matplotlib installation (to be compatible with test servers)
Full Changelog: v0.6.1...v0.6.2