Model
symbolica.community.hepkit Class
Model(path: str | os.PathLike | pathlib.Path) A loaded particle model ready for diagram generation.
Models provide typed access to particles, parameters, couplings, interaction rules, propagators, and numerical parameter-card updates.
Examples
Built-in models need no external files. To import your own UFO directory, see UfoLoader; to restore a normalized JSON model, use Model(path) or Model.from_json.
from symbolica import S, E
from symbolica.community import hepkit as hep
model = hep.Model.standard_model()
photon = model.particle("a")
process = model.process(["e-", "e+"], ["mu-", "mu+"])
result = process.generate_diagrams()
assert result.report.completed
scalar_model = hep.Model.phi4()
assert scalar_model.particle("phi").spin == 1Parameters
pathstr or os.PathLikePath to a normalized HEP JSON model.
Constructor
#Load a model from a normalized HEP JSON file.
Examples
Using the setup in the Model class example:
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as directory:
path = Path(directory) / "model.json"
model.write_json(path)
restored = hep.Model(path)
assert restored.name == model.nameParameters
| Name | Type | Default | Description |
|---|---|---|---|
path | str | os. | — | Path to the JSON model. |
Member details
name
Property · read-only#name: strReturn the model name.
Examples
Using the setup in the Model class example:
model = hep.Model.standard_model()
model_name = model.namerestriction
Property · read-only#restriction: Optional[str] Return the applied restriction name, when present.
Examples
Using the setup in the Model class example:
model = hep.Model.standard_model()
restriction = model.restrictionparticles
Property · read-only#particles: list[Particle] Return all particle species in deterministic model order.
Examples
Using the setup in the Model class example:
fermions = [particle for particle in model.particles if particle.spin == 2]parameters
Property · read-only#parameters: list[Parameter] Return all external and internal parameters in model order.
Examples
Using the setup in the Model class example:
external = [p for p in model.parameters if p.nature == hep.ParameterNature.EXTERNAL]couplings
Property · read-only#couplings: list[Coupling] Return all interaction couplings in model order.
Examples
Using the setup in the Model class example:
qed = [c for c in model.couplings if c.orders.get("QED", 0) > 0]vertex_rules
Property · read-only#vertex_rules: list[VertexRule] Return all interaction vertex rules in model order.
Examples
Using the setup in the Model class example:
electron_vertices = [v for v in model.vertex_rules if "e-" in v.particles]lorentz_structures
Property · read-only#lorentz_structures: list[LorentzStructure] Return all reusable Lorentz structures in model order.
Examples
Using the setup in the Model class example:
lorentz_by_name = {item.name: item for item in model.lorentz_structures}propagators
Property · read-only#propagators: list[Propagator] Return all model-defined propagators in model order.
Examples
Using the setup in the Model class example:
propagators_by_name = {item.name: item for item in model.propagators}functions
Property · read-only#functions: list[ModelFunction] Return all helper functions available to model expressions.
Examples
Using the setup in the Model class example:
functions = {function.name: function for function in model.functions}form_factors
Property · read-only#form_factors: list[FormFactor] Return all momentum-dependent model form factors in model order.
Examples
Using the setup in the Model class example:
form_factors = {factor.name: factor for factor in model.form_factors}standard_model
Static method#standard_model() -> ModelLoad the complete embedded Standard Model with default parameters. No model files or UFO installation are required.
Examples
Using the setup in the Model class example:
model = hep.Model.standard_model()qcd
Static method#qcd() -> ModelLoad QCD with six quark flavors, gluons, and gluon ghosts, filtered from the Standard Model. Preserves its parameters and their default values.
Examples
Using the setup in the Model class example:
model = hep.Model.qcd()qed
Static method#qed() -> ModelLoad QED with photons and all charged fermions (including quarks), filtered from the Standard Model. Preserves its parameters and their default values.
Examples
Using the setup in the Model class example:
model = hep.Model.qed()electroweak
Static method#electroweak() -> ModelLoad the electroweak Standard Model, retaining quarks, Higgs, Goldstones, and electroweak ghosts, and removing gluons and gluon ghosts.
Examples
Using the setup in the Model class example:
model = hep.Model.electroweak()qcd_qed
Static method#qcd_qed() -> ModelLoad strong and electromagnetic interactions of all quarks and charged leptons, including gluon ghosts, with Standard Model parameters.
Examples
Using the setup in the Model class example:
model = hep.Model.qcd_qed()yang_mills
Static method#yang_mills() -> ModelLoad pure SU(3) Yang-Mills theory: gluons and gluon ghosts without quarks.
Examples
Using the setup in the Model class example:
model = hep.Model.yang_mills()phi3
Static method#phi3() -> ModelLoad a real scalar phi with L_int = -g phi^3 / 3!. The external parameters mass and g default to one; the width is zero.
Examples
Using the setup in the Model class example:
model = hep.Model.phi3()phi4
Static method#phi4() -> ModelLoad a real scalar phi with L_int = -lam phi^4 / 4!. The external parameters mass and lam default to one; the width is zero.
Examples
Using the setup in the Model class example:
model = hep.Model.phi4()phi_3_4
Static method#phi_3_4() -> ModelLoad a real scalar phi with L_int = -g phi^3 / 3! - lam phi^4 / 4!. Independent parameters mass, g, and lam default to one; the width is zero.
Examples
Using the setup in the Model class example:
model = hep.Model.phi_3_4()scalar_qed
Static method#scalar_qed() -> ModelLoad scalar QED in Feynman gauge with a, phi+, and phi-. Parameters mass=e=1 and lam=0; the scalar potential is mass^2 |phi|^2 + lam |phi|^4 / 4, and all widths vanish.
Examples
Using the setup in the Model class example:
model = hep.Model.scalar_qed()from_json
Static method#from_json(json: str) -> ModelParse a model from its JSON representation.
Examples
Using the setup in the Model class example:
model_json = model.to_json()
restored = hep.Model.from_json(model_json)
assert restored.name == model.nameParameters
| Name | Type | Default | Description |
|---|---|---|---|
json | str | — | Serialized model object. |
process
Method#process(incoming: Sequence[Particle | ParticleSelector | str | int], outgoing: Sequence[Particle | ParticleSelector | str | int], *, particle_veto: Optional[Sequence[Particle | ParticleSelector | str | int]] = None, particle_selection: Optional[Sequence[Particle | ParticleSelector | str | int]] = None, vertex_allow: Optional[Sequence[VertexRule | str]] = None, vertex_veto: Optional[Sequence[VertexRule | str]] = None) -> Process Define a process with model-validated external states and sector restrictions. The returned process is immutable; loops and other calculation choices are arguments to its generate_diagrams, generate_amplitude and generate_cross_section methods.
Examples
Using the setup in the Model class example:
process = model.process(["e-", "e+"], ["a", "a"])
amplitude = process.generate_amplitude(loops=0)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
incoming | Sequence[ | — | Ordered incoming external states. |
outgoing | Sequence[ | — | Ordered outgoing external states. |
particle_veto | Optional[ | None | Excluded species, including their antiparticles. |
particle_selection | Optional[ | None | Allowed species, including their antiparticles. None allows all; an empty list allows none. Mutually exclusive with particle_veto. |
vertex_allow | Optional[ | None | Allowed interactions. None allows all; an empty list allows none. |
vertex_veto | Optional[ | None | Excluded interactions. |
particle
Method#particle_by_pdg
Method#particle_by_pdg(pdg: int) -> ParticleLook up a particle by PDG code.
Examples
Using the setup in the Model class example:
particle = model.particle_by_pdg(11)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pdg | int | — | Signed PDG particle code. |
parameter
Method#coupling
Method#parse_expression
Method#parse_expression(source: str) -> ExpressionParse a diagram expression with this model's parameter and coupling names.
Graph and tensor functions use the same short names as DOT input. Bare dim and Nc resolve to gammalooprs::dim and spenso::Nc. Other unknown names use the calling module's Symbolica namespace, as in E(...). Explicit namespaces select the exact symbol.
Examples
model = hep.Model.standard_model()
weight = model.parse_expression("GC_11*Q(0,cind(0))")
assert model.parse_expression("MT") == model.parameter("MT").symbolReturns
Expression
Parsed expression, suitable for operations such as model.expand_couplings.
Raises
ValueErrorIf the expression cannot be parsed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | str | — | Symbolica expression in diagram notation. |
scalar_bindings
Method#scalar_bindings(card: Optional[ParameterCard] = None, *, overrides: Optional[Dict[symbolica.Expression, symbolica.Expression]] = None) -> Dict[symbolica.Expression, symbolica.Expression] Return exact model scalar bindings with all named dependencies resolved.
Internal parameter and coupling definitions remain analytic; cached dependent values are not used. Numerical model/card inputs are converted to exact binary64 rationals. This operation does not mutate the model or numerically recompute it. Unknown symbols and UFO functions outside the returned map are retained, not evaluated.
Examples
from symbolica import E
model = hep.Model.standard_model()
values = model.scalar_bindings(overrides={
model.parameter("MT").symbol: E("345/2"),
model.parameter("ymt").symbol: E("345/2"),
model.parameter("WT").symbol: E("0"),
model.parameter("WH").symbol: E("0"),
})
assert values[model.parameter("MT").symbol] == E("345/2")Returns
dict[Expression, Expression]
Native exact expressions keyed by model and additional override symbols.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
card | Optional[ | None | Restriction applied to a copy, including explicit internal overrides. Pass it explicitly even if already applied to the model, because the model does not retain the history of internal overrides. |
overrides | Optional[ | None | Exact scalar definitions, keyed by plain symbols. They take precedence over model/card values before dependencies are resolved. Model parameters can be set here without creating a parameter card. |
vertex_rule
Method#vertex_rule(name: str) -> VertexRuleLook up a vertex rule by name.
Examples
Using the setup in the Model class example:
vertex = model.vertex_rule("V_1")Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | — | Vertex-rule name. |
lorentz_structure
Method#lorentz_structure(name: str) -> LorentzStructureLook up a Lorentz structure by name.
Examples
Using the setup in the Model class example:
lorentz = model.lorentz_structure("FFV1")Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | — | Lorentz-structure name. |
propagator
Method#propagator(name: str) -> PropagatorLook up a propagator by name.
Examples
Using the setup in the Model class example:
name = model.propagators[0].name
propagator = model.propagator(name)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | — | Propagator name. |
function
Method#function(name: str) -> ModelFunctionLook up a model function by name.
Examples
Using model from the class example. A model may have no helper functions:
functions = [model.function(item.name) for item in model.functions]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | — | Function name. |
form_factor
Method#form_factor(name: str) -> FormFactorLook up a form factor by name.
Examples
Using model from the class example. A model may have no form factors:
form_factors = [model.form_factor(item.name) for item in model.form_factors]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | — | Form-factor name. |
default_parameter_card
Method#default_parameter_card() -> ParameterCardBuild a parameter card from the model's current external values.
Examples
Using the setup in the Model class example:
card = model.default_parameter_card()with_parameter_card
Method#with_parameter_card(card: ParameterCard, evaluator: collections.abc.Callable[[EvaluationRequest], EvaluatedValues] | None = None) -> Model Return a copy with a parameter card applied atomically.
Examples
Using the setup in the Model class example:
card = model.default_parameter_card()
card.set("MM", 0.105658, 0.0)
updated = model.with_parameter_card(card)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
card | ParameterCard | — | External parameter values to apply. |
evaluator | collections. | None | Optional evaluator used to recompute dependent values. |
recompute_with
Method#recompute_with(evaluator: collections.abc.Callable[[EvaluationRequest], EvaluatedValues]) -> Model Return a copy with all dependent values recomputed by a callback.
Examples
This callback evaluates the built-in scalar model at its default coupling lam=1. See EvaluationRequest for callback inputs.
from symbolica import S, E
from symbolica.community import hepkit as hep
model = hep.Model.phi4()
process = model.process(["phi", "phi"], ["phi", "phi"])
requests = []
def evaluate(request):
requests.append(request)
return hep.EvaluatedValues(
couplings={"SCALAR_COUPLING": (0.0, -1.0)},
)
updated_model = model.recompute_with(evaluate)
request = requests[0]
formulas = {item.name: item.expression for item in request.couplings}Parameters
| Name | Type | Default | Description |
|---|---|---|---|
evaluator | collections. | — | Callback that evaluates every expression in a request. |
to_json
Method#to_json(pretty: bool = True) -> strSerialize the model as JSON.
Examples
Using the setup in the Model class example:
model.to_json(pretty=False)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pretty | bool | True | Indent the output when true. |
write_json
Method#write_json(path: str | os.PathLike | pathlib.Path) -> None Write the model to a JSON file.
Examples
Using the setup in the Model class example:
model.write_json("model.json")Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path | str | os. | — | Destination for the JSON model. |
__repr__
Method#__repr__() -> strSummarize the defining data as well as the name and particle count.
Examples
Using the setup in the Model class example:
print(model)_repr_html_
Method#_repr_html_() -> strRender a compact inventory of the model in notebook frontends.
Examples
Using the setup in the Model class example:
from IPython.display import display
display(model)_repr_pretty_
Method#_repr_pretty_(pretty: Any, cycle: bool) -> None Write the concise model summary to an IPython pretty printer.
Examples
Using the setup in the Model class example:
from IPython.lib.pretty import pretty
text = pretty(model)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pretty | Any | — | The IPython pretty-printer object. |
cycle | bool | — | Whether this object is part of a recursive formatting cycle. |
expand_couplings
Method#Overloads
Overload 1 #
expand_couplings(expression: TensorExpression) -> TensorExpressionReplace named UFO coefficients by their analytic model expressions.
The input and the stored model are unchanged.
Examples
Using the setup in the Model class example:
analytic = model.expand_couplings(S("UFO::GC_11"))Parameters
| Name | Type | Default | Description |
|---|---|---|---|
expression | TensorExpression | — | Symbolica expression containing named couplings from this model. |
Overload 2 #
expand_couplings(expression: Expression) -> ExpressionReplace named UFO coefficients by their analytic model expressions.
The input and the stored model are unchanged.
Examples
Using the setup in the Model class example:
analytic = model.expand_couplings(S("UFO::GC_11"))Parameters
| Name | Type | Default | Description |
|---|---|---|---|
expression | Expression | — | Symbolica expression containing named couplings from this model. |
View generated signature source: docs/api/python/feynkit-community.pyi:7402