def test_tomography_plot_raises_for_incorrect_number_of_axes(): simulator = sim.Simulator() qubit = GridQubit(0, 0) circuit = circuits.Circuit(ops.X(qubit)**0.5) result = single_qubit_state_tomography(simulator, qubit, circuit, 1000) with pytest.raises(TypeError): # ax is not a List[plt.Axes] ax = plt.subplot() result.plot(ax) with pytest.raises(ValueError): _, axes = plt.subplots(1, 3) result.plot(axes)
def test_single_qubit_state_tomography(): # Check that the density matrices of the output states of X/2, Y/2 and # H + Y gates closely match the ideal cases. simulator = sim.Simulator() qubit = GridQubit(0, 0) circuit_1 = circuits.Circuit(ops.X(qubit)**0.5) circuit_2 = circuits.Circuit(ops.Y(qubit)**0.5) circuit_3 = circuits.Circuit(ops.H(qubit), ops.Y(qubit)) act_rho_1 = single_qubit_state_tomography(simulator, qubit, circuit_1, 1000).data act_rho_2 = single_qubit_state_tomography(simulator, qubit, circuit_2, 1000).data act_rho_3 = single_qubit_state_tomography(simulator, qubit, circuit_3, 1000).data tar_rho_1 = np.array([[0.5, 0.5j], [-0.5j, 0.5]]) tar_rho_2 = np.array([[0.5, 0.5], [0.5, 0.5]]) tar_rho_3 = np.array([[0.5, -0.5], [-0.5, 0.5]]) np.testing.assert_almost_equal(act_rho_1, tar_rho_1, decimal=1) np.testing.assert_almost_equal(act_rho_2, tar_rho_2, decimal=1) np.testing.assert_almost_equal(act_rho_3, tar_rho_3, decimal=1)