Skip to content

Instantly share code, notes, and snippets.

@gonzalocasas
Created August 5, 2026 16:33
Show Gist options
  • Select an option

  • Save gonzalocasas/5d1e1d45c5a074abdb77b27172e3cc6c to your computer and use it in GitHub Desktop.

Select an option

Save gonzalocasas/5d1e1d45c5a074abdb77b27172e3cc6c to your computer and use it in GitHub Desktop.

Migrating from COMPAS 1.x to 2.x

.. rst-class:: lead

COMPAS 2 introduced a number of breaking changes with respect to COMPAS 1. This page summarises the changes that are most likely to affect existing code, and shows how to update it.

Note

This is a condensed overview. The complete list of changes is available in the changelog, in particular in the entries for 2.0.0-alpha.1 up to 2.0.0.

Artists are now scene objects

compas.artists no longer exists. Visualisation is handled by :class:`compas.scene.Scene` and the corresponding scene objects.

# COMPAS 1.x
from compas_rhino.artists import MeshArtist

artist = MeshArtist(mesh, layer="Test")
artist.draw()
# COMPAS 2.x
from compas.scene import Scene

scene = Scene()
scene.add(mesh)
scene.draw()
  • *Artist classes are renamed to *SceneObject and live in compas.scene, compas_rhino.scene, compas_ghpython.scene, and compas_blender.scene.
  • Context related functions (register, build, redraw, clear) moved to compas.scene.context, and Scene.redraw was renamed to Scene.draw.
  • The naming convention of the color dict attributes changed, for example from vertex_color to vertexcolor, and from node_color to nodecolor.
  • What is drawn is controlled with flags rather than with keyword arguments: show, show_points, show_lines, show_surfaces, show_vertices, show_edges, show_faces, show_cells. Each of these optionally accepts a sequence of keys instead of a boolean.
  • Scene objects form a tree, with parent, children, add(), frame, and worldtransformation. Scenes are serialisable.
  • The label drawing methods (draw_vertexlabels, draw_edgelabels, draw_facelabels, draw_celllabels) and the keyword arguments of draw were removed. Set the corresponding attributes on the scene object instead.

The data API

The interface of :class:`compas.data.Data` is based on dunder attributes.

COMPAS 1.x COMPAS 2.x
obj.data obj.__data__
obj.dtype obj.__dtype__
Cls.from_data(data) Cls.__from_data__(data)
obj.to_data() removed, use obj.__data__
obj.data = data removed, there are no data setters
  • The JSON schema machinery was removed: DATASCHEMA, JSONSCHEMANAME, validate_data, validate_json, validate_jsondata, validate_jsonstring, json_validate, and the bundled schema files.
  • :meth:`compas.data.Data.to_jsonstring` and :meth:`compas.data.Data.from_jsonstring` were added, as well as :func:`compas.json_dumpz` and :func:`compas.json_loadz` for ZIP compressed JSON files.
  • to_json, to_jsonstring, :func:`compas.json_dump`, and :func:`compas.json_dumps` take an additional compact=False parameter.
  • Data.name is only included in the serialised data if it was explicitly set.

Because of the datastructure changes described below, JSON files written with COMPAS 1 cannot be read with COMPAS 2, and vice versa.

Datastructures

  • Halfedge was merged into :class:`compas.datastructures.Mesh`, Halfface into :class:`compas.datastructures.VolMesh`, and Network into :class:`compas.datastructures.Graph`. Network remains available as an alias of Graph, but Graph is preferred.

  • The standalone functions were replaced by methods.

    COMPAS 1.x

    COMPAS 2.x

    mesh_weld(mesh)

    mesh.weld()

    meshes_join(meshes)

    Mesh.join(meshes)

    mesh_offset(mesh, d)

    mesh.offset(d)

    mesh_thicken(mesh, t)

    mesh.thickened(t)

    mesh_transform(mesh, T)

    mesh.transform(T)

    mesh_quads_to_triangles(mesh)

    mesh.quads_to_triangles()

    mesh_unify_cycles(mesh)

    mesh.unify_cycles()

    mesh_bounding_box(mesh)

    mesh.aabb()

    mesh_explode(mesh)

    mesh.exploded()

    network_shortest_path(network, u, v)

    graph.shortest_path(u, v)

    network_adjacency_matrix(network)

    graph.adjacency_matrix()

  • Edges are identified by a single identifier instead of by two separate vertices.

    # COMPAS 1.x
    mesh.edge_length(u, v)
    
    # COMPAS 2.x
    mesh.edge_length((u, v))

    This applies to all edge based methods, among others edge_faces, halfedge_face, halfedge_after, halfedge_before, edge_point, edge_midpoint, edge_vector, split_edge, and collapse_edge.

  • Methods returning geometry now return COMPAS geometry objects instead of tuples: vertex_normal, vertex_laplacian, neighborhood_centroid, edge_vector, edge_direction, edge_point, edge_midpoint, face_normal, face_centroid, face_center, and face_plane.

  • key_index and index_key were replaced by vertex_index/index_vertex, node_index/index_node, and edge_index/index_edge.

  • mesh.subdivide() was renamed to mesh.subdivided().

  • :class:`compas.datastructures.Datastructure` provides transform(ed), translate(d), rotate(d), and scale(d).

  • :class:`compas.datastructures.Tree`, :class:`compas.datastructures.TreeNode`, and :class:`compas.datastructures.CellNetwork` were added.

Tolerance and precision

compas.PRECISION and compas.set_precision were replaced by :class:`compas.tolerance.Tolerance` and its singleton instance TOL.

# COMPAS 1.x
import compas
from compas.utilities import geometric_key

compas.set_precision(3)
key = geometric_key(point)
# COMPAS 2.x
from compas.tolerance import TOL

TOL.precision = 3
key = TOL.geometric_key(point)

TOL exposes absolute, relative, angular, approximation, precision, and lineardeflection, together with comparison helpers such as is_zero, is_close, is_allclose, and formatting helpers such as format_number. See :doc:`advanced.tolerance` for more information.

Note that __str__ of :class:`compas.geometry.Point` and :class:`compas.geometry.Vector` uses a limited number of decimals (based on TOL.precision), whereas __repr__ maintains full precision.

Packages that moved out of the core

COMPAS 1.x COMPAS 2.x
compas.robots compas_robots (including the URDF parser, previously in compas.files)
compas.numerical.fd_numpy compas_fd
compas.numerical.dr, compas.numerical.dr_numpy compas_dr
compas.numerical.topop_numpy compas_topopt
compas.numerical.pca_numpy compas.geometry.pca_numpy
compas.numerical.scalarfield_contours compas.geometry.scalarfield_contours
compas.numerical.mma, lma, ga, devo, descent removed
compas.brep compas.geometry.brep
compas.utilities.itertools compas.itertools
compas_rhino.forms removed
compas.rpc.XFunc removed

The CAD packages were flattened as well: compas_rhino.utilities.objects became compas_rhino.objects, compas_rhino.utilities.layers became compas_rhino.layers, and the drawing modules of compas_rhino, compas_ghpython, and compas_blender moved out of their respective utilities subpackages. compas_ghpython.utilities was removed entirely in 2.5.

Geometry

  • compas.geometry.Primitive was removed. :class:`compas.geometry.Arc`, :class:`compas.geometry.Bezier`, :class:`compas.geometry.Circle`, :class:`compas.geometry.Ellipse`, :class:`compas.geometry.Line`, and :class:`compas.geometry.Polyline` are derived from :class:`compas.geometry.Curve`, and :class:`compas.geometry.Transformation` is derived from :class:`compas.data.Data`.
  • Analytical surfaces were added: :class:`compas.geometry.PlanarSurface`, :class:`compas.geometry.CylindricalSurface`, :class:`compas.geometry.SphericalSurface`, :class:`compas.geometry.ConicalSurface`, and :class:`compas.geometry.ToroidalSurface`, as well as the curves :class:`compas.geometry.Hyperbola` and :class:`compas.geometry.Parabola`.
  • NurbsSurface.u_space and v_space became space_u and space_v, and u_isocurve and v_isocurve became isocurve_u and isocurve_v.
  • Brep.from_step_file was renamed to Brep.from_step, and the signature of Brep.slice changed.
  • The X and Y axis are optional in the constructor of :class:`compas.geometry.Frame`.
  • Indexed attribute access was removed from all geometry classes except Point, Vector, Line, Polygon, and Polyline.
  • The conversion classes of compas_rhino.conversions were replaced by functions, for example mesh_to_rhino, mesh_to_compas, box_to_rhino, curve_to_compas.

Other things to watch out for

  • :func:`compas.geometry.oriented_bounding_box_numpy` minimizes volume, which means results can differ from COMPAS 1.
  • Graph.delete_edge no longer deletes the edge in the opposite direction.
  • :func:`compas.geometry.earclip_polygon` was reimplemented, because the previous implementation did not handle all cases.
  • is_planar relies on NetworkX (>=3.0) instead of on planarity.
  • __all__ was removed beyond the second level of the package, so deep imports of previously re-exported names may need to be updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment