Layout ServiceΒΆ

The LayoutService finds an optimal physical qubit layout from a given optimization problem and device, such that all parity constraints are locally implementable on the given device.

It takes a device layout (DeviceConnectivity) and an input optimization problem (ProblemRepresentation) and produces an optimal layout and choice of parity constraints on a given hardware in form of a ParityMapping.

from parityos.bits import get_q
from parityos.devices.device_connectivity import get_rectangular_plaquette_connectivity
from parityos.operators.elementary_operator import Z
from parityos.optimization.constraint import SumConstraint
from parityos.optimization.problem_representation import ProblemRepresentation
from parityos.services.authentication import InteractiveAuth
from parityos.services.client import HTTPClient
from parityos.services.service import LayoutInput, LayoutService

# Create Pauli-Z Operators on 5 logical qubits with ids [0, 1, 2, 3, 4]
z = [Z(get_q(i)) for i in range(5)]
# The interaction hamiltonian defining the optimization problems
hamiltonian = (
    -2 * z[0] * z[1]
    - 3 * z[0] * z[4]
    + z[1] * z[3]
    + 2 * z[3] * z[4]
    - 3 * z[0] * z[1] * z[2]
    + 1.5 * z[2] * z[3] * z[4]
)
# A sum constraint between 3 logical qubits
sum_constraint = SumConstraint(z[0] + z[2] + z[4], 1)
# The complete problem with interaction hamiltonian and explicit constraints
problem = ProblemRepresentation(hamiltonian, sum_constraints=sum_constraint)

# A 4 x 4 qubit quantum annealer with 3 and 4 body plaquette interactions
device_layout = get_rectangular_plaquette_connectivity(4, 4)

# Set up connection to ParityOS cloud service
client = HTTPClient(InteractiveAuth("my_parityos_username"))  # handles authentication
service = LayoutService(client)  # handles API communication with the cloud service

# Run problem (with a certain configuration or preset and a description to recognize the job by)
# and obtain result
result = service.run(LayoutInput(problem, device_layout), "my_preset", "My first parityos job.")
# the mapping between logical qubits and physical device qubits
print(result.encoding_map)
# the constraints on the device qubits (given explicit sum constraint and parity mapping constraints)
print(result.constraints)