UserSpace.absref#

UserSpace.absref(**kwargs)[source]#

Set references in absolute mode.

Creates references that maintain fixed bindings regardless of inheritance or space derivation. Absolute references always point to the exact object specified, even when accessed from derived spaces. The mode of a reference is relevant only when modelx objects, such as cells or spaces, are assigned to the reference.

This is a convenience method equivalent to calling set_ref() with refmode="absolute" for each reference.

Absolute vs Relative:

  • Absolute: Reference always points to the same object

  • Relative: Reference adjusts based on inheritance context

Parameters:

**kwargs – Keyword arguments where each key is the reference name and each value is the object to reference. Multiple references can be set in a single call.

Example

In the example below, a cells foo is defined in Space S. abs_foo in Space S is defined as an absolute reference to foo, while rel_foo is defined as a relative reference.

When Space S is inherited by S[y], abs_foo continues to point to S.foo, while rel_foo points to S[y].foo, which uses the parameter y in stead of S.y:

>>> import modelx as mx

>>> s  = mx.new_space('S')

>>> @mx.defcells
... def foo(x):
...     return x + y

>>> s.absref(abs_foo=foo)
>>> s.relref(rel_foo=foo)
>>> s.y = 0

>>> s.parameters = 'y'

>>> s[1].abs_foo(10)  # Absolute reference to S.foo
10

>>> s[1].rel_foo(10)  # Relative reference to S[1].foo
11

See also

  • relref(): Set references in relative mode

  • set_ref(): Set individual reference with explicit mode

  • refs: View all references