QuantumComputingIntro - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Toolboxes : Quantum Chemistry : Courses : Lessons : QuantumComputingIntro

Quantum Computing Fundamentals:

An Introduction

Copyright (c) RDMCHEM LLC 2025

 

 

Meet the Qubit

Gates

State Preparation

Measurement

Quantum Algorithm

References

Meet the Qubit

 

First, we load the QuantumChemistry package

> 

withQuantumChemistry;

AOIntegrals,AOLabels,ActiveSpaceCI,ActiveSpaceSCF,AtomicData,BondAngles,BondDistances,Charges,ChargesPlot,Chat,ContractedSchrodinger,CorrelationEnergy,CoupledCluster,DensityFunctional,DensityPlot3D,Dipole,DipolePlot,Energy,ExcitationEnergies,ExcitationSpectra,ExcitationSpectraPlot,ExcitedStateEnergies,ExcitedStateSpins,ExcitonDensityPlot,ExcitonPopulations,ExcitonPopulationsPlot,FullCI,GeometryOptimization,HartreeFock,Interactive,Isotopes,LiteratureSearch,LocalOrbitals,MOCoefficients,MODiagram,MOEnergies,MOIntegrals,MOOccupations,MOOccupationsPlot,MOSymmetries,MP2,MolecularData,MolecularDictionary,MolecularGeometry,NuclearEnergy,NuclearGradient,OscillatorStrengths,Parametric2RDM,PlotMolecule,Populations,Purify2RDM,QuantumComputing,RDM1,RDM2,RDMFunctional,RTM1,ReadXYZ,Restore,Save,SaveXYZ,SearchBasisSets,SearchFunctionals,SkeletalStructure,SolventDatabase,Thermodynamics,TransitionDipolePlot,TransitionDipoles,TransitionOrbitalPlot,TransitionOrbitals,Variational2RDM,VibrationalModeAnimation,VibrationalModes,Video

(1.1)

 

Second, we load the QuantumComputing subpackage

> 

withQuantumComputing;

ConvertDirac,Gate,InitialState,MeasureState,PrepareState,QubitPopulations,QubitPopulationsPlot

(1.2)

 

A classical bit has two states that are usually denoted as 0 and 1.  A quantum bit (or qubit) has two independent basis states 0 and 1, but also any linear combination of these two states.  To demonstrate, let's prepare a quantum state with one qubit in its 0 state

 

> 

state≔ InitialState1;

state≔Ψ0

(1.3)

 

We can apply a unitary transformation, known in quantum computing as a gate, to change the state of the qubit.  For example, we can excite (or flip) the qubit by using the Pauli-X gate

 

> 

Ux ≔ GateX;

Ux≔0110

(1.4)
> 

state ≔ PrepareState1=Ux,state;

state≔Ψ1

(1.5)

 

Or we can use the Hadamard gate to form a linear combination of the 0 and 1 states

 

> 

Uh ≔ GateH;

Uh≔222222−22

(1.6)
> 

state ≔ PrepareState1=Uh,state;

state≔2⁢Ψ02−2⁢Ψ12

(1.7)

 

In this state we have a 1/2 probability of being up and a 1/2 probability of being down.

 

Gates

 

In quantum computing unitary operators are known as gates.  For example, we have already seen a few 1-qubit gates such as the Pauli-X and Hadamard gates.  Other gates include the Pauli-Z gate  

 

> 

 Uz ≔ GateZ;

Uz≔100−1

(2.1)

 

which has no effect on the 0-qubit state

 

> 

state ≔ InitialState1;

state≔Ψ0

(2.2)

 

> 

PrepareState1=Uz, state;

Ψ0

(2.3)

 

or the Pauli Y gate

 

> 

Uy ≔ GateY;

Uy≔0−II0

(2.4)

 

which flips the qubit while introducing an imaginary phase

 

> 

PrepareState1=Uy, state;

I⁢Ψ1

(2.5)

 

or the most general 1-qubit gate, known as the U (universal) gate that depends on 3 angles that we keep symbolic

 

> 

 Uu ≔ GateU,theta=theta,phi=phi,lambda=lambda;

Uu≔cos⁡θ2−ⅇI⁢λ⁢sin⁡θ2ⅇI⁢φ⁢sin⁡θ2ⅇI⁢φ+λ⁢cos⁡θ2

(2.6)

 

which generates the following general rotated state

 

> 

PrepareState1=Uu, state;

cos⁡θ2⁢Ψ0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ1

(2.7)

 

Each of these gates is unitary.  A unitary operator or matrix has the following identity:  

 

UUH= I

For example,

 

> 

'Ux·Ux%H' = Ux·Ux%H;

Ux·UxH=1001

(2.8)

 

or

 

> 

 'Uu·Uu%H' = Uu·subsI=−I,Uu%T;

Uu·UuH=cos⁡θ22+ⅇI⁢λ⁢sin⁡θ22⁢ⅇ−I⁢λcos⁡θ2⁢ⅇ−I⁢φ⁢sin⁡θ2−ⅇI⁢λ⁢sin⁡θ2⁢ⅇ−I⁢φ+λ⁢cos⁡θ2ⅇI⁢φ⁢sin⁡θ2⁢cos⁡θ2−ⅇI⁢φ+λ⁢cos⁡θ2⁢ⅇ−I⁢λ⁢sin⁡θ2ⅇI⁢φ⁢sin⁡θ22⁢ⅇ−I⁢φ+ⅇI⁢φ+λ⁢cos⁡θ22⁢ⅇ−I⁢φ+λ

(2.9)
> 

simplifyrhs%;

sin⁡θ22+cos⁡θ2200sin⁡θ22+cos⁡θ22

(2.10)
> 

 simplify%;

1001

(2.11)

 

Because the gates are unitary, we can always undo any rotation with an application of the Hermitian transpose of the gate

 

> 

 state2 ≔ PrepareState1=Uu, state;

state2≔cos⁡θ2⁢Ψ0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ1

(2.12)

 

> 

subsI=−I,Uu%T 

cos⁡θ2ⅇ−I⁢φ⁢sin⁡θ2−ⅇ−I⁢λ⁢sin⁡θ2ⅇ−I⁢φ+λ⁢cos⁡θ2

(2.13)


But after using the Hermitian transpose, we return to the original state

 

> 

state3 ≔ PrepareState1=subsI=−I,Uu%T,state2;

state3≔cos⁡θ22+ⅇI⁢φ⁢sin⁡θ22⁢ⅇ−I⁢φ⁢Ψ0+−ⅇ−I⁢λ⁢sin⁡θ2⁢cos⁡θ2+ⅇ−I⁢φ+λ⁢cos⁡θ2⁢ⅇI⁢φ⁢sin⁡θ2⁢Ψ1

(2.14)

 

What happened?  Let's try simplifying

 

> 

state3 ≔ simplifystate3;

state3≔Ψ0

(2.15)

 

We can also examine 2-qubit gates.

 

For example, the CNOT gate is

 

> 

Ucnot ≔ GateCNOT;

Ucnot≔1000000100100100

(2.16)

 

This gate examines the first qubit.  If the first qubit is 1, then it flips the second qubit; otherwise, it applies the identity operator.

 

Let's try it!

 

First, we prepare an initial state with two qubits.

 

> 

state ≔ InitialState2;

state≔Ψ0,0

(2.17)

 

Applying the CNOT gate

 

> 

PrepareState1,2=Ucnot,state;

Ψ0,0

(2.18)

 

does nothing because the first qubit is in the 0 state.

 

Let's first apply the Pauli-X gate to the first qubit

 

> 

state2 ≔ PrepareState1=Ux,state;

state2≔Ψ1,0

(2.19)

 

Now applying the CNOT gate

 

> 

 state3 ≔ PrepareState1,2=Ucnot,state2;

state3≔Ψ1,1

(2.20)

 

flips the second qubit from 0 to 1.

 

Let's try this again by applying the U gate to the first qubit

 

> 

 state2 ≔ PrepareState1=Uu,state;

state2≔cos⁡θ2⁢Ψ0,0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ1,0

(2.21)

 

Now applying the CNOT gate,

 

> 

 state3 ≔ PrepareState1,2=Ucnot,state2;

state3≔cos⁡θ2⁢Ψ0,0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ1,1

(2.22)

 

we observe that the component of the state with the first qubit in 0 does not change while the component of the state with the first qubit in 1 has its second qubit flipped from 0 to 1.

 

Like the 1-qubit gates, the CNOT gate is unitary, which we can check

 

> 

'Ucnot·Ucnot%H' = Ucnot·Ucnot%H; 

Ucnot·UcnotH=1000010000100001

(2.23)

 

Other 2-qubit gates include:

 

The controlled X gate:

> 

GateCX;

1000000100100100

(2.24)

 

The controlled Hadamard gate:

> 

GateCH;

100002202200100220−22

(2.25)

 

The SWAP gate:

> 

Uswap ≔ GateSWAP;

Uswap≔1000001001000001

(2.26)

 

As the name implies, the SWAP gate exchanges the states of two qubits.

 

For example, let us apply the U gate to qubit 1

 

> 

state2 ≔ PrepareState1=Uu,state;

state2≔cos⁡θ2⁢Ψ0,0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ1,0

(2.27)

 

and then the SWAP gate

 

> 

state3 ≔ PrepareState1,2=Uswap,state2;

state3≔cos⁡θ2⁢Ψ0,0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ0,1

(2.28)

 

Notice that the states of the first and second qubits were swapped.

 

We can undo the SWAP via its transpose (note that SWAP is real)

 

> 

 state4 ≔ PrepareState1,2=Uswap%T,state3;

state4≔cos⁡θ2⁢Ψ0,0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ1,0

(2.29)

 

The SWAP gate can be expressed in terms of the CNOT gate

 

> 

 state3 ≔ PrepareState2,1=Ucnot,1,2=Ucnot,2,1=Ucnot,state2;

state3≔cos⁡θ2⁢Ψ0,0+ⅇI⁢φ⁢sin⁡θ2⁢Ψ0,1

(2.30)

 

In fact, the 1-qubit U gate and the 2-qubit CNOT form a universal set of quantum gates in that any quantum state can be prepared from them.

 

State Preparation

To demonstrate state preparation, we make a Schrodinger cat state in which the state of all qubits down becomes entangled with the state of all qubits up.

 

First, we prepare our initial state with all qubits in the 0 state.

 

> 

 state≔ InitialState4;

state≔Ψ0,0,0,0

(3.1)

 

The necessary circuit is an initial application of the Hadamard gate followed by 3 CNOT gates

 

> 

 circuit ≔ 1= GateH,seqi,i+1=GateCNOT, i=1..3;

circuit≔1=222222−22,1,2=1000000100100100,2,3=1000000100100100,3,4=1000000100100100

(3.2)

 

We prepare the new state by applying the circuit to the initial state

 

> 

 state2 ≔ PrepareStatecircuit,state;

state2≔2⁢Ψ0,0,0,02+2⁢Ψ1,1,1,12

(3.3)

 

The new state entangles a state of 4 "down" qubits with a state of 4 "up" qubits.  Like Schrodinger's cat, our state is half up and half down.

 

Measurement

 

Quantum measurement is the process of taking the expectation value of an arbitrary operator.  Practically, on quantum computers we take expectation values of products of 1-qubit operators whose linear combinations can represent arbitrary operators.

 

The simplest measurement is to measure each of the qubits.

 

For example, we can form a 1-qubit operator that gives the probability of a qubit being in the 1 state

 

> 

Up ≔ GateI−GateZ2;

Up≔0001

(4.1)

 

Taking the Schrodinger cat state from the previous example, we can measure the probability of the first qubit being in the 1 state

 

> 

MeasureState1=Up,state2;

12

(4.2)

 

which, given that it is a cat state, is not surprisingly one half.

 

We can plot the independent single qubit populations

 

> 

QubitPopulationsPlotstate2;

 

The probability of all four being up, obtained from the product of four 1-qubit (I-Z)/2 operators,

 

> 

 MeasureState1=Up,2=Up,3=Up,4=Up,state2;

12

(4.3)

 

is also one half.

 

Quantum Algorithm

 

Here we consider a quantum algorithm for the time evolution of an exciton along a chain of 4 chromophores

 

First, we prepare an initial state

 

> 

state ≔ InitialState4;

state≔Ψ0,0,0,0

(5.1)

 

Second, a photon hits the first chromophore, creating an exciton, which we program with the Pauli-X gate acting on qubit 1

 

> 

state2 ≔ PrepareState1= GateX, state;

state2≔Ψ1,0,0,0

(5.2)

 

Next, the exciton transfers from the first chromophore to the second chromophore

 

> 

state3 ≔ PrepareState1,2=GateSWAP,state2;

state3≔Ψ0,1,0,0

(5.3)

 

Then onto the third chromophore

 

> 

 state4 ≔ PrepareState2,3=GateSWAP,state3;

state4≔Ψ0,0,1,0

(5.4)

 

And onto the fourth chromophore

 

> 

 state5 ≔ PrepareState3,4=GateSWAP,state4;

state5≔Ψ0,0,0,1

(5.5)

 

Finally, the exciton transfer its energy to a reaction center, and the excitation is quenched

 

> 

state6 ≔ PrepareState4=GateX,state5;

state6≔Ψ0,0,0,0

(5.6)

 

We can represent the transfer part of the process (minus the quenching) by the following circuit

 

> 

circuit ≔ 1= GateX, seqi,i+1=GateSWAP, i=1..3;

circuit≔1=0110,1,2=1000001001000001,2,3=1000001001000001,3,4=1000001001000001

(5.7)

 

Applying the circuit to the initial state

 

> 

state5 ≔ PrepareStatecircuit,state;

state5≔Ψ0,0,0,1

(5.8)
> 

 

 

generates the state with the exciton on the fourth chromophore.

 

In this particular algorithm, the SWAP gate causes the exciton to hop classically from the first chromophore to the fourth chromophore.

 

References

1. 

M. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information (Cambridge University Press, Cambridge, 2000).

2. 

Amira Abbas and Stina Andersson and Abraham Asfaw and Antonio Corcoles and Luciano Bello and Yael Ben-Haim and Mehdi Bozzo-Rey and Sergey Bravyi and Nicholas Bronn and Lauren Capelluto and Almudena Carrera Vazquez and Jack Ceroni and Richard Chen and Albert Frisch and Jay Gambetta and Shelly Garion and Leron Gil and Salvador De La Puente Gonzalez and Francis Harkins and Takashi Imamichi and Pavan Jayasinha and Hwajung Kang and Amir h. Karamlou and Robert Loredo and David McKay and Alberto Maldonado and Antonio Macaluso and Antonio Mezzacapo and Zlatko Minev and Ramis Movassagh and Giacomo Nannicini and Paul Nation and Anna Phan and Marco Pistoia and Arthur Rattew and Joachim Schaefer and Javad Shabani and John Smolin and John Stenger and Kristan Temme and Madeleine Tod and Ellinor Wanzambi and Stephen Wood and James Wootton, Learn Quantum Computation using Qiskit (IBM, Heightstown, New York, 2023). https://qiskit.org/textbook/preface.html