How to use the “compose” function in Qiskit

The “compose” function is used to join two circuits q_1 and q_2.

Let qc_1:

And qc_2:

To join 1 and 2, just use the following code:

qc = qc_1.compose(qc_2)

An alternative method, already deprecated, is to use the summation:

qc = qc_1 + qc_2

Compose has the advantage of being more general. It is possible to change the “wiring” of the circuit:

qc = qc_1.compose(qc_2, qubits =[0,2,1,3])

It is also possible to join a circuit with fewer qubits to a circuit with more qubits, indicating how they are wired together. If it is the opposite, joining a circuit with more qubits to another one with less, will give an error — the trick is to invert the composition of the circuit and use the option Front = True.

Qiskit Documentation:

https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.html#qiskit.circuit.QuantumCircuit.compose

Example code:

https://github.com/asgunzi/qiskit_compose

--

--

--

Arnaldo Gunzi notes on Quantum Computing and Information

Recommended from Medium

42 Free Reports on Salesforce User Adoption (with no configuration or coding!)

Software testing feels like a big waste of time

Strategic Barricades for Software Development

Enterprise Budgeting — Every CFO’s Success Formula in Cloud

Moving from NodeJS to Rust in 2019

AWS Certified Solutions Architect — Associate

Asserts With Flow Annotations in PHP7

Creating CLI In Go With Cobra

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arnaldo Gunzi

Arnaldo Gunzi

Project Manager on Analytics and Innovation. “Samurai of Analytics”. Passionate about Combinatorial Optimization, Philosophy and Quantum Computing.

More from Medium

RECENT TRENDS IN QUANTUM COMPUTING

Overview of IBM Quantum Challenge Fall 2021

Multiple Qubits and Circuits Part-1

Financial Analysis: The Quantum Era