The QPath Blog


q_rEngineer_QP_APP_b

Using QuantumPath® Q Provider Factory with quantum programmes implemented with Ocean SDK

Q Provider Factory is a Python library of QrEngineer APP that allows quantum programs developed with different SDKs from the main quantum providers to be adapted to the QuantumPath® ecosystem with the aim of making it easier for developers to use all the functionalities and advantages of the platform without the user having to give up working with their favourite SDK [1].

One of the technologies supported by Q Provider Factory is Ocean SDK, the Python development software provided by D-Wave, which allows you to solve optimisation problems on their annealing quantum computers.

In the following we will show, step by step, how to use Q Provider Factory to transpile and execute, through QuantumPath®, a quantum program implemented with Ocean SDK. The example chosen for the article is the optimisation problem “Nurse Scheduling“, whose source code can be found in GitHub de D-Wave repository, where there is an extensive catalogue of examples of optimisation problems implemented with this SDK.

 

Using Q Provider Factory

·       Install QrEngineer SDK.

To work with Q Provider Factory, it is necessary to install QrEngineer SDK, for which it is necessary to execute the following instruction in a command console:

 pip install QrEngineerSDK

 

·       Identify the main file of the quantum programme to be integrated with QuantumPath®, in this case nurse_scheduling.py.

# Off-diagonal terms in soft nurse constraint

# Include only the same nurse, across days

for nurse in range(n_nurses):

    for day1 in range(n_days):

        for day2 in range(day1 + 1, n_days):

 

            ind1 = get_index(nurse, day1)

            ind2 = get_index(nurse, day2)

            Q[ind1, ind2] += 2 * lagrange_soft_nurse * preference ** 2

 

# Solve the problem, and use the offset to scale the energy

e_offset = (lagrange_hard_shift * n_days * workforce ** 2) +
(lagrange_soft_nurse * n_nurses * min_duty_days ** 2)

bqm = BinaryQuadraticModel.from_qubo(Q, offset=e_offset)

 

·       Identify the line where the creation of the Binay Quadratic Model object with the mathematical representation of the problem ends.

# Solve the problem, and use the offset to scale the energy

e_offset = (lagrange_hard_shift * n_days * workforce ** 2) +
(lagrange_soft_nurse * n_nurses * min_duty_days ** 2)

bqm = BinaryQuadraticModel.from_qubo(Q, offset=e_offset)

 

·       Add after that line, the Q Provider Factory code needed to transpile the circuit and run it through QuantumPath®:

 

o   Add an import statement to the SDK’s QProviderFactory class.

 from QrEngineerSDK import QProviderFactory

 

o   Instantiate the QProviderFactory object, specifying the QuantumPath® credentials.

qprovider = QProviderFactory(user = ‘***qpath user***’,
passwordSHA256=’***sha-256 encrypted password***’)

 

o   Transpile the original Binary Quadratic Model to a QuantumPath® annealing circuit, using the transpileDwaveBQM instruction.

 

qpathCircuit = qProvider.transpileDwaveBQM(bqm)

 

o   Launch the execution of the circuit through QuantumPath®, providing the solution identifier, the quantum device, the namespace, the circuit name and the number of executions or samples to perform.

 

qpathSolutionID = 10742
qpathDeviceID = 7
qpathCircuitName = ‘NurseScheduling’
qpathNamespace = ‘TEST’
qpathNumRepeats = 100
result =
qprovider.executeQPathCircuit(qpathSolutionID,qpathDeviceID,qpathCircuitName,
qpathNamespace,qpathNumRepeats,qpathCircuit)

 

o   Check the result of the execution and display it on the screen:

if result.success:
print(“Execution result: ” + str(result.histogram))
else:
print(“Error executing the circuit” + result.error)

 

Once the execution is finished in Q Provider Factory, the user can access QuantumPath® and visualise the circuit and flow automatically generated by the SDK in the indicated solution, and check the result of the execution in the platform.

Illustration 1: Circuit generated with QrEngineer Python SDK, as seen in QuantumPath®.

 

In addition, as can be seen in the following illustrations, development and execution tasks can be carried out with the Nurse Scheduling” optimisation problem adapted to QPath®.

Illustration 2: Editing the Hamiltonian of “Nurse Scheduling” with Q Assets Compositor® for Annealing

Illustration 3: QuantumPath® Runtime Dashboard

 

Once the adaptation is done, we will not only have the original code refactored and fully operational, but we will also have additional advantages:

·       The possibility of launching the problem in all those devices compatible with annealing optimisation technologies, which in QuantumPath® can be both QPUs from other providers and gate-based QPUs, through the platform’s Q Agnostic QAOA® services. Simply by changing the connection strings and preparing the solution in the QuantumPath® Solution Manager.

·       The problem generated in the QuantumPath® asset repository. Which, again, provides a migration of the problem to the “no code” platform and bring the solution into the product solution lifecycle.

·       Encapsulate the resulting solution in other solutions that under qSOA® services can be exploited in classic applications.

 

Using Q Provider Factory Web UI

Q Provider Factory Web UI allows to speed up the above process by automating the refactoring of the original program code and writing the necessary Q Provider Factory SDK code by the user. To do this, the user must follow the following steps:

·       Access the tool and authenticate with their QuantumPath® credentials.

·       Create a new project or access an existing one.

Illustration 4: Q Provider Factory project catalogue.

 

·       Attach the source code of the quantum circuit or program.

Illustration 5: Form for adding a quantum circuit.

Illustration 6: Quantum circuit code added to a project.

 

·       From the “Code migrations” tab, generate new integration code with QuantumPath®, indicating:

o   Namespace and name of the circuit to be created in QPath®.

o   QPath® solution where to place the circuit.

o   Quantum device where to launch the execution of the circuit.

Illustration 7: Form to generate the code for a new integration with QPath®. 

 

·       From the source code, select the main program file and the line where the Q Provider Factory code is to be inserted.

Illustration 8: Selecting the location where the Q Provider Factory code is to be inserted. 

 

·       Save the generated code and download it for local execution.

Illustration 9: Code generated by the tool.  

 

·       Before executing it, the user must edit it and insert his password:

o   Base64 encoded:

qprovider = QProviderFactory(user = ‘***quantum path user***’,
passwordB64=’***Base64-encoded password***’)

o   Or SHA256 encrypted:

qprovider = QProviderFactory(user = ‘***quantum path user***’,
passwordSHA256=’***sha-256 encrypted password***’)

 

By launching the program execution from a local command console, you can see the result of the integration and execution against QPath®:

Illustration 10: Command console running the modified “Nurse scheduling” programme.

 

Having done this, as shown in the Q Provider Factory section, the developer will be able to access, visualise and work without limitations with the “Nurse Scheduling” optimisation problem from the QuantumPath® platform.

 

Summary

QuantumPath® is a Full-Stack platform for quantum software development and lifecycle control of hybrid quantum/classical systems: from the creation of the quantum algorithm, through its development, testing and implementation, integration, deployment and reuse. A platform designed to enable the engineering and lifecycle of hybrid quantum software.

As we have seen, thanks to QPath®’s Q Provider Factory adapters, it has taken just a few steps to adapt the “Nurse Scheduling” programme to QuantumPath®. With this, developers can have a new added value by being able to use other tools on their selected platform, in addition to being able to continue using the code and keep it in its original environment by reusing the contents gained in that environment, in this case D-Wave’s Ocean SDK, which can also be used directly from QPath®.

This working option opens a new path to the developer and to the development of quantum applications in a less traumatic way if, enabling the reuse of the knowledge and intuition gained, it is desired to migrate to be able to use some of the many functionalities of QPath®, namely: vendor agnostic technology, asset management, Q Assets Compositor® design tools, metalanguages, compilers, transpilers, scalable execution units on demand, unified results, integration adapters, quantum services catalogue to name the most relevant functionalities as well as taking advantage of the qSOA® architecture for the dynamic integration of the quantum programs with the classical IT of the organisations, technological risk management … In short, to be able to use the whole ALM stack oriented to the professional development of hybrid quantum/classical software systems.

Once the “Nurse Scheduling” programme has been adapted to the platform, it will enter the lifecycle, as a native element, of the rest of the QPath® capabilities (QAgnostic, QHybrid, QQuality, QManagement, QBusiness and QWorkforce). This ecosystem offers other possibilities of exploitation of the development adapted to QPath®, by being able to use in its life cycle the wide set of tools, services, methods and processes of the platform designed from the perspective of Quantum Software Engineering. 

[1] Martínez, A. Peterssen, G. Hevia, J.L. QrEngineer APP beta 1 quantum software reengineering tool (I). The QPath Blog. August 2023.