Driver ServiceΒΆ
The DriverService generates constraint preserving driver (mixer) Hamiltonians for a QAOA optimization. The advantage of constraint preserving mixer Hamiltonians is that constraints do not need to be implemented as additional terms with an energy penalty. The service takes a ProblemRepresentation of an optimization problem already transformed to parity qubits using a ParityMapping and a DeviceConnectivity and returns the following three Hamiltonians:
A constrain Hamiltonian in the Pauli Z basis
A driver Hamiltonian in the Pauli X basis
A driver Hamiltonian consisting of exchange (or hopping) terms (
ExchangeTerm)
Circuits for applying exponentials of these Hamiltonians on a given device can be obtained using the Circuit Service.
from parityos.bits import get_q
from parityos.devices.device_connectivity import (
get_rectangular_nearest_neighbor_connectivity,
)
from parityos.operators.elementary_operator import Z
from parityos.optimization.constraint import ProductConstraint
from parityos.optimization.problem_representation import ProblemRepresentation
from parityos.services.authentication import InteractiveAuth
from parityos.services.client import HTTPClient
from parityos.services.service import DriverInput, DriverService
# The parity transformed problem Hamiltonian
hamiltonian = Z(get_q(0, 1)) + Z(get_q(1, 0)) - 2 * Z(get_q(1, 1)) - Z(get_q(0, 0))
# The parity transformed constraints
constraints = [
ProductConstraint(Z(get_q(0, 1)) * Z(get_q(1, 0)) * Z(get_q(0, 0))),
ProductConstraint(Z(get_q(1, 1)) * Z(get_q(0, 1)) * Z(get_q(1, 0))),
]
# the parity transformed problem representation
problem = ProblemRepresentation(hamiltonian, constraints)
# A 4 x 4 square grid qubit quantum computing device with nearest neighbor interactions
device_layout = get_rectangular_nearest_neighbor_connectivity(4, 4)
# Set up connection to ParityOS cloud service
client = HTTPClient(InteractiveAuth("my_parityos_username")) # handles authentication
service = DriverService(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(DriverInput(problem, device_layout), "my_preset", "My first parityos job.")
# The returned constraint preserving driver Hamiltonians
print(result.constraint_hamiltonian)
print(result.x_driver_hamiltonian)
print(result.exchange_driver_hamiltonian)