{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# COLLADA Interoperability\n", "\n", "This notebook demonstrates how to interoperate `tqec` with [COLLADA](https://en.wikipedia.org/wiki/COLLADA)(`.dae`) files. COLLADA files can be imported/exported to/from [SketchUp](https://www.sketchup.com/), which is a common used 3D modeling tool in QEC paper.\n", "\n", "`tqec` relies on [PyCollada](https://github.com/pycollada/pycollada) under the hood to realize the interoperability with COLLADA files." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import COLLADA model\n", "\n", "A common workflow starting from SketchUp is:\n", "\n", "1. Open the [template file](https://github.com/QCHackers/tqec/blob/main/assets/template.skp) in SketchUp.\n", "2. Construct the model representing the logical computation.\n", "3. Export the model as a COLLADA(`.dae`) file from SketchUp.\n", "4. Import the COLLADA file to `tqec` as a `BlockGraph`, which can be compiled to circuits.\n", "\n", "`tqec` provides the function `tqec.interop.read_block_graph_from_dae_file` to import a COLLADA file as a `BlockGraph`. Or you can call `BlockGraph.from_dae_file` directly." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tqec import BlockGraph\n", "\n", "graph = BlockGraph.from_dae_file(\"../media/user_guide/logical_cnot.dae\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Export COLLADA model\n", "\n", "If you start with building the logical computation in `tqec` and build a `BlockGraph`, you can export the `BlockGraph` to a COLLADA file by calling `BlockGraph.to_dae_file`." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "graph.to_dae_file(\"logical_cnot.dae\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display COLLADA model\n", "\n", "`tqec` provides the function `tqec.interop.display_collada_model` to view the COLLADA model as html and render it with [three.js](https://threejs.org/). It can be used in IPython environment to display and play with the model interactively. You can also call `BlockGraph.view_as_html` directly to first convert it to a COLLADA model then display it." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "graph.view_as_html()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Additionally, you can attach the correlation surface to the model to visualize what the logical observable looks like:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "correlation_surfaces = graph.find_correlation_surfaces()\n", "graph.view_as_html(\n", " pop_faces_at_direction=\"-Y\",\n", " show_correlation_surface=correlation_surfaces[0],\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 }