If you do not have access to data you can instead pass in a collection of gates to the gates prop either in the update function or the constructor. To try this, where you have initialized the visualizer instance update the code like so:
const myVisualizer = new Visualizer({
wrapper: visualizerWrapper,
gates: [{ gateType: "X" }, { gateType: "H" }, { gateType: "Z" }, { gateType: "T" }]
})
You can also pass in an optional rotation percentage, as a fraction, for each gate which will then tell the visualizer to rotate the gate by only the specified percentage of a standard rotation for that gate operation:
gates: [{ gateType: "X", rotationPercentage: 0.3 }, { gateType: "H", rotationPercentage: 0.8 }, { gateType: "Z", rotationPercentage: 0.5 }, { gateType: "T", rotationPercentage: 0.4 }]
You could also pass in an instantGates
prop set to true
and this would cause the gates animation to jump to each gate without animating a path for it
The Visualizer will generate the correct data to animate from the gate sequence you passed in. Now when you preview your HTML you will see an animated visualization of the above gate sequence. See the DOCS section on Gates for more info and available gate types
At this point you could also simulate a measurement on the Bloch sphere. There is a special "gate" operation type you can pass in: MEASUREMENT
. This will simulate taking a measurement of the qubit from the final state after the gate sequence has been run. The state indicator will jump to the north or south pole depending on the probability of the measurement calculation. The MEASUREMENT
operation will only have an effect if added at the end of the gate sequence
You could update the above line of code to be:
gates: [{ gateType: "X", rotationPercentage: 0.3 }, { gateType: "H", rotationPercentage: 0.8 }, { gateType: "Z", rotationPercentage: 0.5 }, { gateType: "T", rotationPercentage: 0.4 }, { gateType: "MEASUREMENT" }]