Example Usage - dynexcoin/DynexSDK GitHub Wiki

Dynex n.Quantum Annealing

Find a solution to a QUBO problem:

import dynex
import dimod

# Define the QUBU problem:
bqmodel = dimod.BinaryQuadraticModel({0: -1, 1: -1}, {(0, 1): 2}, 0.0, dimod.BINARY)  

# Sample the problem:
model = dynex.BQM(bqmodel)
sampler = dynex.DynexSampler(model, mainnet=False) # using local testnet sampler
sampleset = sampler.sample(num_reads=32, annealing_time = 100)

# Output the result:
print(sampleset)

Output during sampling:

[DYNEX] SAMPLER INITIALISED
[DYNEX|TESTNET] *** WAITING FOR READS ***
╭────────────┬─────────────┬───────────┬───────────────────────────┬─────────┬─────────┬────────────────╮
│   DYNEXJOB │   BLOCK FEE │ ELAPSED   │ WORKERS READ              │ CHIPS   │ STEPS   │ GROUND STATE   │
├────────────┼─────────────┼───────────┼───────────────────────────┼─────────┼─────────┼────────────────┤
│         -1 │           0 │           │ *** WAITING FOR READS *** │         │         │                │
╰────────────┴─────────────┴───────────┴───────────────────────────┴─────────┴─────────┴────────────────╯

[DYNEX] FINISHED READ AFTER 0.01 SECONDS
[DYNEX] SAMPLESET READY
   0  1 energy num_oc.
0  1  0   -1.0       1
['BINARY', 1 rows, 1 samples, 2 variables]```


Result:

   0  1 energy num_oc.
0  0  1   -1.0       1
['BINARY', 1 rows, 1 samples, 2 variables]

Learn more:

Dynex n.Quantum Gate Circuits

Execute and measure a simple PennyLane circuit:

import dynex
import dynex_circuit
import pennylane as qml

dev = qml.device("default.qubit", wires=2)

# Define the quantum circuit:
@qml.qnode(dev)
def circuit(params):
    qml.Hadamard(wires = 0)
    qml.CNOT(wires = [0,1])
    qml.RZ(params[0], wires = 0)
    return qml.probs(wires = [0,1])

# Input parameters:
params = [0.1]

# draw circuit:
_ = qml.draw_mpl(circuit, style="black_white", expansion_strategy="device")(params)

# Execute and measure on Dynex:
measure = dynex_circuit.execute(circuit, params, method='measure', shots=1, mainnet=True)
print(measure)

Which outputs:

╭────────────┬──────────┬─────────────────┬─────────────┬───────────┬────────────────┬────────────┬─────────┬────────────────╮
│   DYNEXJOB │   QUBITS │   QUANTUM GATES │   BLOCK FEE │   ELAPSED │   WORKERS READ │   CIRCUITS │   STEPS │   GROUND STATE │
├────────────┼──────────┼─────────────────┼─────────────┼───────────┼────────────────┼────────────┼─────────┼────────────────┤
│      28513 │       19 │              56 │        0.00 │      0.52 │              1 │       1000 │     256 │       34338.00 │
╰────────────┴──────────┴─────────────────┴─────────────┴───────────┴────────────────┴────────────┴─────────┴────────────────╯
╭────────────┬─────────────────┬────────────┬───────┬──────────┬──────────────┬─────────────────────────────┬───────────┬──────────╮
│     WORKER │         VERSION │   CIRCUITS │   LOC │   ENERGY │      RUNTIME │                 LAST UPDATE │     STEPS │   STATUS │
├────────────┼─────────────────┼────────────┼───────┼──────────┼──────────────┼─────────────────────────────┼───────────┼──────────┤
│ 1147..9be1 │ 2.3.5.OZM.134.L │       1000 │     0 │     0.00 │ 3.113746382s │  2024-08-07T06:41:11.13505Z │ 0 (0.00%) │  STOPPED │
├────────────┼─────────────────┼────────────┼───────┼──────────┼──────────────┼─────────────────────────────┼───────────┼──────────┤
│ 85ee..69b7 │ 2.3.5.OZM.134.L │       1000 │     0 │     0.00 │ 7.939941036s │ 2024-08-07T06:41:06.308857Z │ 0 (0.00%) │  STOPPED │
╰────────────┴─────────────────┴────────────┴───────┴──────────┴──────────────┴─────────────────────────────┴───────────┴──────────╯
[DYNEX] FINISHED READ AFTER 52.37 SECONDS
[DYNEX] SAMPLESET READY
[0 0]