Skip to content
Snippets Groups Projects

Support the combination of allocation, run and deallocation together.

Merged c.luo requested to merge cl-simplify-job-submission into master
Files
2
+ 20
2
@@ -87,7 +87,7 @@ class JuqcsBackend(Backend):
'''Check if there is a running allocation attached to this backend instance.'''
# never allocated or expired
if (self._expiration_time is None) \
or (self._expiration_time < datetime.datetime.now()):
or (self._expiration_time < datetime.datetime.now()):
self._expiration_time = None
self._allocation_id = None # delete expired ID
self._alloc_qubits = None # delete alloc qubits
@@ -228,12 +228,30 @@ class JuqcsBackend(Backend):
Run {run_input} (QuantumCircuit or list(QuantumCircuit)) on pre-existing allocation.
Returns:
JuqcsJob
'''
'''
# automatically allocate based on the max number of qubits in the input circuits
self_allocated = False
if not self._allocation_is_valid():
self_allocated = True
if isinstance(run_input, list):
required_qubits = max(circuit.num_qubits for circuit in run_input)
else:
required_qubits = run_input.num_qubits
print("Allocating nodes for 30 minutes.")
self.allocate(max_qubits=required_qubits, minutes=30)
job_id = str(uuid4())
print('Submitting circuits for simulation, this may take a few minutes...')
print(f'the job id is : {job_id}')
juqcs_job = JuqcsJob(self, job_id)\
.submit(run_input, **options)
# automatically deallocate if the allocation is automatic
if self_allocated is True:
self.deallocate()
self_allocated = False
return juqcs_job
Loading