-
Notifications
You must be signed in to change notification settings - Fork 945
Simple Circuit Examples
Trevor Grant edited this page Aug 16, 2024
·
1 revision
This example demonstrates how to create and execute a basic quantum circuit using the Qiskit backend in the QuMat library.
from qumat.qumat import QuMat
# Define the backend configuration for Qiskit
backend_config = {
'backend_name': 'qiskit', # Using Qiskit backend
'backend_options': {
'simulator_type': 'qasm_simulator',
'shots': 1024
}
}
# Create a QuMat instance with the specified configuration
qumat_instance = QuMat(backend_config)
# Create an empty circuit with 2 qubits
qumat_instance.create_empty_circuit(2)
# Apply a Hadamard gate on qubit 0
qumat_instance.apply_hadamard_gate(0)
# Apply a CNOT gate with control qubit 0 and target qubit 1
qumat_instance.apply_cnot_gate(0, 1)
# Execute the circuit and get the result
result = qumat_instance.execute_circuit()
print(result)
Expected output:
{'00': a, '11': b}
# where a and b are the counts measured.
This example demonstrates how to create and execute a basic quantum circuit using the Cirq backend in the QuMat library.
from qumat.qumat import QuMat
# Define the backend configuration for Cirq
backend_config = {
'backend_name': 'cirq', # Using Cirq backend
'backend_options': {
'simulator_type': 'default', # Currently, only 'default' is supported
'shots': 1024
}
}
# Create a QuMat instance with the specified configuration
qumat_instance = QuMat(backend_config)
# Create an empty circuit with 2 qubits
qumat_instance.create_empty_circuit(2)
# Apply a Hadamard gate on qubit 0
qumat_instance.apply_hadamard_gate(0)
# Apply a CNOT gate with control qubit 0 and target qubit 1
qumat_instance.apply_cnot_gate(0, 1)
# Execute the circuit and get the result
result = qumat_instance.execute_circuit()
print(result)
Expected output:
Counter({0b00: a, 0b11: b})
# where a and b are the counts measured.
This example demonstrates how to create and execute a basic quantum circuit using the Amazon Braket backend in the QuMat library.
from qumat.qumat import QuMat
# Define the backend configuration for Amazon Braket
backend_config = {
'backend_name': 'amazon_braket', # Using Amazon Braket backend
'backend_options': {
'simulator_type': 'default', # Currently, only 'default' is supported
'shots': 1024
}
}
# Create a QuMat instance with the specified configuration
qumat_instance = QuMat(backend_config)
# Create an empty circuit with 2 qubits
qumat_instance.create_empty_circuit(2)
# Apply a Hadamard gate on qubit 0
qumat_instance.apply_hadamard_gate(0)
# Apply a CNOT gate with control qubit 0 and target qubit 1
qumat_instance.apply_cnot_gate(0, 1)
# Execute the circuit and get the result
result = qumat_instance.execute_circuit()
print(result)
Expected output:
{'00': a, '11': b}
# where a and b are the counts measured.