def test_get_qc_noisy_qpu_error(client_configuration: QCSClientConfiguration, dummy_compiler: DummyCompiler): expected_message = ( "pyQuil currently does not support initializing a noisy QuantumComputer " "based on a QCSQuantumProcessor. Change noisy to False or specify the name of a QVM." ) with pytest.raises(ValueError, match=expected_message): get_qc("Aspen-8", noisy=True)
def test_qc_error(client_configuration: QCSClientConfiguration): # QVM is not a QPU with pytest.raises(ValueError): get_qc("9q-square-noisy-qvm", as_qvm=False, client_configuration=client_configuration) with pytest.raises(ValueError): get_qc("5q", as_qvm=False, client_configuration=client_configuration)
def test_qc_joint_calibration(client_configuration: QCSClientConfiguration): # noise model with 95% symmetrized readout fidelity per qubit noise_model = asymmetric_ro_model([0, 1], 0.945, 0.955) qc = get_qc("2q-qvm", client_configuration=client_configuration) qc.qam.noise_model = noise_model # |01> state program p = Program() p += RESET() p += X(0) p.wrap_in_numshots_loop(10000) # ZZ experiment sz = ExperimentSetting(in_state=_pauli_to_product_state(sZ(0) * sZ(1)), out_operator=sZ(0) * sZ(1), additional_expectations=[[0], [1]]) e = Experiment(settings=[sz], program=p) results = qc.run_experiment(e) # ZZ expectation value for state |01> with 95% RO fid on both qubits is about -0.81 assert np.isclose(results[0].expectation, -0.81, atol=0.01) assert results[0].total_counts == 40000 # Z0 expectation value for state |01> with 95% RO fid on both qubits is about -0.9 assert np.isclose(results[0].additional_results[0].expectation, -0.9, atol=0.01) assert results[0].additional_results[1].total_counts == 40000 # Z1 expectation value for state |01> with 95% RO fid on both qubits is about 0.9 assert np.isclose(results[0].additional_results[1].expectation, 0.9, atol=0.01) assert results[0].additional_results[1].total_counts == 40000
def test_nq_qvm_qc(client_configuration: QCSClientConfiguration): for n_qubits in [2, 4, 7, 19]: qc = get_qc(f"{n_qubits}q-qvm", client_configuration=client_configuration) for q1, q2 in itertools.permutations(range(n_qubits), r=2): assert (q1, q2) in qc.qubit_topology().edges assert qc.name == f"{n_qubits}q-qvm"
def test_qc(client_configuration: QCSClientConfiguration): qc = get_qc("9q-square-noisy-qvm", client_configuration=client_configuration) assert isinstance(qc, QuantumComputer) assert qc.qam.noise_model is not None assert qc.qubit_topology().number_of_nodes() == 9 assert qc.qubit_topology().degree[0] == 2 assert qc.qubit_topology().degree[4] == 4 assert str(qc) == "9q-square-noisy-qvm"
def test_qc_compile(dummy_compiler: DummyCompiler, client_configuration: QCSClientConfiguration): qc = get_qc("5q", as_qvm=True, noisy=True, client_configuration=client_configuration) qc.compiler = dummy_compiler prog = Program() prog += H(0) assert qc.compile(prog) == prog
def test_qc_run(client_configuration: QCSClientConfiguration): qc = get_qc("9q-square-noisy-qvm", client_configuration=client_configuration) bs = qc.run( qc.compile( Program( Declare("ro", "BIT", 1), X(0), MEASURE(0, ("ro", 0)), ).wrap_in_numshots_loop(3))).readout_data.get("ro") assert bs.shape == (3, 1)
def test_run_symmetrized_readout_error( client_configuration: QCSClientConfiguration): # This test checks if the function runs for any possible input on a small number of qubits. # Locally this test was run on all 8 qubits, but it was slow. qc = get_qc("8q-qvm", client_configuration=client_configuration) sym_type_vec = [-1, 0, 1, 2, 3] prog_vec = [Program(I(x) for x in range(0, 3))[0:n] for n in range(0, 4)] trials_vec = list(range(0, 5)) for prog, trials, sym_type in itertools.product(prog_vec, trials_vec, sym_type_vec): print(qc.run_symmetrized_readout(prog, trials, sym_type))
def test_noisy(client_configuration: QCSClientConfiguration): # https://github.com/rigetti/pyquil/issues/764 p = Program( Declare("ro", "BIT", 1), X(0), MEASURE(0, ("ro", 0)), ).wrap_in_numshots_loop(10000) qc = get_qc("1q-qvm", noisy=True, client_configuration=client_configuration) result = qc.run(qc.compile(p)).readout_data.get("ro") assert result.mean() < 1.0
def test_get_qc_endpoint_id(client_configuration: QCSClientConfiguration, qcs_aspen8_isa: InstructionSetArchitecture): """ Assert that get_qc passes a specified ``endpoint_id`` through to its QPU when constructed for a live quantum processor. """ respx.get( url= f"{client_configuration.profile.api_url}/v1/quantumProcessors/test/instructionSetArchitecture", ).respond(json=qcs_aspen8_isa.to_dict()) qc = get_qc("test", endpoint_id="test-endpoint") assert qc.qam._qpu_client._endpoint_id == "test-endpoint"
def test_qc_calibration_2q(client_configuration: QCSClientConfiguration): # noise model with 95% symmetrized readout fidelity per qubit noise_model = asymmetric_ro_model([0, 1], 0.945, 0.955) qc = get_qc("2q-qvm", client_configuration=client_configuration) qc.qam.noise_model = noise_model # bell state program (doesn't matter) p = Program() p += RESET() p += H(0) p += CNOT(0, 1) p.wrap_in_numshots_loop(10000) # ZZ experiment sz = ExperimentSetting(in_state=_pauli_to_product_state(sZ(0) * sZ(1)), out_operator=sZ(0) * sZ(1)) e = Experiment(settings=[sz], program=p) results = qc.calibrate(e) # ZZ expectation should just be (1 - 2 * readout_error_q0) * (1 - 2 * readout_error_q1) np.isclose(results[0].expectation, 0.81, atol=0.01) assert results[0].total_counts == 40000
def test_qc_noisy(client_configuration: QCSClientConfiguration): qc = get_qc("5q", as_qvm=True, noisy=True, client_configuration=client_configuration) assert isinstance(qc, QuantumComputer)