DVLab-NTU / qsyn

A C++-based growing software system for synthesizing, optimizing, and verifying quantum circuits
Apache License 2.0
168 stars 15 forks source link

QCir Refactor #82

Open JoshuaLau0220 opened 8 months ago

JoshuaLau0220 commented 8 months ago

The Problem

Currently, the qcir package is hard to use mainly because it fails to account for the variability of different types of gates. For example, we can’t model a matrix or a boolean oracle to a gate;

Also, some gates expose inappropriate interfaces; the SWAP gate---currently implemented through a GateRotationCategory of swap---exposes get_phase(), and before a previous refactoring, a T gate exposes set_phase()---which causes problems in identifying gate type.

Comparing with Qiskit’s Abstraction

Qiskit’s

I’ve investigated how Qiskit structures their qk.QuantumCircuit. Roughly speaking, their abstraction is as follows:

A QuantumCircuit contains a list of CircuitInstructions.

A CircuitInstruction is composed of an Operation and its operands. For example, a cx q[0], q[1]; instruction is composed of the operation cx and operand q[0], q[1];

An Operation can be a quantum gate, measurements, barriers, etc.

Note that in the above, none of the above hierarchy maintains the gate connectivity explicitly because QuantumCircuit always sorts its CircuitInstruction in the topological order. Qiskit also has another class called DAGCircuit for applications that require further knowledge of the connections.

Ours

Currently, our abstraction is as follows:

A QCir contains a list of QCirGates.

A QCirGate is an instruction and knows its connection to the predecessors/successors.

A GateType represents a quantum gate and is a helper class in instantiating QCirGate. Note that each QCirGate does not own a GateType but takes the latter’s information into the former’s members.

The Remedy

I propose to

More specifically, here’s a plan of how we would achieve that: