示例#1
0
def basic_variational_circuit(params, rotations, masked_circuit: MaskedCircuit):
    full_parameters = masked_circuit.expanded_parameters(params)
    wires = masked_circuit.wires
    dropout_mask = masked_circuit.full_mask(DropoutMask)
    for wire, _is_masked in enumerate(masked_circuit.mask(Axis.WIRES)):
        qml.RY(np.pi / 4, wires=wire)
    r = -1
    for layer, _is_layer_masked in enumerate(masked_circuit.mask(Axis.LAYERS)):
        for wire, _is_wire_masked in enumerate(masked_circuit.mask(Axis.WIRES)):
            r += 1
            if dropout_mask[layer][wire]:
                continue
            if rotations[r] == 0:
                rotation = qml.RX
            elif rotations[r] == 1:
                rotation = qml.RY
            else:
                rotation = qml.RZ
            rotation(full_parameters[layer][wire], wires=wire)

        for wire in range(0, wires - 1, 2):
            if (
                Axis.ENTANGLING in masked_circuit.masks
                and masked_circuit.mask(Axis.ENTANGLING)[layer, wire]
            ):
                continue
            qml.CZ(wires=[wire, wire + 1])
        for wire in range(1, wires - 1, 2):
            if (
                Axis.ENTANGLING in masked_circuit.masks
                and masked_circuit.mask(Axis.ENTANGLING)[layer, wire]
            ):
                continue
            qml.CZ(wires=[wire, wire + 1])
示例#2
0
文件: utils.py 项目: cirKITers/masKIT
def variational_circuit(params, masked_circuit: MaskedCircuit = None):
    full_parameters = masked_circuit.expanded_parameters(params)
    for layer, layer_hidden in enumerate(masked_circuit.mask(Axis.LAYERS)):
        if not layer_hidden:
            for wire, wire_hidden in enumerate(masked_circuit.mask(Axis.WIRES)):
                if not wire_hidden:
                    if not masked_circuit.mask(Axis.PARAMETERS)[layer][wire][0]:
                        qml.RX(full_parameters[layer][wire][0], wires=wire)
                    if not masked_circuit.mask(Axis.PARAMETERS)[layer][wire][1]:
                        qml.RY(full_parameters[layer][wire][1], wires=wire)
            for wire in range(0, masked_circuit.mask(Axis.LAYERS).size - 1, 2):
                qml.CZ(wires=[wire, wire + 1])
            for wire in range(1, masked_circuit.mask(Axis.LAYERS).size - 1, 2):
                qml.CZ(wires=[wire, wire + 1])
    return qml.probs(wires=range(len(masked_circuit.mask(Axis.WIRES))))