def test_generate_training_circuits_with_clifford_circuit(): with pytest.raises(ValueError, match="Circuit is already Clifford."): generate_training_circuits( Circuit(cirq.ops.rx(0.0).on(cirq.LineQubit(0))), num_training_circuits=1, fraction_non_clifford=0.0, )
def test_generate_training_circuits_with_clifford_circuit(): circuit = Circuit(cirq.ops.rx(0.0).on(cirq.LineQubit(0))) assert generate_training_circuits( circuit, num_training_circuits=2, fraction_non_clifford=0.0, ) == [circuit, circuit]
def test_generate_training_circuits_bad_methods(): with pytest.raises(ValueError): generate_training_circuits( Circuit(cirq.ops.rx(0.5).on(cirq.LineQubit(0))), num_training_circuits=1, fraction_non_clifford=0.0, method_select="unknown select method", ) with pytest.raises(ValueError): generate_training_circuits( Circuit(cirq.ops.rx(0.5).on(cirq.LineQubit(0))), num_training_circuits=1, fraction_non_clifford=0.0, method_replace="unknown replace method", )
def test_generate_training_circuits_any_qprogram(circuit_type): circuit = random_x_z_cnot_circuit(cirq.LineQubit.range(3), n_moments=5, random_state=1) circuit = convert_from_mitiq(circuit, circuit_type) (clifford_circuit, ) = generate_training_circuits( circuit, num_training_circuits=1, fraction_non_clifford=0.0) assert is_clifford(clifford_circuit)
def test_generate_training_circuits(): circuit = random_x_z_cnot_circuit(cirq.LineQubit.range(3), n_moments=5, random_state=1) assert not is_clifford(circuit) (clifford_circuit, ) = generate_training_circuits( circuit, num_training_circuits=1, fraction_non_clifford=0.0) assert is_clifford(clifford_circuit)
def test_generate_training_circuits_mega(method_select, method_replace, kwargs): circuit = random_x_z_cnot_circuit(qubits=4, n_moments=10, random_state=1) num_train = 10 fraction_non_clifford = 0.1 train_circuits = generate_training_circuits( circuit, num_training_circuits=num_train, fraction_non_clifford=0.1, random_state=np.random.RandomState(13), method_select=method_select, method_replace=method_replace, **kwargs, ) assert len(train_circuits) == num_train for train_circuit in train_circuits: assert set(train_circuit.all_qubits()) == set(circuit.all_qubits()) assert count_non_cliffords(train_circuit) == int( round(fraction_non_clifford * count_non_cliffords(circuit)))