# A Graph-Based Approach for Modelling Quantum Circuits
## 5 Supporting Tools and Model Transformations
### Transformation to Reduce the Number of Modelling Elements  
The modelling resources needed by each strategy in the case of the sample quantum circuit that solves the riddle described in Section 4.3 are summarised in Table 1. Please note that the number of Qubits and QuantumGates required are the same in all cases, four qubits and sixteen gates, since these are the number of quantum elements that appear in (the first half of) the quantum circuit that solves the riddle. Thus, the total number of 'additional' elements needed to be able to model the quantum circuit can be seen as the overload that a particular modelling strategy adds to the model. As shown in the table, the strategy that models the vertical sections of the circuit, entitled \"slice\", is the most efficient in this respect. It drastically reduces the number of additional modelling elements needed at the cost of losing expressiveness, since the models will be just a line with Nodes that have a complex internal structure. The formulas listed in Table 2 can be used to calculate the number of additional modelling elements required by each strategy. \begin{table}
\begin{tabular}{c c c c c c} \hline  & **Swim-Lane** & **Mixed Swim-Lane** & **Linear** & **Slice** & **Mixed Linear** \\ \hline Nodes & 17 & 13 & 17 & 7 & 13 \\ Edges & 16 & 16 & 16 & 6 & 12 \\ \hline Total & 33 & 29 & 33 & 13 & 25 \\ Overload & 165\% & 145\% & 165\% & 65\% & 125\% \\ \hline \end{tabular}
\end{table} 
Table 1: Some statistics on the number of modelling elements required to model (half of) the quantum circuit for solving the example riddle. where  
\(l:\) longest path of circuit  
\(q:\) number of qubits  
\(g:\) number of QuantumGates elements  
\(se:\) nodes that mark the start or end of the graph, with value \(\{0,1,2\}\)  
\(cg_{x}:\) number of QuantumGates controlled by '\(x\)' qubits  
\[C:\text{total number of controlled gates},\sum_{x=1}cg_{x}\]  
It is indeed possible to reduce the number of modelling elements needed in order to model a quantum circuit by realising that there is generally a horizontal flow of control imposed by qubits and that the order established by the Edges can be also obtained by using a queue (first-in first-out) as the type of collection employed to store just the Nodes. Particularly, this is the default collection type employed in EMF for containment relationships. This optimization reduces to almost one half the number of additional modelling elements required to model a given quantum circuit. This is the purpose of the containment relationship coloured in red between Qubit and Node in the metamodel shown in Figure 2.  
It is worth noting that only the strategy \"mixed swim-lane\" cannot take advantage of this optimization given that Nodes can contain any number of QuantumGates that act on any number of Qubits. This is no surprise since this strategy is the most flexible one. Models employing it should be transformed into models that employ any of the other strategies, for instance the strategy \"swim-lane\" by executing the transformation described at the end of the previous section, in order to obtain a model that can seize this reduction in the number of modelling elements. The Epsilon model transformation available at the GitHub repository, outlined in Algorithm 2, demonstrates this option for the \"linear\" strategy.