FeynKit · latest
On this page

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 == 1

Parameters

path str or os.PathLike

Path 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.name

Parameters

NameTypeDefaultDescription
pathstr | os.PathLike | pathlib.Path—

Path to the JSON model.

Member details

name

Property · read-only#
name: str

Return the model name.

Examples

Using the setup in the Model class example:

model = hep.Model.standard_model()
model_name = model.name

restriction

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.restriction

particles

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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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() -> Model

Load 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) -> Model

Parse 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.name

Parameters

NameTypeDefaultDescription
jsonstr—

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

NameTypeDefaultDescription
incomingSequence[Particle | ParticleSelector | str | int]—

Ordered incoming external states.

outgoingSequence[Particle | ParticleSelector | str | int]—

Ordered outgoing external states.

particle_vetoOptional[Sequence[Particle | ParticleSelector | str | int]]None

Excluded species, including their antiparticles.

particle_selectionOptional[Sequence[Particle | ParticleSelector | str | int]]None

Allowed species, including their antiparticles. None allows all; an empty list allows none. Mutually exclusive with particle_veto.

vertex_allowOptional[Sequence[VertexRule | str]]None

Allowed interactions. None allows all; an empty list allows none.

vertex_vetoOptional[Sequence[VertexRule | str]]None

Excluded interactions.

particle

Method#
particle(name: str) -> Particle

Look up a particle by name.

Examples

Using the setup in the Model class example:

electron = model.particle("e-")
assert electron.pdg_code == 11

Parameters

NameTypeDefaultDescription
namestr—

Particle name or antiname.

particle_by_pdg

Method#
particle_by_pdg(pdg: int) -> Particle

Look up a particle by PDG code.

Examples

Using the setup in the Model class example:

particle = model.particle_by_pdg(11)

Parameters

NameTypeDefaultDescription
pdgint—

Signed PDG particle code.

parameter

Method#
parameter(name: str) -> Parameter

Look up a parameter by name.

Examples

Using the setup in the Model class example:

mass = model.parameter("MM")
assert mass.nature == hep.ParameterNature.EXTERNAL

Parameters

NameTypeDefaultDescription
namestr—

Parameter name.

coupling

Method#
coupling(name: str) -> Coupling

Look up a coupling by name.

Examples

Using the setup in the Model class example:

coupling = model.coupling("GC_1")

Parameters

NameTypeDefaultDescription
namestr—

Coupling name.

parse_expression

Method#
parse_expression(source: str) -> Expression

Parse 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").symbol

Returns

Expression

Parsed expression, suitable for operations such as model.expand_couplings.

Raises

ValueError

If the expression cannot be parsed.

Parameters

NameTypeDefaultDescription
sourcestr—

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

NameTypeDefaultDescription
cardOptional[ParameterCard]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.

overridesOptional[Dict[symbolica.Expression, symbolica.Expression]]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) -> VertexRule

Look up a vertex rule by name.

Examples

Using the setup in the Model class example:

vertex = model.vertex_rule("V_1")

Parameters

NameTypeDefaultDescription
namestr—

Vertex-rule name.

lorentz_structure

Method#
lorentz_structure(name: str) -> LorentzStructure

Look up a Lorentz structure by name.

Examples

Using the setup in the Model class example:

lorentz = model.lorentz_structure("FFV1")

Parameters

NameTypeDefaultDescription
namestr—

Lorentz-structure name.

propagator

Method#
propagator(name: str) -> Propagator

Look up a propagator by name.

Examples

Using the setup in the Model class example:

name = model.propagators[0].name
propagator = model.propagator(name)

Parameters

NameTypeDefaultDescription
namestr—

function

Method#
function(name: str) -> ModelFunction

Look 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

NameTypeDefaultDescription
namestr—

Function name.

form_factor

Method#
form_factor(name: str) -> FormFactor

Look 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

NameTypeDefaultDescription
namestr—

Form-factor name.

default_parameter_card

Method#
default_parameter_card() -> ParameterCard

Build 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

NameTypeDefaultDescription
cardParameterCard—

External parameter values to apply.

evaluatorcollections.abc.Callable[[EvaluationRequest], EvaluatedValues] | NoneNone

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

NameTypeDefaultDescription
evaluatorcollections.abc.Callable[[EvaluationRequest], EvaluatedValues]—

Callback that evaluates every expression in a request.

to_json

Method#
to_json(pretty: bool = True) -> str

Serialize the model as JSON.

Examples

Using the setup in the Model class example:

model.to_json(pretty=False)

Parameters

NameTypeDefaultDescription
prettyboolTrue

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

NameTypeDefaultDescription
pathstr | os.PathLike | pathlib.Path—

Destination for the JSON model.

__repr__

Method#
__repr__() -> str

Summarize 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_() -> str

Render 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

NameTypeDefaultDescription
prettyAny—

The IPython pretty-printer object.

cyclebool—

Whether this object is part of a recursive formatting cycle.

expand_couplings

Method#

Overloads

Overload 1 #
expand_couplings(expression: TensorExpression) -> TensorExpression

Replace 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
NameTypeDefaultDescription
expressionTensorExpression—

Symbolica expression containing named couplings from this model.

Overload 2 #
expand_couplings(expression: Expression) -> Expression

Replace 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
NameTypeDefaultDescription
expressionExpression—

Symbolica expression containing named couplings from this model.