Skip to main content

Documentation Index

Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt

Use this file to discover all available pages before exploring further.

View on GitHub

Open this notebook in GitHub to run it yourself
This tutorial demonstrates an approximated quantum function: a state preparation. Depending on the given functional error, the synthesis engine automatically chooses implementation with fewer resources. The demonstration is on a random state vector, of size 262^6.
import numpy as np

NUM_QUBITS = 6
np.random.seed(12)
amplitudes = 1 - 2 * np.random.rand(2**NUM_QUBITS)
amplitudes = (amplitudes / np.linalg.norm(amplitudes)).tolist()

bounds = np.linspace(0.0, 0.3, 10)
print("The upper bounds:", bounds)
Output:

The upper bounds: [

0.         0.03333333 0.06666667 0.1        0.13333333 0.16666667
   0.2        0.23333333 0.26666667 0.3       ]
  

from classiq import *

preferences = Preferences(
    custom_hardware_settings=CustomHardwareSettings(basis_gates=["cx", "u"]),
    random_seed=1235,
    optimization_timeout_seconds=100,
    transpilation_option="custom",
)


depths = []
cx_counts = []
qprogs = []

for b in bounds:

    @qfunc
    def main(out: Output[QArray]) -> None:
        prepare_amplitudes(amplitudes=amplitudes, bound=b, out=out)

    qprog = synthesize(main, preferences=preferences)
    qprogs.append(qprog)

    depths.append(qprog.transpiled_circuit.depth)
    cx_counts.append(qprog.transpiled_circuit.count_ops["cx"])

print("classiq depths:", depths)
print("cx-counts depths:", cx_counts)
Output:
classiq depths: [114, 8662, 7853, 7622, 7392, 6932, 6702, 6472, 6241, 6010]
  cx-counts depths: [62, 5722, 5171, 5011, 4851, 4531, 4371, 4211, 4051, 3891]
  

import matplotlib.pyplot as plt

classiq_color = "#D7F75B"
plt.rcParams["font.family"] = "serif"
plt.rc("savefig", dpi=300)

plt.rcParams["axes.linewidth"] = 1
plt.rcParams["xtick.major.size"] = 5
plt.rcParams["xtick.minor.size"] = 5
plt.rcParams["ytick.major.size"] = 5
plt.rcParams["ytick.minor.size"] = 5


plt.plot(
    np.round(bounds, 2),
    depths,
    "o",
    label="classiq depth",
    markerfacecolor=classiq_color,
    markeredgecolor="k",
    markersize=8,
    markeredgewidth=1.5,
)
plt.plot(
    np.round(bounds, 2),
    cx_counts,
    "*",
    label="classiq cx-counts",
    markerfacecolor=classiq_color,
    markeredgecolor="k",
    markersize=12,
    markeredgewidth=1.5,
)


plt.legend(fontsize=16, loc="upper right")


plt.ylabel("Depth, CX-count", fontsize=16)
plt.xlabel("error bound ($L_2$ metric)", fontsize=16)
plt.yticks(fontsize=16)
plt.xticks(fontsize=16)
Output:
(array([-0.05,  

0.  ,  0.05,  0.1 ,  0.15,  0.2 ,  0.25,  0.3 ,  0.35]),
   [Text(-0.05, 0, '−0.05'),
    Text(0.0, 0, '0.00'),
    Text(0.05, 0, '0.05'),
    Text(0.10000000000000002, 0, '0.10'),
    Text(0.15000000000000002, 0, '0.15'),
    Text(0.2, 0, '0.20'),
    Text(0.25000000000000006, 0, '0.25'),
    Text(0.30000000000000004, 0, '0.30'),
    Text(0.35000000000000003, 0, '0.35')])
  

output