qsharp-runtime icon indicating copy to clipboard operation
qsharp-runtime copied to clipboard

Dump the Bloch sphere coordinates of a Qubit (from the simulator)

Open RufusJWB opened this issue 3 years ago • 2 comments

Please describe what you would like the feature to accomplish.
I'd like to dump a QuBit from the simulator in the form of Bloch sphere coordinates

Describe the solution you'd like

use qb1 = Qubit();
DumpRegisterAsBlochSphereCoordinates((),[qb1])

Describe alternatives you've considered
I was thinking about dumping the state from the simulator into a text file, parse the text file and calculate the Bloch sphere coordinates.

Additional context
You could use https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.preparation.blochspherecoordinates

RufusJWB avatar Jun 29 '22 15:06 RufusJWB

If you're using Q# from Python, the qsharp.capture_diagnostics context manager can be used to extract simulator dumps into QuTiP objects, where you can perform this kind of analysis.

For example:

with qsharp.capture_diagnostics(as_qobj=True) as diag:
    RunMain.simulate()
# diag should now contain QuTiP objects for each DumpMachine call in
# RunMain

cgranade avatar Jun 29 '22 15:06 cgranade

If you're using Q# from Python,

I'm intending to using q# directly. If this is not working, I'd prefer to use c# over Python. Would you have an example in c#?

RufusJWB avatar Jun 29 '22 16:06 RufusJWB