Skip to content

allow repeating parameters#911

Closed
hhorii wants to merge 3 commits into
Qiskit:masterfrom
hhorii:repeated_parameters
Closed

allow repeating parameters#911
hhorii wants to merge 3 commits into
Qiskit:masterfrom
hhorii:repeated_parameters

Conversation

@hhorii
Copy link
Copy Markdown
Contributor

@hhorii hhorii commented Aug 29, 2020

Summary

Allow use of a circuit for multiple parameters

Details and comments

Currently, parameterized Qobj allows a circuit to take a parameter set. This PR allows a circuit to take multiple parameter set.

@hhorii
Copy link
Copy Markdown
Contributor Author

hhorii commented Sep 2, 2020

Just repeating circuits may not satisfy Aqua's use case. Aqua inserts calibration circuits. These inserted circuits should not be repeated.

@chriseclectic chriseclectic added this to the Aer 0.7 milestone Sep 16, 2020
@hhorii hhorii force-pushed the repeated_parameters branch from b32b46d to d37708a Compare September 20, 2020 15:46
@chriseclectic
Copy link
Copy Markdown
Member

chriseclectic commented Sep 24, 2020

I think this is already supported, its just nested differently. The code example in #485 shows how to runs multiple parameterizations for multiple circuits (Which need not have the same number of parameterizations).

For the case of a single circuit I want to run with 10 different parameterizations for example I can do:

import numpy as np
from qiskit import *

# Example circuit
qc = QuantumCircuit(1, 1)
qc.ry(0, 0)
qc.rx(0, 0)
qc.measure(0, 0)

# Make random parameter values
num_parameterizations = 10
ry_params = np.random.rand(num_parameterizations)
rx_params = np.random.rand(num_parameterizations)
parameterizations = [
    [[[0, 0], ry_params], [[1, 0], rx_params]]
]

# Assemble parameterized qobj
qobj = assemble(qc, parameterizations=parameterizations)

# Execute
sim = Aer.get_backend("qasm_simulator")
result = sim.run(qobj).result()
print('Status: {}'.format(result.status))
print("Results for parameterized circuit:")
for j in range(num_parameterizations):
    print(result.get_counts(j))

Which prints 10 counts:

Status: COMPLETED
Results for parameterized circuit:
{'0': 1013, '1': 11}
{'0': 884, '1': 140}
{'0': 993, '1': 31}
{'0': 894, '1': 130}
{'0': 981, '1': 43}
{'0': 847, '1': 177}
{'0': 806, '1': 218}
{'0': 883, '1': 141}
{'0': 798, '1': 226}
{'0': 860, '1': 164}

@hhorii
Copy link
Copy Markdown
Contributor Author

hhorii commented Sep 25, 2020

@chriseclectic thanks. you are right. I misunderstood the current impl. Let me close this PR.

@hhorii hhorii closed this Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants