Hello Many Worlds
With Classiq (as, perhaps, with quantum computing) there are many parallel worlds in which to work; specifically, the IDE and Python SDK interfaces. The 'Hello World' example below runs in different flows of the design-optimize-analyze-execute steps between the IDE and the Python SDK:
- All in IDE
- Design (SDK) - Optimize (SDK) - Analyze (IDE) - Execute (SDK)
- Design (SDK) - Optimize (SDK) - Analyze (IDE) - Execute (IDE)
The 'Hello World' example calculates the simple arithmetic operation \(y=x^2+1\) in a superposition. This example is covered in depth in Classiq 101.
All in IDE
Copy and paste the following code in the Model
tab in the IDE, then click Synthesize
as shown in the GIF:
qfunc main(output x: qnum, output y:qnum){
allocate(4, x);
hadamard_transform(x);
y = x**2+1;
}
![](https://docs.classiq.io/resources/many_worlds_ide_design.gif)
Check that you receive two blocks in the quantum circuit: hadamard_transform
and Arithmetic
, then click Execute
:
![](https://docs.classiq.io/resources/many_worlds_ide_analyze.gif)
In the Execution
tab, under the Classiq provider, choose the simulator (and make sure that other options are not selected). Change the job name to 'hello world' and click Run
:
![](https://docs.classiq.io/resources/many_worlds_ide_execute.gif)
In the Jobs
tab, check the results by hovering over the histogram bars and verifying you receive 16 bars. Each bar encapsulates the correct relation between \(x\) and \(y\); i.e., \(y=x^2+1\):
![](https://docs.classiq.io/resources/many_worlds_ide_results.gif)
That's it! You just completed designing, optimizing, analyzing, and executing your first quantum algorithm with the Classiq IDE.
Design (SDK) - Optimize (SDK) - Analyze (IDE) - Execute (SDK)
Design your hello world quantum algorithm by running the following code in your favorite Python SDK environment (after installing Classiq):
from classiq import *
@qfunc
def main(x: Output[QNum], y: Output[QNum]):
allocate(4, x)
hadamard_transform(x) # creates a uniform superposition
y |= x**2 + 1
qfunc main(output x: qnum, output y: qnum) {
allocate(4, x);
hadamard_transform(x);
y = (x ** 2) + 1;
}
Optimize your algorithm by running this code from the Python SDK:
quantum_program = synthesize(create_model(main))
Analyze your quantum circuit in the IDE by running this code in Python and opening the pop-up link:
show(quantum_program)
![](https://docs.classiq.io/resources/many_worlds_ide_analyze.gif)
Execute your code in the Python SDK by running this:
job = execute(quantum_program)
results = job.result()[0].value.parsed_counts
print(results)
Check that you receive 16 pairs of {'x': , 'y': }
and that the values indeed follow the connection \(y=x^2+1\).
That's it! You just completed your first quantum algorithm in the Python SDK.
Design (SDK) - Optimize (SDK) - Analyze (IDE) - Execute (IDE)
Now, run the same example using a mixed flow of the previous two:
Design your hello world quantum algorithm by running this code in your favorite Python SDK environment (after installing Classiq):
from classiq import *
@qfunc
def main(x: Output[QNum], y: Output[QNum]):
allocate(4, x)
hadamard_transform(x) # creates a uniform superposition
y |= x**2 + 1
qfunc main(output x: qnum, output y: qnum) {
allocate(4, x);
hadamard_transform(x);
y = (x ** 2) + 1;
}
Optimize your algorithm by running this code in the Python SDK:
quantum_program = synthesize(create_model(main))
Analyze your quantum circuit in the IDE by running this code in Python and opening the pop-up link:
show(quantum_program)
![](https://docs.classiq.io/resources/many_worlds_ide_analyze.gif)
Check that you receive two blocks in the quantum circuit: hadamard_transform
and Arithmetic
, then click Execute
:
![](https://docs.classiq.io/resources/many_worlds_ide_analyze.gif)
In the Execution
tab, under the Classiq provider, choose the simulator (and make sure that other options are not selected). Change the job name to 'hello world' and click Run
:
![](https://docs.classiq.io/resources/many_worlds_ide_execute.gif)
In the Jobs
tab, check the results by hovering over the histogram bars and verifying you receive 16 bars. Each bar encapsulates the correct relation between \(x\) and \(y\); i.e., \(y=x^2+1\):
![](https://docs.classiq.io/resources/many_worlds_ide_results.gif)
That's it! You just completed the hello world example in a mixed flow of IDE and Python SDK.
You are ready to continue with Classiq 101. Enjoy!
write_qmod(create_model(main), "hello_many_worlds")