Beispiel #1
0
def test_acceptance_with_qiskit():
    """Test gate operations with QASM interface"""
    circuit = Circuit()

    circuit += ops.RotateX(0, -np.pi)
    circuit += ops.RotateY(0, -np.pi)
    circuit += ops.RotateZ(0, -np.pi)
    circuit += ops.CNOT(0, 1)
    circuit += ops.Hadamard(0)
    circuit += ops.PauliX(0)
    circuit += ops.PauliY(0)
    circuit += ops.PauliZ(0)
    circuit += ops.SGate(0)
    circuit += ops.TGate(0)
    circuit += ops.SqrtPauliX(0)
    circuit += ops.MolmerSorensenXX(0, 1)
    circuit += ops.ControlledPauliY(0, 1)
    circuit += ops.ControlledPauliZ(0, 1)
    circuit += ops.SingleQubitGate(0, 1, 0, 1, 0, 1.0)
    circuit += ops.PragmaRepeatedMeasurement('ro', 1, None)
    circuit += ops.MeasureQubit(0, 'ro', 0)
    circuit += ops.DefinitionFloat(name='rof', length=1, is_output=True)
    circuit += ops.DefinitionBit(name='ro', length=2, is_output=True)
    circuit += ops.DefinitionComplex(name='roc', length=1, is_output=True)
    circuit += ops.InputSymbolic('other', 0)
    circuit += ops.PragmaSetNumberOfMeasurements(20, 'ro')

    backend = QasmBackend(number_qubits=2)
    backend.run_circuit(circuit=circuit, overwrite=True)

    q_circuit = QuantumCircuit.from_qasm_file(
        "default_qasm_backend_output.qasm")
Beispiel #2
0
def test_circuit(measurement):
    """Test building a circuit"""
    circuit = Circuit()
    circuit += ops.DefinitionFloat(name='ro', length=1, is_output=True)
    circuit += ops.DefinitionComplex(name='ro', length=1, is_output=True)
    circuit += ops.DefinitionBit(name='ro', length=1, is_output=True)
    circuit += ops.PauliX(qubit=0)
    circuit += measurement[0]
    assert len(circuit) > 0
def test_all_operations(op: Any):
    """Test all operations with mocked interface"""
    circuit = Circuit()
    circuit += ops.DefinitionFloat(name='ro', length=1, is_output=False)
    circuit += ops.DefinitionBit(name='ro', length=1, is_output=False)
    circuit += ops.DefinitionComplex(name='ro', length=1, is_output=False)
    circuit += ops.DefinitionUsize(name='ro', length=1, is_output=False)
    circuit += op
    mocked_call_circuit(circuit=circuit,
                        classical_bit_registers={},
                        classical_float_registers={},
                        classical_complex_registers={},
                        output_bit_register_dict={},
                        output_complex_register_dict={},
                        number_qubits=1)
Beispiel #4
0
def test_mocked_backend(measurement):
    """Test mocked backend"""
    circuit = Circuit()
    circuit += ops.DefinitionFloat(name='ro', length=1, is_output=True)
    circuit += ops.DefinitionComplex(name='ro', length=1, is_output=True)
    circuit += ops.DefinitionBit(name='ro', length=1, is_output=True)
    circuit += ops.PauliX(qubit=0)
    circuit += measurement[0]

    mocked = MockedBackend(number_qubits=2)

    results = mocked.run_circuit(circuit=circuit)[measurement[2]]['ro'][0]
    if isinstance(results[0], List):
        assert isinstance(results[0][0], measurement[1])
    else:
        assert isinstance(results[0], measurement[1])
Beispiel #5
0
def test_pyquest_global_phase():
    """Test with PyQuEST"""
    circuit = Circuit()
    circuit += ops.DefinitionBit(name='out', length=2, is_output=True)
    circuit += ops.DefinitionFloat(name='global_phase',
                                   length=1,
                                   is_output=True)
    circuit += ops.PauliX(qubit=0)
    circuit += ops.PragmaGlobalPhase(phase=1)
    circuit += ops.PragmaGlobalPhase(phase='test')
    circuit += ops.MeasureQubit(qubit=0, readout='out', readout_index=0)
    circuit += ops.MeasureQubit(qubit=1, readout='out', readout_index=1)
    circuit += ops.InputSymbolic(name="test", input=-2)
    circuit = circuit.substitute_parameters({})
    pyquest = PyQuestBackend(number_qubits=2)
    (output_bit_register_dict, output_float_register_dict,
     output_complex_register_dict) = pyquest.run_circuit(circuit)
    assert output_bit_register_dict['out'] == [[True, False]]
    assert len(output_bit_register_dict['out']) == 1
    assert output_float_register_dict['global_phase'][0][0] == -1
    (ops.Hadamard(0), 'h q[0]'),
    (ops.PauliX(0), 'x q[0]'),
    (ops.PauliY(0), 'y q[0]'),
    (ops.PauliZ(0), 'z q[0]'),
    (ops.SGate(0), 's q[0]'),
    (ops.TGate(0), 't q[0]'),
    (ops.SqrtPauliX(0), 'rx(1.5707963267948966) q[0]'),
    (ops.MolmerSorensenXX(0, 1), 'rxx(pi/2) q[0],q[1]'),
    (ops.ControlledPauliY(0, 1), 'cy q[0],q[1]'),
    (ops.ControlledPauliZ(0, 1), 'cz q[0],q[1]'),
    (ops.SingleQubitGate(0, 1, 0, 1, 0, 1.0), 'u3(0.0,0.0,-0.0) q[0]'),
    (ops.PragmaRepeatedMeasurement('ro', 1, None), 'measure q -> ro;\n'),
    (ops.PragmaRepeatedMeasurement('ro', 1, {0: 1, 1: 0}),
     'measure q[1] -> ro[0];\nmeasure q[0] -> ro[1];\n'),
    (ops.MeasureQubit(0, 'ro', 0), 'measure q[0] -> ro[0]'),
    (ops.DefinitionFloat(name='ro', length=1, is_output=True), 'creg ro[1]'),
    (ops.DefinitionUsize(name='ro', length=1, is_output=True), 'creg ro[1]'),
    (ops.DefinitionBit(name='ro', length=1, is_output=True), 'creg ro[1]'),
    (ops.DefinitionComplex(name='ro', length=1, is_output=True), 'creg ro[1]'),
    (ops.InputSymbolic('other', 0), None),
    (ops.PragmaSetNumberOfMeasurements(20, 'ro'), None)
])
def test_gate_translation(gate: Tuple[Any, str]):
    """Test gate operations with QASM interface"""
    qasm_operation = qasm_call_operation(operation=gate[0],
                                         number_qubits=2)

    if gate[1] is None:
        assert qasm_operation is None
    else:
        npt.assert_string_equal(qasm_operation, gate[1])