  Averting the impending harms of climate change requires to replace fossil
fuels with renewables as a primary source of energy. Non-electric renewable
potential being limited, this implies extending the use of electricity
generated from wind and solar beyond the power sector, either by direct
electrification or synthetic fuels. Modeling the transformation towards such an
energy system is challenging, because it imposes to consider fluctuations of
wind and solar and the manifold ways the demand side could adjust to these
fluctuations.
  This paper introduces a graph-based method to formulate energy system models
to address these challenges. By organizing sets in rooted trees, two features
to facilitate modeling high shares of renewables and sector integration are
enabled. First, the method allows the level of temporal and spatial detail to
be varied by energy carrier. This enables modeling with a high level of detail
and a large scope, while keeping models computationally tractable. Second, the
degree to which energy carriers are substitutable when converted, stored,
transported, or consumed can be modeled to achieve a detailed but flexible
representation of sector integration. An application of the formulation
demonstrates that the variation of temporal detail achieves an average
reduction in computation time of 70\%.
