3

I'm just starting with Qiskit and I would like to reproduce basic results about spin measurements. For that I want to prepare multiple spins each in arbitrary directions and measure them in arbitrary directions to get the probabilities.

What is the suggested way to do that in Qiskit?

Gere
  • 130
  • 2
  • This question might be helpful. It is not for arbitrary directions, but does show how to measure in the X-basis and Y-basis: https://quantumcomputing.stackexchange.com/questions/13605/how-to-measure-in-another-basis – phasefactor Aug 17 '21 at 15:58
  • Another useful reference might be this lab from the Qiskit textbook: https://qiskit.org/textbook/ch-labs/Lab02_QuantumMeasurement.html It discusses why the measurement has to be done in the Z-basis and shows how to do some measurements. – phasefactor Aug 17 '21 at 16:08

1 Answers1

3

The suggested way to do measurements in a different axis is to change the orientation of the state vector at the end and measure in the $z$-basis as usual.

To go from one basis to the other you can use $H$ and $S=\sqrt{Z}$ gates that act as unitary transformations of your system. If you apply $H$ to your qubit and then do a measurement, it is the same as measuring in the $x$-axis. $HS^\dagger+$measurement is the same as measuring in the $y$-axis. A visual representation can be found in this answer: https://quantumcomputing.stackexchange.com/a/13611/15775

If you need to do a measurement in any other basis you can use rotation gates $R_y(\theta),R_z(\theta)+$measurement (two rotation gates are enough to do all kind of rotations).

To prepare an arbitrary state, you can use .initialize. Alternatively, you can also use the rotation gates.

The details of the gate operations and arbitrary initialization in Qiskit can be found here: https://qiskit.org/documentation/tutorials/circuits/3_summary_of_quantum_operations.html

Mauricio
  • 2,296
  • 3
  • 25