# A Graph-Based Approach for Modelling Quantum Circuits

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Related Work

## 3. Background on the Unitary Circuit Model

## 4. Modelling the Unitary Circuit Model of Quantum Computation

#### 4.1. A Unified Metamodel for the Unitary Circuit Model

`Qubit`and

`Control`gate) and in grey (abstract base meta-class

`QuantumGate`). The control gate allows the creation of multi-qubit gates, which are needed to entangle qubits.

`QuantumGate`) to add all the gates available in the general unitary quantum circuit model. For the sake of simplicity, only two gates, which are needed to model the example quantum circuit described below, have been added to the metamodel (coloured in green):

`H`(the Hadamard gate, to create superposition) and

`X`(the NOT gate). This version is sufficient for the purposes of this paper. The containment relationship between

`Qubit`and

`QuantumGate`, coloured in red in Figure 2, will be justified in Section 5.3 and can be ignored for now.

`Control`gates as needed and set their controlGate property to the gate they control.

#### 4.2. Supported Modelling Strategies

`Node`meta-class is the key to the modelling capabilities offered by the metamodel. Given its ability to have an internal structure, it can store any number of

`QuantumGate`s, each acting over a

`Qubit`. It is therefore the way to logically group together all the gates that define a multi-qubit gate where needed. The metamodel allows the use of at least five modelling strategies, depending on the type of DAG being created (a line or a general DAG) and the way in which the

`Node`meta-class is used. Graphical representations of these strategies are shown in the following section. It may help the reader to examine them to gain a better idea of each of the strategies described below:

- Strategy “swim-lane”:
`Node`s contain exactly one`QuantumGate`and the graph is organised as a set of lines that link the`Node`s that contain gates operating over the same qubit. In the literature, the work [17] fits this strategy, as it defines a profile for the UML activity diagram. - Strategy “linear”: similar to the previous one, but the graph is now organised as a line that preserves the relative order of execution of the gates contained in the
`Node`s. To the best of our knowledge, no work in the literature follows this strategy. - Strategy “slice”:
`Node`s contain all the`QuantumGate`s involved in a vertical slice of the quantum circuit (hence the name of the strategy), and the graph is organised as a line. The work described in [9] fits this strategy. - Strategy “mixed swim-lane”:
`Node`s contain only one logical operation, be it a single`QuantumGate`operating on one qubit or all the`QuantumGate`s corresponding to a multi-qubit gate. The graph is organised as a set of lines connecting the`Node`s that contain gates operating over the same qubit. As for this strategy, no work in the literature conforms to it. - Strategy “mixed linear”: like the previous one, but now the graph is organised as in the strategy “linear”. To our knowledge, no work in the literature corresponds to it.

`Node`provides the developer with the necessary flexibility to decide whether she/he wants to model the quantum circuit using only the gates that operate on a qubit, or to group in a

`Node`all the gates that model a controlled gate, or in the most extreme case, all the gates that appear in a particular vertical section of the circuit.

#### 4.3. Example Application

`Edge`s of the metamodel but rather a visual aid added in the figures to better display the relationships that exist among controlled gates in the graph representation of the quantum circuit. Ellipses represent

`Node`s that contain just one gate, while circles with horizontal lines represent

`Node`s that contain more than one gate.

`〈vertical〉:〈gate〉(〈qubit〉)`” for single qubit gates, or “

`〈vertical〉:c(〈qubit〉,〈controlledQubit〉)`” for control gates. The label inside a circle has as many letters as qubits in the circuit, where the symbol ‘−’ indicates that no gate acts on that qubit, according to the order in which the letters are written. This notation has only an illustrative purpose, to make it easier to identify the correspondence between the nodes of the graph and the gates of the quantum circuit. It should be highlighted that the two “linear” graphs in the figure show one of the possible orderings of such graphs. Specifically, the one in which the quantum circuit is represented from top to bottom.

#### 4.4. Completing the Metamodel with OCL Constraints

`Edge`to self is allowed, no

`Node`can remain without at least one incoming/outgoing

`Edge`, no two

`Edge`s can have the same source and destination

`Node`), we define the following specific constraints, shown in Listing 1, tailored to the particularities of quantum circuits. It is worth highlighting that the constraints listed below are independent of the modelling strategy used in the model:

- All
`QuantumGate`s contained in a`Node`should operate on different`Qubits`. The OCL constraint`GatesOperateOnDifferentQubits`checks this. - The
`Qubit`on which a`Control`gate operates must be different from the`Qubit`on which the controlled`QuantumGate`operates. Checked by`OperatesOnADifferentQubitThanControlledGate`OCL constraint. - A
`Control`gate cannot control another`Control`gate. Multi-controlled gates, such as the Toffoli gate, can be modelled by having each individual`Control`gate point to the gate it controls, instead of pointing to the next`Control`gate in the chain. The main drawback of this last modelling choice is that you could create models where`Control`gates just control other`Control`gates, potentially creating loops which will make it even harder to detect. The OCL constraint`CannotControlAnotherControlGate`checks it. - If a
`Node`contains more than one gate, then all the`Control`gates within it must control gates also contained on that node. From the point of view of model well-formedness, this constraint is not necessary, but has been added to ensure some logical order in the structure. The OCL constraint`AllControlSameNode`checks it.

Listing 1. OCL constraints to check model validity. |

- A model that has
`Edge`s and in which at least one`Qubit`contains gates is not valid. The OCL constraint`Edges_QubitsContainGates`checks it. - At least one of the collections
`Circuit.edges`,`Circuit.nodes`or`Qubit.gates`must contain elements. This means that not all of these collections can be empty. The OCL constraint`NotAllCollectionsEmpty`checks it.

## 5. Supporting Tools and Model Transformations

#### 5.1. Identification of the Strategy Followed in a Model

`kindOfStrategy`, defined in Listing 2. This operation is needed to avoid mixing strategies in the same model, as this can confuse the users of the model and hinder the development of further tools. Also, some tools in the toolchain may require that the input models follow a particular strategy.

Listing 2. OCL query operation that detects the kind of strategy employed in a model. |

`Edge`s to/from a

`Node`is 2. In this case, if at least one

`Node`contains more than one gate that is not a

`Control`gate, then the model follows the strategy “slice”. If not, but at least one

`Node`contains more than one gate, then it follows the strategy “mixed linear”. Otherwise, it follows the strategy “linear”. In the case of the strategies “swim-lane” and “mixed swim-lane”,

`Node`s can be the source or destination of more than one

`Edge`, but at least one

`Node`contains more than one gate in the case of the “mixed swim-lane” strategy. This is not the case for the strategy “swim-lane”.

#### 5.2. Transformation between the Modelling Strategies

- The strategies “swim-lane” and “mixed swim-lane” are basically the same, except that the second one groups together in a single
`Node`all the gates involved in a multi-qubit operation. Therefore, the transformation between both strategies relies on grouping and ungrouping the multi-qubit gates and adding or removing`Edge`s connecting gates operating on the same qubit as needed. The correspondence between the two strategies is 1-to-1. - The “slice” strategy can be transformed into/from either the “swim-lane” or “mixed swim-lane” ones by realising that a given slice (
`Node`) contains gates operating over different qubits. Thus, it is possible to generate the “swim-lane” version by creating`Node`s containing only one gate and creating`Edge`s connecting the`Node`s containing gates operating over the same`Qubit`, in the order defined by the input circuit. The same procedure applies to generating a model that follows the “mixed” strategy but, in this case, controlled gates must be stored in the same`Node`. Again, the correspondence between these strategies is 1-to-1. - The strategies “linear” and “mixed linear” are the most flexible ones in the sense that the same quantum circuit can be modelled by several such graphs, simply by changing the relative order of the
`Node`s in the line, with the only restriction that if two`Node`s contain gates that operate on the same qubit, they cannot be interchanged. As in the first case, the transformation between both strategies relies on grouping and ungrouping the multi-qubit gates contained in`Node`s, according to the target strategy. When transforming between strategies “linear” and “swim-lane”, the transformation only has to reconFigure`Edge`s according to the`Qubit`the`Node`s (the`QuantumGate`contained in the`Node`, to be precise) they link operate over. The transformation from “mixed linear” to “swim-lane” also requires that the gates contained in`Node`s must be ungrouped or grouped, respectively, and as described above, depending on the direction of the transformation. For the strategies “slice” and “mixed”, the transformation must first rearrange the gates in`Node`s according to the chosen strategy, remove the ones that remain empty, and then link the`Node`s as described in the previous sentence. In any case, given the flexibility of these strategies regarding the order of the`Node`s in the graph, the correspondence with the other strategies is n-to-1.

`Node`s and

`Edge`s, as outlined above, which must be handled carefully to properly transform nodes containing only one quantum gate and nodes containing more than one, while considering the edges entering and exiting them. Algorithm 1 provides a more complete yet succinct description of this transformation.

Algorithm 1 Transformation from strategy “mixed swim-lane” to “swim-lane”. |

// ⟹ means “transformed into” |

// ← means “store the element/s generated for the RHS on the LHS” |

// The values of the attributes/properties not specified in the transformation |

// are just copied from the input model to the output one |

f:In!Qubit ⟹ t:Out!Qubit |

f:In!H ⟹ t:Out!H |

f:In!X ⟹ t:Out!X |

f:In!Control ⟹ tn:Out!Node, tc:Out!Control |

tn.gates = tc |

f:In!Node / f.gates.size()≤1 ⟹ t:Out!Node |

t.gates ← f.gates |

f:In!Node / f.gates.size()>1 ⟹ t:Out!Node |

t.gates ← (f.gates–> selectOne (g | not g.isTypeOf(In!Control))) |

f:In!Edge(not (f.src.gates.size()>1 and f.dst.gates.size()>1))) ⟹ t:Out!Edge |

set t.src and t.dst so that the gate contained in each node operates on |

the same qubit |

f:In!Edge(f.src.gates.size()>1 and f.dst.gates.size()>1)) ⟹ t:Out!Edge* |

create as many Out!Edge as needed to link Out!Nodes created from |

composite In!Nodes |

f:In!Circuit ⟹ t:Out!Circuit |

t.qubits ← f.qubits |

t.nodes ← f.nodes |

t.nodes ← In!Control.allInstances() |

t.edges ← f.edges |

#### 5.3. Transformation to Reduce the Number of Modelling Elements

`Qubit`s and

`QuantumGate`s 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

`Node`s 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.

`Edge`s can be also obtained by using a queue (first-in first-out) as the type of collection employed to store just the

`Node`s. 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.

`Node`s can contain any number of

`QuantumGate`s that act on any number of

`Qubit`s. 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.

Algorithm 2 Reduction of model elements for the “linear” strategy. |

// ⟹ means “transformed into” |

// ← means “store the element/s generated for the RHS on the LHS” |

// The values of the attributes/properties not specified in the transformation |

// are just copied from the input model to the output one |

f:In!Qubit ⟹ t:Out!Qubit |

f:In!H ⟹ t:Out!H |

f:In!X ⟹ t:Out!X |

f:In!Control ⟹ t:Out!Control |

f:In!Node ⟹ t:Out!Node |

t.gates ← f.gates |

f:In!Circuit ⟹ t:Out!Circuit |

t.qubits ← f.qubits |

t.nodes ← f.nodes in the order specified by Edges, starting from a |

Node that has no incoming Edge |

`Qubit`s contain nothing.

#### 5.4. Detecting if a Model Has Been Reduced

`Edge`s. The OCL query operation

`whichReducedStrategy`, shown in Listing 3, serves this purpose.

Listing 3. OCL query operation that detects if the transformation that reduces the number of
modelling elements has been applied to a model. |

`Qubit`s do not contain gates, but rather all the gates are contained in

`Node`s contained themselves in the

`Circuit`. In this case, if at least one

`Node`contains more than one gate that is not a

`Control`gate, then the model follows the strategy “slice”. If not, but at least one

`Node`contains more than one gate, then it follows the strategy “mixed linear”. Otherwise, the model follows the strategy “linear”. If

`Qubit`s in the model contain gates, then the model follows the “swim-lane” strategy. Please keep in mind that the reduction transformation cannot be applied to a model that follows the “mixed swim-lane” strategy. In this case, the OCL query operation returns 0 (no reduction has been applied).

## 6. Evaluation of the Proposal

#### 6.1. Ease of Model Manipulation

`QuantumGate`or

`Qubit`in its correct place and how easy it is to restore the model to a valid and correct state after deleting such an element.

`Node`s are the preferred ones because in them it is easy to establish a correspondence between the quantum circuit and the elements of the model, and therefore it is easy to identify where to add the new element or how to restore the model to a valid state. Among them, “mixed swim-lane” is preferred over the other two because the circuit structure is better represented than in the “mixed linear” strategy and because changes only require updating

`Edge`s, whereas in the “slice” strategy the user may have to move gates to different

`Node`s to rearrange the model to represent the quantum circuit. Then come the “swim-lane” and “linear” strategies, because there is no horizontal structure in “linear” that can help the user to perform the operations.

`Edge`s give the user freedom to place

`Node`s in any order. Nevertheless, with the appropriate support from editors, it can be useful and even easier for the user to manipulate models in this reduced form.

#### 6.2. Ease of Implementation of Model-to-Model Transformations

`Edge`s may still be useful for other transformations down the toolchain. It is also possible that there are transformations that require the presence of

`Edge`s in order to be properly defined.

#### 6.3. Ease of Implementation of Model-to-Text Transformations

`Control`gates in the model to find them).

`Edge`s, which are no longer needed because model-to-text transformations are usually the last to be performed in a model-driven development framework.

#### 6.4. On the Role of Domain-Specific Languages

#### 6.5. Integration in a Hybrid Classical–Quantum Development Environment

#### 6.6. Application to Other Quantum Computing Models

## 7. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Conflicts of Interest

## Abbreviations

QC | Quantum Computing |

OCL | Object Constraint Language |

UML | Unified Modelling Language |

MDE | Model-Driven Engineering |

MOF | Meta-Object Facility |

DAG | Direct Acyclic Graph |

DSL | Domain Specific Language |

KDM | Knowledge Discovery Metamodel |

## Appendix A

`X,Y,Z`, phase

`P`,

`Swap`, generic

`U`gate and

`Measurement`. For the latter, the class

`Cbit`has been included, which represents a classical bit to store the measurement result of a qubit. All new quantum gates have been added as extensions of the abstract base class

`QuantumGate`. The inheritance relationship is shown in red. The same procedure would be used to add additional gates.

**Figure A1.**Extension to the metamodel shown in Figure 2 to better represent quantum circuits. The new classes added are shown in blue. The red lines represent the inheritance relationship.

## References

- Benioff, P. The computer as a physical system: A microscopic quantum mechanical Hamiltonian model of computers as represented by Turing machines. J. Stat. Phys.
**1980**, 22, 563–591. [Google Scholar] [CrossRef] - Feynman, R.P. Simulating physics with computers. Int. J. Theor. Phys.
**1982**, 21, 467–488. [Google Scholar] [CrossRef] - Shor, P.W. Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer (revised version of the original paper, published in 1994). SIAM Rev.
**1999**, 41, 303–332. [Google Scholar] [CrossRef] - Grover, L.K. A Fast Quantum Mechanical Algorithm for Database Search. In Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing, STOC ’96, New York, NY, USA, 22–24 May 1996; pp. 212–219. [Google Scholar] [CrossRef]
- Piattini, M.; Serrano, M.; Perez-Castillo, R.; Petersen, G.; Hevia, J.L. Toward a Quantum Software Engineering. IT Prof.
**2021**, 23, 62–66. [Google Scholar] [CrossRef] - Piattini, M.; Peterssen, G.; Pérez-Castillo, R. Quantum Computing: A New Software Engineering Golden Age. SIGSOFT Softw. Eng. Notes
**2020**, 45, 12–14. [Google Scholar] [CrossRef] - Nimbe, P.; Weyori, B.A.; Adekoya, A.F. Models in quantum computing: A systematic review. Quantum Inf. Process.
**2021**, 20, 80. [Google Scholar] [CrossRef] - Chi-Chih Yao, A. Quantum circuit complexity. In Proceedings of the 1993 IEEE 34th Annual Foundations of Computer Science, Palo Alto, CA, USA, 3–5 November 1993; pp. 352–361. [Google Scholar] [CrossRef]
- Alonso, D.; Sánchez, P.; Sánchez-Rubio, F. Engineering the Development of Quantum Programs: Application to the Boolean Satisfiability Problem. Adv. Eng. Softw.
**2022**, 173, 103216. [Google Scholar] [CrossRef] - Bézivin, J. On the unification power of models. Softw. Syst. Model.
**2005**, 4, 171–188. [Google Scholar] [CrossRef] - Atkinson, C.; Kühne, T. Model-driven development: A metamodeling foundation. IEEE Softw.
**2003**, 20, 36–41. [Google Scholar] [CrossRef] - Selic, B. The pragmatics of model-driven development. IEEE Softw.
**2003**, 20, 19–25. [Google Scholar] [CrossRef] - Rodrigues Da Silva, A. Model-driven engineering: A survey supported by the unified conceptual model. Comput. Lang. Syst. Struct.
**2015**, 43, 139–155. [Google Scholar] [CrossRef] - Kahani, N.; Bagherzadeh, M.; Cordy, J.R.; Dingel, J.; Varró, D. Survey and classification of model transformation tools. Softw. Syst. Model.
**2019**, 18, 2361–2397. [Google Scholar] [CrossRef] - Sendall, S.; Kozaczynski, W. Model transformation: The heart and soul of model-driven software development. IEEE Softw.
**2003**, 20, 42–45. [Google Scholar] [CrossRef] - Sánchez, P.; Alonso, D. On the Definition of Quantum Programming Modules. Appl. Sci.
**2021**, 11, 5843. [Google Scholar] [CrossRef] - Perez-Castillo, R.; Jimenez-Navajas, L.; Piattini, M. Modelling Quantum Circuits with UML. In Proceedings of the 2021 IEEE/ACM 2nd International Workshop on Quantum Software Engineering (Q-SE), IEEE Computer Society, Madrid, Spain, 1–2 June 2021; pp. 7–12. [Google Scholar] [CrossRef]
- Pérez-Delgado, C.A.; Perez-Gonzalez, H.G. Towards a Quantum Software Modeling Language. In Proceedings of the IEEE/ACM 42nd International Conference on Software Engineering Workshops, New York, NY, USA, 27 June 2020; pp. 442–444. [Google Scholar] [CrossRef]
- Ali, S.; Yue, T. Modeling Quantum Programs: Challenges, Initial Results, and Research Directions. In Proceedings of the 1st ACM SIGSOFT International Workshop on Architectures and Paradigms for Engineering Quantum Software, New York, NY, USA, 13 November 2020; pp. 14–21. [Google Scholar] [CrossRef]
- Moin, A.; Challenger, M.; Badii, A.; Günnemann, S. Towards Model-Driven Engineering for Quantum AI. In INFORMATIK 2022; Gesellschaft für Informatik: Bonn, Germany, 2022; pp. 1121–1131. [Google Scholar] [CrossRef]
- Pérez-Castillo, R.; Piattini, M. Design of classical-quantum systems with UML. Computing
**2022**, 104, 2375–2403. [Google Scholar] [CrossRef] - De Stefano, M.; Pecorelli, F.; Di Nucci, D.; Palomba, F.; De Lucia, A. Software engineering for quantum programming: How far are we? J. Syst. Softw.
**2022**, 190, 111326. [Google Scholar] [CrossRef] - Killoran, N.; Izaac, J.; Quesada, N.; Bergholm, V.; Amy, M.; Weedbrook, C. Strawberry Fields: A Software Platform for Photonic Quantum Computing. Quantum
**2019**, 3, 129. [Google Scholar] [CrossRef] - Pfister, O. Continuous-variable quantum computing in the quantum optical frequency comb. J. Phys. B At. Mol. Opt. Phys.
**2019**, 53, 012001. [Google Scholar] [CrossRef] - Barenco, A.; Bennett, C.H.; Cleve, R.; DiVincenzo, D.P.; Margolus, N.; Shor, P.; Sleator, T.; Smolin, J.A.; Weinfurter, H. Elementary gates for quantum computation. Phys. Rev. A
**1995**, 52, 3457–3467. [Google Scholar] [CrossRef] [PubMed] - Penrose, R. Applications of negative dimensional tensors. In Proceedings of the Conference on Combinatorial Mathematics and its Applications, Oxford, UK, 7–10 July 1971. [Google Scholar]
- Giovannetti, V.; Lloyd, S.; Maccone, L. Quantum Random Access Memory. Phys. Rev. Lett.
**2008**, 100, 160501. [Google Scholar] [CrossRef] - Arunachalam, S.; Gheorghiu, V.; Jochym-O’Connor, T.; Mosca, M.; Srinivasan, P.V. On the robustness of bucket brigade quantum RAM. New J. Phys.
**2015**, 17, 123010. [Google Scholar] [CrossRef] - Zidan, M.; Abdel-Aty, A.H.; Khalil, A.; Abdel-Aty, M.; Eleuch, H. A Novel Efficient Quantum Random Access Memory. IEEE Access
**2021**, 9, 151775–151780. [Google Scholar] [CrossRef] - Object Management Group, Inc. Object Constraint Language (OCL) v. 2.4; Object Management Group Headquarters: Needham, MA, USA, 2014; Available online: https://www.omg.org/spec/OCL (accessed on 22 October 2023).
- Kolovos, D.; Paige, R.; Polack, F. The Epsilon Transformation Language. In Proceedings of the Theory and Practice of Model Transformations Conference, ICMT 2008, Zürich, Switzerland, 1–2 July 2008; Lecture Notes in Computer Science. Springer: Berlin, Germany, 2008; Volume 5063, pp. 46–60. [Google Scholar] [CrossRef]
- Ma, H.; Shao, W.; Zhang, L.; Ma, Z.; Jiang, Y. Applying OO Metrics to Assess UML Meta-models. In Proceedings of the UML 2004—The Unified Modeling Language. Modeling Languages and Applications, Lisbon, Portugal, 11–15 October 2004; Springer: Berlin/Heidelberg, Germany, 2004; pp. 12–26. [Google Scholar]
- Strahonja, V. The Evaluation Criteria of Workflow Metamodels. In Proceedings of the 2007 29th International Conference on Information Technology Interfaces, Dubrovnik, Croatia, 25–28 June 2007; pp. 553–558. [Google Scholar] [CrossRef]
- Zhiyi, M.; Xiao, H.; Chao, L. Assessing the quality of metamodels. Fron. Comp. Sci.
**2013**, 7, 558. [Google Scholar] [CrossRef] - Treinish, M. Qiskit: An Open-Source Framework for Quantum Computing; Zenodo: Geneva, Switzerland, 2021. [Google Scholar] [CrossRef]
- Object Management Group, Inc. Knowledge Discovery Metamodel (KDM) v. 1.4; Object Management Group Headquarters: Needham, MA, USA, 2016; Available online: https://www.omg.org/spec/KDM (accessed on 22 October 2023).
- Abhijith, J.; Adedoyin, A.; Ambrosiano, J.; Anisimov, P.; Casper, W.; Chennupati, G.; Coffrin, C.; Djidjev, H.; Gunter, D.; Karra, S.; et al. Quantum Algorithm Implementations for Beginners. ACM Trans. Quantum Comput.
**2022**, 3, 1–92. [Google Scholar] [CrossRef] - Yetiş, H.; Karaköse, M. An improved and cost reduced quantum circuit generator approach for image encoding applications. Quantum Inf. Process.
**2022**, 21, 203. [Google Scholar] [CrossRef] - McCaskey, A.; Dumitrescu, E.; Liakh, D.; Chen, M.; Feng, W.; Humble, T. A language and hardware independent approach to quantum–classical computing. SoftwareX
**2018**, 7, 245–254. [Google Scholar] [CrossRef] - Zidan, M. A novel quantum computing model based on entanglement degree. Mod. Phys. Lett. B
**2020**, 34, 2050401. [Google Scholar] [CrossRef] - Kitaev, A. Fault-tolerant quantum computation by anyons. Ann. Phys.
**2003**, 303, 2–30. [Google Scholar] [CrossRef] - Santoro, G.E.; Tosatti, E. Optimization using quantum mechanics: Quantum annealing through adiabatic evolution. J. Phys. A Math. Gen.
**2006**, 39, R393. [Google Scholar] [CrossRef]

**Figure 1.**Two equivalent quantum circuits that include the Hadamard, NOT, Z, Control-NOT, and Toffoli gates. Only the relative placement of quantum gates and the dependencies in the order of execution created by multi-qubit gates (Control-NOT and Toffoli gates) are important.

**Figure 2.**Metamodel for quantum software following the quantum circuit model that can accommodate at least five modelling strategies. The diagram uses the UML class diagram notation, where the cardinality between meta-classes is given with minimum and maximum values (* means ’unbounded’). An extended version of this metamodel is shown in Appendix A.

**Figure 4.**Graph representations that follow the five strategies for modelling the quantum circuit that solves the example riddle. Dashed lines represent the relationship between a control gate and the gate being controlled. They are not part of the metamodel but rather a visual aid added to better understand the graph representations.

**Table 1.**Some statistics on the number of modelling elements required to model (half of) the quantum circuit for solving the example riddle.

Swim-Lane | Mixed Swim-Lane | Linear | Slice | Mixed Linear | |
---|---|---|---|---|---|

Nodes | 17 | 13 | 17 | 7 | 13 |

Edges | 16 | 16 | 16 | 6 | 12 |

Total | 33 | 29 | 33 | 13 | 25 |

Overload | 165% | 145% | 165% | 65% | 125% |

**Table 2.**Formulas that determine the number of additional modelling elements required by each strategy.

Strategy | Nodes | Edges |
---|---|---|

Swim-lane | $g+se$ | $g-C-1+se\xb7q$ |

Mixed swim-lane | $g-C+se$ | $g-C-1+se\xb7q$ |

Linear | $g+se$ | $g-C-1+se\xb7q$ |

Slice | $l+se$ | $l+se-1$ |

Mixed linear | $g-C+se$ | $g-C-1+se$ |

**Table 3.**Summary of suitability of the strategies for performing operations related to modelling activities using a [−2,2] Likert scale. CM stands for ‘changes in models’, M2M for ‘model-to-model transformation’ and M2T for ‘model-to-text transformation’.

Strategy | CM | M2M | M2T |
---|---|---|---|

Slice | $+1$ | $+1$ | $+2$ |

Mixed swim-lane | $+2$ | $+2$ | $-1$ |

Swim-lane | $-1$ | $+1$ | $-2$ |

Linear | $-2$ | $-2$ | $+1$ |

Mixed linear | $+2$ | $-1$ | $+2$ |

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |

© 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Alonso, D.; Sánchez, P.; Álvarez, B.
A Graph-Based Approach for Modelling Quantum Circuits. *Appl. Sci.* **2023**, *13*, 11794.
https://doi.org/10.3390/app132111794

**AMA Style**

Alonso D, Sánchez P, Álvarez B.
A Graph-Based Approach for Modelling Quantum Circuits. *Applied Sciences*. 2023; 13(21):11794.
https://doi.org/10.3390/app132111794

**Chicago/Turabian Style**

Alonso, Diego, Pedro Sánchez, and Bárbara Álvarez.
2023. "A Graph-Based Approach for Modelling Quantum Circuits" *Applied Sciences* 13, no. 21: 11794.
https://doi.org/10.3390/app132111794