inv
Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.
Syntax
Description
Examples
Inverse of Quantum Circuit
Create a quantum circuit that consists of 3 quantum gates.
gates = [hGate(1); sGate(2); rxGate(1,pi/3)]; c = quantumCircuit(gates);
Find the inverse of the quantum circuit. Show the gate operations of the original circuit and the inverted gate operations of the inverse circuit.
cinv = inv(c); c.Gates
ans = 3×1 SimpleGate array with gates: Id Gate Control Target Angle 1 h 1 2 s 2 3 rx 1 pi/3
cinv.Gates
ans = 3×1 SimpleGate array with gates: Id Gate Control Target Angle 1 rx 1 -pi/3 2 si 2 3 h 1
Here, hGate
is its own inverse, siGate
is the
inverse of sGate
, and the rotation angle of rxGate
has changed sign to rotate backwards.
Inverse of Rotation Gate
Construct a y-axis rotation gate with a rotation angle of π/2.
g = ryGate(1,pi/2)
g = SimpleGate with properties: Type: "ry" ControlQubits: [1×0 double] TargetQubits: 1 Angles: 1.5708
Find the inverse of the rotation gate.
ginv = inv(g)
ginv = SimpleGate with properties: Type: "ry" ControlQubits: [1×0 double] TargetQubits: 1 Angles: -1.5708
Inverse of Composite Quantum Gate
Construct a composite gate that consists of two inner gates.
gates = [hGate(1); cxGate(1,2)]; cg = compositeGate(gates,[1 2]);
Find the inverse of the composite gate. Show the gate operations of the original composite gate and the inverted gate operations of the inverse composite gate.
cginv = inv(cg); cg.Gates
ans = 2×1 SimpleGate array with gates: Id Gate Control Target 1 h 1 2 cx 1 2
cginv.Gates
ans = 2×1 SimpleGate array with gates: Id Gate Control Target 1 cx 1 2 2 h 1
Create a quantum circuit that consists of the composite gate and its inverse. Show that the operations of these gates cancel each other out and the matrix representation of this circuit is an identity matrix.
c = quantumCircuit([cg; cginv]); M = getMatrix(c)
M = 1.0000 0 0 0 0 1.0000 0 0 0 0 1.0000 0 0 0 0 1.0000
Input Arguments
c
— Quantum circuit or gate
quantumCircuit
object | SimpleGate
object | CompositeGate
object
Quantum circuit or gate, specified as a quantumCircuit
,
SimpleGate
, or CompositeGate
object.
If
c
is aquantumCircuit
orCompositeGate
object, theninv
reverses the order of the original gates inc
and replaces each gate with its inverse.If
c
is aSimpleGate
object, theninv
replaces the gate with its inverse.
Version History
Introduced in R2023a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)