示例#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")
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
import pytest
import sys
import numpy as np
from qoqo import operations as ops
from qoqo import Circuit
from typing import Any
from qoqo_mock import mocked_call_circuit


@pytest.mark.parametrize("op", [
    ops.Bogoliubov(1, 0, 0.01, 0.02),
    ops.CNOT(1, 0),
    ops.ControlledPauliY(1, 0),
    ops.ControlledPauliZ(1, 0),
    ops.ControlledPhaseShift(1, 0, 0.01),
    ops.FSwap(1, 0),
    ops.Fsim(1, 0, 0.01, 0.02, 0.03),
    ops.Qsim(1, 0, 0.01, 0.02, 0.03),
    ops.GivensRotation(1, 0, 0.01, 0.02),
    ops.GivensRotationLittleEndian(0, 1, 0.01, 0.02),
    ops.ISwap(1, 0),
    ops.InvSqrtISwap(1, 0),
    ops.MolmerSorensenXX(1, 0),
    ops.VariableMSXX(1, 0, 0.01),
    ops.PMInteraction(1, 0, 0.01),
    ops.ComplexPMInteraction(1, 0, 0.01, 0.02),
    ops.SWAP(1, 0),
示例#3
0
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
import pytest
import sys
import numpy as np
import numpy.testing as npt
from typing import Tuple, Any
from qoqo import operations as ops
from qoqo_qasm import qasm_call_operation


@pytest.mark.parametrize("gate", [
    (ops.RotateX(0, -np.pi), 'rx(-3.141592653589793) q[0]'),
    (ops.RotateY(0, -np.pi), 'ry(-3.141592653589793) q[0]'),
    (ops.RotateZ(0, -np.pi), 'rz(-3.141592653589793) q[0]'),
    (ops.CNOT(0, 1), 'cx q[0],q[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]'),